From 824231284cb076fe97cdd6ef8fc7a3dfc0504373 Mon Sep 17 00:00:00 2001 From: Tristan Hume Date: Thu, 1 Aug 2013 12:49:36 -0400 Subject: [PATCH] Run test suite with both parsers --- Rakefile | 15 ++++++++++++- test/liquid/error_handling_test.rb | 7 +++--- test/liquid/parsing_quirks_test.rb | 34 ++++++++++++++++++------------ test/liquid/variable_test.rb | 6 ++++-- test/test_helper.rb | 17 +++++++++++---- 5 files changed, 55 insertions(+), 24 deletions(-) diff --git a/Rakefile b/Rakefile index 486bdfe..6dca0af 100755 --- a/Rakefile +++ b/Rakefile @@ -7,12 +7,25 @@ require 'rubygems/package_task' task :default => 'test' -Rake::TestTask.new(:test) do |t| +Rake::TestTask.new(:lax_test) do |t| + t.libs << '.' << 'lib' << 'test' + t.test_files = FileList['test/liquid/**/*_test.rb'] + t.options = 'lax' + t.verbose = false +end + +Rake::TestTask.new(:strict_test) do |t| t.libs << '.' << 'lib' << 'test' t.test_files = FileList['test/liquid/**/*_test.rb'] t.verbose = false end +desc 'runs test suite with both strict and lax parsers' +task :test do + Rake::Task['lax_test'].invoke + Rake::Task['strict_test'].invoke +end + gemspec = eval(File.read('liquid.gemspec')) Gem::PackageTask.new(gemspec) do |pkg| pkg.gem_spec = gemspec diff --git a/test/liquid/error_handling_test.rb b/test/liquid/error_handling_test.rb index 43136b8..6d3aff9 100644 --- a/test/liquid/error_handling_test.rb +++ b/test/liquid/error_handling_test.rb @@ -63,9 +63,10 @@ class ErrorHandlingTest < Test::Unit::TestCase end def test_unrecognized_operator - Template.error_mode = :strict - assert_raise(SyntaxError) do - Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ') + with_error_mode(:strict) do + assert_raise(SyntaxError) do + Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ') + end end end diff --git a/test/liquid/parsing_quirks_test.rb b/test/liquid/parsing_quirks_test.rb index 04c1307..ef21117 100644 --- a/test/liquid/parsing_quirks_test.rb +++ b/test/liquid/parsing_quirks_test.rb @@ -34,26 +34,32 @@ class ParsingQuirksTest < Test::Unit::TestCase Template.parse("{{test}}") Template.parse("{{|test}}") end - assert_raise(SyntaxError) do - Template.parse("{{test |a|b|}}") + with_error_mode(:strict) do + assert_raise(SyntaxError) do + Template.parse("{{test |a|b|}}") + end end end def test_meaningless_parens_error - assert_raise(SyntaxError) do - markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false" - Template.parse("{% if #{markup} %} YES {% endif %}") + with_error_mode(:strict) do + assert_raise(SyntaxError) do + markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false" + Template.parse("{% if #{markup} %} YES {% endif %}") + end end end def test_unexpected_characters_syntax_error - assert_raise(SyntaxError) do - markup = "true && false" - Template.parse("{% if #{markup} %} YES {% endif %}") - end - assert_raise(SyntaxError) do - markup = "false || true" - Template.parse("{% if #{markup} %} YES {% endif %}") + with_error_mode(:strict) do + assert_raise(SyntaxError) do + markup = "true && false" + Template.parse("{% if #{markup} %} YES {% endif %}") + end + assert_raise(SyntaxError) do + markup = "false || true" + Template.parse("{% if #{markup} %} YES {% endif %}") + end end end @@ -66,7 +72,7 @@ class ParsingQuirksTest < Test::Unit::TestCase end def test_meaningless_parens_lax - with_lax_parsing do + with_error_mode(:lax) do assigns = {'b' => 'bar', 'c' => 'baz'} markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false" assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}", assigns) @@ -74,7 +80,7 @@ class ParsingQuirksTest < Test::Unit::TestCase end def test_unexpected_characters_silently_eat_logic_lax - with_lax_parsing do + with_error_mode(:lax) do markup = "true && false" assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}") markup = "false || true" diff --git a/test/liquid/variable_test.rb b/test/liquid/variable_test.rb index a4dd2da..30513c3 100644 --- a/test/liquid/variable_test.rb +++ b/test/liquid/variable_test.rb @@ -127,8 +127,10 @@ class VariableTest < Test::Unit::TestCase end def test_strict_filter_argument_parsing - assert_raises(SyntaxError) do - Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !) + with_error_mode(:strict) do + assert_raises(SyntaxError) do + Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !) + end end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index c0c4ffa..a14a277 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -9,7 +9,15 @@ rescue LoadError end require File.join(File.dirname(__FILE__), '..', 'lib', 'liquid') -Liquid::Template.error_mode = :strict +mode = :strict +if ARGV.last == 'lax' + puts "-- LAX ERROR MODE" + ARGV.pop + mode = :lax +else + puts "-- STRICT ERROR MODE" +end +Liquid::Template.error_mode = mode module Test @@ -27,10 +35,11 @@ module Test assert_match expected, Template.parse(template).render(assigns) end - def with_lax_parsing - Liquid::Template.error_mode = :lax + def with_error_mode(mode) + old_mode = Liquid::Template.error_mode + Liquid::Template.error_mode = mode yield - Liquid::Template.error_mode = :strict + Liquid::Template.error_mode = old_mode end end # Assertions end # Unit