rearranges test helper modules

This commit is contained in:
Torsten Ruger 2017-04-10 16:12:15 +03:00
parent 0233e91355
commit 0d96f5e35f
8 changed files with 111 additions and 99 deletions

View File

@ -20,82 +20,4 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'test'))
require 'rubyx'
module Compiling
def clean_compile(clazz_name , method_name , args , statements)
compiler = Vm::MethodCompiler.create_method(clazz_name,method_name,args ).init_method
compiler.process( Vm.ast_to_code( statements ) )
end
end
module Risc
# 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("Risc::","")
str.split(",").each_slice(5).each do |line|
puts " " + line.join(",") + ","
end
puts "length = #{classes.length}"
exit(1)
end
end
end
class Ignored
def == other
return false unless other.class == self.class
Sof::Util.attributes(self).each do |a|
begin
left = send(a)
rescue NoMethodError
next # not using instance variables that are not defined as attr_readers for equality
end
begin
right = other.send(a)
rescue NoMethodError
return false
end
return false unless left.class == right.class
return false unless left == right
end
return true
end
end
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }

View File

@ -0,0 +1,11 @@
require_relative "helper"
module Mom
class TestAssignemnt < MiniTest::Test
include CompilerHelper
def test_class_exists
assert Instruction.new
end
end
end

View File

@ -3,7 +3,7 @@ require_relative "helper"
module Risc
class IfCalledTest < MiniTest::Test
include Ticker
include Compiling
include CleanCompile
def setup
@string_input = <<HERE

View File

@ -3,7 +3,7 @@ require_relative "helper"
module Risc
class IfSimpleTest < MiniTest::Test
include Ticker
include Compiling
include CleanCompile
def setup
@string_input = <<HERE

47
test/support/compiling.rb Normal file
View File

@ -0,0 +1,47 @@
module CompilerHelper
def in_Test(statements)
"class Test ; #{statements} ; end"
end
def in_Space(statements)
"class Space ; #{statements} ; end"
end
def as_main(statements)
in_Space("def main ; #{statements}; end")
end
end
module CleanCompile
def clean_compile(clazz_name , method_name , args , statements)
compiler = Vm::MethodCompiler.create_method(clazz_name,method_name,args ).init_method
compiler.process( Vm.ast_to_code( statements ) )
end
end
class Ignored
def == other
return false unless other.class == self.class
Sof::Util.attributes(self).each do |a|
begin
left = send(a)
rescue NoMethodError
next # not using instance variables that are not defined as attr_readers for equality
end
begin
right = other.send(a)
rescue NoMethodError
return false
end
return false unless left.class == right.class
return false unless left == right
end
return true
end
end

49
test/support/risc.rb Normal file
View File

@ -0,0 +1,49 @@
module Risc
# 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("Risc::","")
str.split(",").each_slice(5).each do |line|
puts " " + line.join(",") + ","
end
puts "length = #{classes.length}"
exit(1)
end
end
end

View File

@ -26,7 +26,7 @@ module Risc
module Statements
include AST::Sexp
include Compiling
include CleanCompile
include SpaceHack
def setup

View File

@ -1,18 +1 @@
require_relative "../helper"
module Vool
module CompilerHelper
def in_Test(statements)
"class Test ; #{statements} ; end"
end
def in_Space(statements)
"class Space ; #{statements} ; end"
end
def as_main(statements)
in_Space("def main ; #{statements}; end")
end
end
end