~singpolyma/dhall-ruby

da5b58b4e21b6e71b26fcd84e78a13da563614cd — Stephen Paul Weber 4 years ago 3f6f7ac
Speed up tests by not resolving when not needed
3 files changed, 35 insertions(+), 16 deletions(-)

M test/test_cache_key.rb
M test/test_normalization.rb
M test/test_typechecker.rb
M test/test_cache_key.rb => test/test_cache_key.rb +9 -5
@@ 12,12 12,16 @@ class TestCacheKey < Minitest::Test
	Pathname.glob(TESTS + "**/*A.dhall").each do |path|
		test = path.relative_path_from(TESTS).to_s.sub(/A\.dhall$/, "")
		define_method("test_#{test}") do
			assert_equal(
				(TESTS + "#{test}B.hash").read.chomp,
				Dhall::Parser.parse_file(path).value.resolve(
			parsed_a = Dhall::Parser.parse_file(path).value
			hash_a = if test !~ /unit|simple/
				parsed_a.resolve(
					relative_to: Dhall::Import::Path.from_string(path)
				).then(&:cache_key).sync
			)
				)
			else
				Promise.resolve(parsed_a)
			end.then(&:cache_key).sync

			assert_equal (TESTS + "#{test}B.hash").read.chomp, hash_a
		end
	end
end

M test/test_normalization.rb => test/test_normalization.rb +12 -3
@@ 14,12 14,21 @@ class TestNormalization < Minitest::Test

		define_method("test_#{test}") do
			Dhall::Function.disable_alpha_normalization! if test !~ /α/

			parsed_a = Dhall::Parser.parse_file(path).value
			binary_a = if test !~ /unit|simple/
				parsed_a.resolve(
					relative_to: Dhall::Import::Path.from_string(path)
				)
			else
				Promise.resolve(parsed_a)
			end.then(&:normalize).sync.to_binary

			assert_equal(
				Dhall::Parser.parse_file(TESTS + "#{test}B.dhall").value.to_binary,
				Dhall::Parser.parse_file(path).value.resolve(
					relative_to: Dhall::Import::Path.from_string(path)
				).then(&:normalize).sync.to_binary
				binary_a
			)

			Dhall::Function.enable_alpha_normalization! if test !~ /α/
		end
	end

M test/test_typechecker.rb => test/test_typechecker.rb +14 -8
@@ 14,16 14,22 @@ class TestTypechecker < Minitest::Test
		bside = TESTS + "#{test}B.dhall"

		define_method("test_#{test}") do
			parsed_a = Dhall::Parser.parse_file(path).value
			parsed_b = Dhall::Parser.parse_file(bside).value

			final_a, final_b = if test !~ /unit|simple/
				Promise.all([parsed_a, parsed_b].map { |e|
					e.resolve(
						relative_to: Dhall::Import::Path.from_string(path)
					)
				})
			else
				Promise.resolve([parsed_a, parsed_b])
			end.sync

			assert_respond_to(
				Dhall::TypeChecker.for(
					Dhall::TypeAnnotation.new(
						value: Dhall::Parser.parse_file(path).value.resolve(
							relative_to: Dhall::Import::Path.from_string(path)
						).sync,
						type:  Dhall::Parser.parse_file(bside).value.resolve(
							relative_to: Dhall::Import::Path.from_string(bside)
						).sync
					)
					Dhall::TypeAnnotation.new(value: final_a, type: final_b)
				).annotate(Dhall::TypeChecker::Context.new),
				:type
			)