move test helpers up, so they can be used in Melon too
This commit is contained in:
parent
4ba182a822
commit
091900ef1c
@ -28,6 +28,57 @@ module Compiling
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module Register
|
||||||
|
# relies on @interpreter instance to be set up during setup
|
||||||
|
module InterpreterHelpers
|
||||||
|
|
||||||
|
def check_chain should
|
||||||
|
should.each_with_index do |name , index|
|
||||||
|
got = ticks(1)
|
||||||
|
assert_equal got.class ,name , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_return val
|
||||||
|
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
|
||||||
|
assert_equal val , @interpreter.get_register(:r0).return_value
|
||||||
|
end
|
||||||
|
|
||||||
|
def ticks num
|
||||||
|
last = nil
|
||||||
|
num.times do
|
||||||
|
last = @interpreter.instruction
|
||||||
|
@interpreter.tick
|
||||||
|
end
|
||||||
|
return last
|
||||||
|
end
|
||||||
|
|
||||||
|
def show_ticks
|
||||||
|
classes = []
|
||||||
|
tick = 1
|
||||||
|
begin
|
||||||
|
while true and (classes.length < 200)
|
||||||
|
cl = ticks(1).class
|
||||||
|
tick += 1
|
||||||
|
classes << cl
|
||||||
|
break if cl == NilClass
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
puts "Error at tick #{tick}"
|
||||||
|
puts e
|
||||||
|
puts e.backtrace
|
||||||
|
end
|
||||||
|
str = classes.to_s.gsub("Register::","")
|
||||||
|
str.split(",").each_slice(5).each do |line|
|
||||||
|
puts " " + line.join(",") + ","
|
||||||
|
end
|
||||||
|
puts "length = #{classes.length}"
|
||||||
|
exit(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
class Ignored
|
class Ignored
|
||||||
def == other
|
def == other
|
||||||
return false unless other.class == self.class
|
return false unless other.class == self.class
|
||||||
|
@ -5,12 +5,13 @@ require "parser/ruby22"
|
|||||||
module Melon
|
module Melon
|
||||||
module MelonTests
|
module MelonTests
|
||||||
include CompilerHelper
|
include CompilerHelper
|
||||||
|
include Register::InterpreterHelpers
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Register.machine.boot
|
Register.machine.boot
|
||||||
end
|
end
|
||||||
|
|
||||||
def check
|
def check_nil
|
||||||
RubyCompiler.compile @string_input
|
RubyCompiler.compile @string_input
|
||||||
Register::Collector.collect_space
|
Register::Collector.collect_space
|
||||||
@interpreter = Register::Interpreter.new
|
@interpreter = Register::Interpreter.new
|
||||||
|
@ -4,6 +4,7 @@ require "register/interpreter"
|
|||||||
module Register
|
module Register
|
||||||
module Ticker
|
module Ticker
|
||||||
include AST::Sexp
|
include AST::Sexp
|
||||||
|
include InterpreterHelpers
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Register.machine.boot
|
Register.machine.boot
|
||||||
@ -18,48 +19,5 @@ module Register
|
|||||||
def do_clean_compile
|
def do_clean_compile
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_chain should
|
|
||||||
should.each_with_index do |name , index|
|
|
||||||
got = ticks(1)
|
|
||||||
assert_equal got.class ,name , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def check_return val
|
|
||||||
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
|
|
||||||
assert_equal val , @interpreter.get_register(:r0).return_value
|
|
||||||
end
|
|
||||||
|
|
||||||
def ticks num
|
|
||||||
last = nil
|
|
||||||
num.times do
|
|
||||||
last = @interpreter.instruction
|
|
||||||
@interpreter.tick
|
|
||||||
end
|
|
||||||
return last
|
|
||||||
end
|
|
||||||
|
|
||||||
def show_ticks
|
|
||||||
classes = []
|
|
||||||
tick = 1
|
|
||||||
begin
|
|
||||||
while true and (classes.length < 200)
|
|
||||||
cl = ticks(1).class
|
|
||||||
tick += 1
|
|
||||||
classes << cl
|
|
||||||
break if cl == NilClass
|
|
||||||
end
|
|
||||||
rescue => e
|
|
||||||
puts "Error at tick #{tick}"
|
|
||||||
puts e
|
|
||||||
puts e.backtrace
|
|
||||||
end
|
|
||||||
str = classes.to_s.gsub("Register::","")
|
|
||||||
str.split(",").each_slice(5).each do |line|
|
|
||||||
puts " " + line.join(",") + ","
|
|
||||||
end
|
|
||||||
puts "length = #{classes.length}"
|
|
||||||
exit(1)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user