From 0084406cfdd2ba5359d844b690a90039b97726b7 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 4 Jan 2017 21:38:03 +0200 Subject: [PATCH] let check return and assert in main test so one can better locale the error (the assert in the helper does not give stack trace) a shot at keeping the calling handshake out of the asserts failed --- test/typed/method_compiler/helper.rb | 37 +++++++++++++++++++--------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/test/typed/method_compiler/helper.rb b/test/typed/method_compiler/helper.rb index 8aedfbde..cc6ec389 100644 --- a/test/typed/method_compiler/helper.rb +++ b/test/typed/method_compiler/helper.rb @@ -29,8 +29,13 @@ module Register Register.machine.boot # force boot to reset main end - - def check + def preamble + [Label, SlotToReg , LoadConstant, RegToSlot, LoadConstant,RegToSlot, LoadConstant, SlotToReg, SlotToReg ] + end + def postamble + [ Label, FunctionReturn] + end + def check_nil assert @expect , "No output given" compiler = Typed::MethodCompiler.new code = Typed.ast_to_code( @input ) @@ -38,25 +43,33 @@ module Register produced = compiler.process( code ) produced = Parfait.object_space.get_main.instructions compare_instructions produced , @expect - produced + end + def check_return + was = check_nil + raise was if was + Parfait.object_space.get_main.instructions end - def compare_instructions instruction , expect + def compare_instructions( instruction , expect ) index = 0 - start = instruction + all = instruction.to_arr + full_expect = preamble + expect + postamble + full_expect = expect begin - should = expect[index] - assert should , "No instruction at #{index}" - assert_equal instruction.class , should , "Expected at #{index+1}\n#{should(start)}" + should = full_expect[index] + return "No instruction at #{index}" unless should + return "Expected at #{index+1}\n#{should(all)}" unless instruction.class == should index += 1 instruction = instruction.next end while( instruction ) + nil end - def should start - str = start.to_ac.to_s - str.gsub!("Register::","") + def should( all ) + #preamble.each {all.shift} + #postamble.each {all.pop} + str = all.to_s.gsub("Register::","") ret = "" - str.split(",").each_slice(7).each do |line| + str.split(",").each_slice(6).each do |line| ret += " " + line.join(",") + " ,\n" end ret