From 047900d0ddf479a2fc615a8dacb29f82a7ce4a6a Mon Sep 17 00:00:00 2001 From: Tristan Hume Date: Mon, 19 Aug 2013 15:14:26 -0400 Subject: [PATCH] Proper warning support --- Rakefile | 6 ++++++ lib/liquid/tags/for.rb | 1 + lib/liquid/tags/if.rb | 2 +- test/liquid/error_handling_test.rb | 7 +++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index d88d8f5..137b8e3 100755 --- a/Rakefile +++ b/Rakefile @@ -14,6 +14,12 @@ Rake::TestTask.new(:base_test) do |t| t.verbose = false end +desc 'run test suite with warn error mode' +task :warn_test do + ENV['LIQUID_PARSER_MODE'] = 'warn' + Rake::Task['base_test'].invoke +end + desc 'runs test suite with both strict and lax parsers' task :test do ENV['LIQUID_PARSER_MODE'] = 'lax' diff --git a/lib/liquid/tags/for.rb b/lib/liquid/tags/for.rb index 69fc9d3..7ddcdde 100644 --- a/lib/liquid/tags/for.rb +++ b/lib/liquid/tags/for.rb @@ -58,6 +58,7 @@ module Liquid end def render(context) + context.errors.concat(@warnings) if @warnings context.registers[:for] ||= Hash.new(0) collection = context[@collection_name] diff --git a/lib/liquid/tags/if.rb b/lib/liquid/tags/if.rb index d573afd..90cc880 100644 --- a/lib/liquid/tags/if.rb +++ b/lib/liquid/tags/if.rb @@ -29,7 +29,7 @@ module Liquid end def render(context) - context.errors += @warnings if @warnings + context.errors.concat(@warnings) if @warnings context.stack do @blocks.each do |block| if block.evaluate(context) diff --git a/test/liquid/error_handling_test.rb b/test/liquid/error_handling_test.rb index 6d3aff9..6e4889a 100644 --- a/test/liquid/error_handling_test.rb +++ b/test/liquid/error_handling_test.rb @@ -79,6 +79,13 @@ class ErrorHandlingTest < Test::Unit::TestCase end end + def test_warnings + template = Liquid::Template.parse('{% if ~~~ %}derp{% else %}wat{% endif %}', :error_mode => :warn) + assert_equal 'wat', template.render + assert_equal 1, template.errors.size + assert_equal 'Unexpected character ~.', template.errors.first.message + end + # Liquid should not catch Exceptions that are not subclasses of StandardError, like Interrupt and NoMemoryError def test_exceptions_propagate assert_raise Exception do