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
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