mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 00:40:40 -07:00
Test migration parity using existing integration tests
This commit is contained in:
@@ -5,7 +5,7 @@ require 'rake/testtask'
|
||||
$LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
|
||||
require "liquid/version"
|
||||
|
||||
task(default: [:test, :rubocop])
|
||||
task(default: [:test, "test:migrator_integration", :rubocop])
|
||||
|
||||
desc('run test suite with default parser')
|
||||
Rake::TestTask.new(:base_test) do |t|
|
||||
@@ -33,6 +33,23 @@ task :rubocop do
|
||||
end
|
||||
end
|
||||
|
||||
namespace :test do
|
||||
task :migrator_integration do
|
||||
ENV['LIQUID_MIGRATOR'] = '1'
|
||||
original_parse_mode = ENV['LIQUID_PARSER_MODE']
|
||||
begin
|
||||
Rake::Task['integration_test'].reenable
|
||||
["lax", "strict"].each do |parse_mode|
|
||||
ENV['LIQUID_PARSER_MODE'] = parse_mode
|
||||
Rake::Task['integration_test'].invoke
|
||||
Rake::Task['integration_test'].reenable
|
||||
end
|
||||
ensure
|
||||
ENV['LIQUID_PARSER_MODE'] = original_parse_mode
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc('runs test suite with both strict and lax parsers')
|
||||
task :test do
|
||||
ENV['LIQUID_PARSER_MODE'] = 'lax'
|
||||
|
||||
@@ -49,6 +49,27 @@ module Minitest
|
||||
assert_equal(expected, output, message)
|
||||
end
|
||||
|
||||
if ENV['LIQUID_MIGRATOR']
|
||||
puts "-- Liquid Migrator Enabled"
|
||||
|
||||
alias_method(:assert_template_result_without_migrator, :assert_template_result)
|
||||
|
||||
def assert_template_result(expected, source, assigns = {}, error_mode: nil, partials: nil, **kwargs)
|
||||
migrated_source = Liquid::Template.migrate(source, line_numbers: true, error_mode: error_mode&.to_sym)
|
||||
assert_no_migration(migrated_source)
|
||||
if partials
|
||||
migrated_partials = {}
|
||||
partials.each do |name, partial|
|
||||
new_partial = Liquid::Template.migrate(partial, line_numbers: true, error_mode: error_mode&.to_sym)
|
||||
assert_no_migration(new_partial)
|
||||
migrated_partials[name] = new_partial
|
||||
end
|
||||
end
|
||||
assert_template_result_without_migrator(expected, migrated_source, assigns,
|
||||
error_mode: 'strict', partials: migrated_partials, **kwargs)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_match_syntax_error(match, template, error_mode: nil)
|
||||
exception = assert_raises(Liquid::SyntaxError) do
|
||||
Template.parse(template, line_numbers: true, error_mode: error_mode&.to_sym).render
|
||||
@@ -60,6 +81,10 @@ module Minitest
|
||||
assert_match_syntax_error("", template, error_mode: error_mode)
|
||||
end
|
||||
|
||||
def assert_no_migration(source)
|
||||
assert_equal(source, Liquid::Template.migrate(source))
|
||||
end
|
||||
|
||||
def assert_usage_increment(name, times: 1)
|
||||
old_method = Liquid::Usage.method(:increment)
|
||||
calls = 0
|
||||
|
||||
@@ -107,10 +107,6 @@ class MigrateUnitTest < Minitest::Test
|
||||
|
||||
private
|
||||
|
||||
def assert_no_migration(source)
|
||||
assert_equal(source, Liquid::Template.migrate(source))
|
||||
end
|
||||
|
||||
def assert_migration(source_to_expected_output_hash)
|
||||
source_to_expected_output_hash.each do |source, expect|
|
||||
message = "source: #{source.inspect}"
|
||||
|
||||
Reference in New Issue
Block a user