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
This commit is contained in:
Torsten Ruger 2017-01-04 21:38:03 +02:00
parent 49da77f996
commit 0084406cfd

View File

@ -29,8 +29,13 @@ module Register
Register.machine.boot # force boot to reset main Register.machine.boot # force boot to reset main
end end
def preamble
def check [Label, SlotToReg , LoadConstant, RegToSlot, LoadConstant,RegToSlot, LoadConstant, SlotToReg, SlotToReg ]
end
def postamble
[ Label, FunctionReturn]
end
def check_nil
assert @expect , "No output given" assert @expect , "No output given"
compiler = Typed::MethodCompiler.new compiler = Typed::MethodCompiler.new
code = Typed.ast_to_code( @input ) code = Typed.ast_to_code( @input )
@ -38,25 +43,33 @@ module Register
produced = compiler.process( code ) produced = compiler.process( code )
produced = Parfait.object_space.get_main.instructions produced = Parfait.object_space.get_main.instructions
compare_instructions produced , @expect compare_instructions produced , @expect
produced end
def check_return
was = check_nil
raise was if was
Parfait.object_space.get_main.instructions
end end
def compare_instructions instruction , expect def compare_instructions( instruction , expect )
index = 0 index = 0
start = instruction all = instruction.to_arr
full_expect = preamble + expect + postamble
full_expect = expect
begin begin
should = expect[index] should = full_expect[index]
assert should , "No instruction at #{index}" return "No instruction at #{index}" unless should
assert_equal instruction.class , should , "Expected at #{index+1}\n#{should(start)}" return "Expected at #{index+1}\n#{should(all)}" unless instruction.class == should
index += 1 index += 1
instruction = instruction.next instruction = instruction.next
end while( instruction ) end while( instruction )
nil
end end
def should start def should( all )
str = start.to_ac.to_s #preamble.each {all.shift}
str.gsub!("Register::","") #postamble.each {all.pop}
str = all.to_s.gsub("Register::","")
ret = "" ret = ""
str.split(",").each_slice(7).each do |line| str.split(",").each_slice(6).each do |line|
ret += " " + line.join(",") + " ,\n" ret += " " + line.join(",") + " ,\n"
end end
ret ret