Make builtin tests more stand alone

not relying on the whole boot process
easier to test basic when broken (like now)
This commit is contained in:
Torsten Rüger 2019-08-22 17:52:19 +03:00
parent 5dc8c046e7
commit c13d4fb017
16 changed files with 59 additions and 45 deletions

View File

@ -5,10 +5,24 @@ module Mom
class BootTest < MiniTest::Test class BootTest < MiniTest::Test
def setup def setup
Parfait.boot!(Parfait.default_test_options) Parfait.boot!(Parfait.default_test_options)
@functions = Builtin.boot_functions Builtin.compiler_for( Parfait.object_space.get_class.instance_type , Space , :main)
end end
def get_compiler( name ) def get_int_compiler(name)
@functions.each.find{|meth| meth.callable.name == name} obj_type = Parfait.object_space.get_type_by_class_name(:Integer)
Builtin.compiler_for( obj_type , Integer , name)
end
def get_operator_compiler(name)
obj_type = Parfait.object_space.get_type_by_class_name(:Integer)
Builtin.operator_compiler( obj_type , name)
end
def get_object_compiler(name)
obj_type = Parfait.object_space.get_type_by_class_name(:Object)
Builtin.compiler_for( obj_type , Object , name)
end
def get_word_compiler(name)
obj_type = Parfait.object_space.get_type_by_class_name(:Word)
Builtin.compiler_for( obj_type , Word , name)
end end
end end
end end

View File

@ -5,19 +5,7 @@ module Mom
class TestIntComp1Risc < BootTest class TestIntComp1Risc < BootTest
def setup def setup
super super
@method = get_compiler(:<) @method = get_int_compiler(:<)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 28 , @method.to_risc.risc_instructions.length
end
end
class TestIntComp2Risc < BootTest
def setup
super
@method = get_compiler(:>=)
end end
def test_compile def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class
@ -26,5 +14,17 @@ module Mom
assert_equal 27 , @method.to_risc.risc_instructions.length assert_equal 27 , @method.to_risc.risc_instructions.length
end end
end end
class TestIntComp2Risc < BootTest
def setup
super
@method = get_int_compiler(:>=)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 26 , @method.to_risc.risc_instructions.length
end
end
end end
end end

View File

@ -5,7 +5,7 @@ module Mom
class TestIntDiv10Risc < BootTest class TestIntDiv10Risc < BootTest
def setup def setup
super super
@method = get_compiler(:div10) @method = get_int_compiler(:div10)
end end
def test_compile def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class

View File

@ -5,7 +5,7 @@ module Mom
class TestIntDiv4Risc < BootTest class TestIntDiv4Risc < BootTest
def setup def setup
super super
@method = get_compiler(:div4) @method = get_int_compiler(:div4)
end end
def test_compile def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class

View File

@ -5,7 +5,7 @@ module Mom
class TestObjectExitRisc < BootTest class TestObjectExitRisc < BootTest
def setup def setup
super super
@method = get_compiler(:exit) @method = get_object_compiler(:exit)
end end
def test_compile def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class

View File

@ -5,13 +5,13 @@ module Mom
class TestWordGetRisc < BootTest class TestWordGetRisc < BootTest
def setup def setup
super super
@method = get_compiler(:get_internal_byte) @method = get_word_compiler(:get_internal_byte)
end end
def test_compile def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class
end end
def test_risc_length def test_risc_length
assert_equal 48 , @method.to_risc.risc_instructions.length assert_equal 47 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -5,13 +5,13 @@ module Mom
class TestWordGetRisc < BootTest class TestWordGetRisc < BootTest
def setup def setup
super super
@method = get_compiler(:get_internal_byte) @method = get_object_compiler(:get_internal_word)
end end
def test_compile def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class
end end
def test_risc_length def test_risc_length
assert_equal 48 , @method.to_risc.risc_instructions.length assert_equal 19 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -5,7 +5,7 @@ module Mom
class TestObjectInitRisc < BootTest class TestObjectInitRisc < BootTest
def setup def setup
super super
@method = get_compiler(:__init__) @method = get_object_compiler(:__init__)
end end
def test_compile def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class

View File

@ -5,7 +5,7 @@ module Mom
class TestIntDiv4 < BootTest class TestIntDiv4 < BootTest
def setup def setup
super super
@method = get_compiler(:div4) @method = get_int_compiler(:div4)
end end
def test_has_get_internal def test_has_get_internal
assert_equal Mom::MethodCompiler , @method.class assert_equal Mom::MethodCompiler , @method.class
@ -17,7 +17,7 @@ module Mom
class TestIntDiv10 < BootTest class TestIntDiv10 < BootTest
def setup def setup
super super
@method = get_compiler(:div10) @method = get_int_compiler(:div10)
end end
def test_has_get_internal def test_has_get_internal
assert_equal Mom::MethodCompiler , @method.class assert_equal Mom::MethodCompiler , @method.class
@ -29,7 +29,7 @@ module Mom
class TestIntComp1 < BootTest class TestIntComp1 < BootTest
def setup def setup
super super
@method = get_compiler(:<) @method = get_int_compiler(:<)
end end
def test_has_get_internal def test_has_get_internal
assert_equal Mom::MethodCompiler , @method.class assert_equal Mom::MethodCompiler , @method.class
@ -41,7 +41,7 @@ module Mom
class TestIntComp2 < BootTest class TestIntComp2 < BootTest
def setup def setup
super super
@method = get_compiler(:>=) @method = get_int_compiler(:>=)
end end
def test_has_get_internal def test_has_get_internal
assert_equal Mom::MethodCompiler , @method.class assert_equal Mom::MethodCompiler , @method.class
@ -56,7 +56,7 @@ module Mom
end end
def each_method &block def each_method &block
Risc.operators.each do |name| Risc.operators.each do |name|
method = get_compiler(name) method = get_operator_compiler(name)
block.yield(method) block.yield(method)
end end
end end

View File

@ -5,7 +5,7 @@ module Mom
class TestObjectMissingRisc < BootTest class TestObjectMissingRisc < BootTest
def setup def setup
super super
@method = get_compiler(:method_missing) @method = get_object_compiler(:_method_missing)
end end
def test_compile def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class

View File

@ -5,7 +5,7 @@ module Mom
class TestObjectGet < BootTest class TestObjectGet < BootTest
def setup def setup
super super
@method = get_compiler(:get_internal_word) @method = get_object_compiler(:get_internal_word)
end end
def test_has_get_internal def test_has_get_internal
assert_equal Mom::MethodCompiler , @method.class assert_equal Mom::MethodCompiler , @method.class
@ -17,7 +17,7 @@ module Mom
class TestObjectSet < BootTest class TestObjectSet < BootTest
def setup def setup
super super
@method = get_compiler(:set_internal_word) @method = get_object_compiler(:set_internal_word)
end end
def test_has_get_internal def test_has_get_internal
assert_equal Mom::MethodCompiler , @method.class assert_equal Mom::MethodCompiler , @method.class
@ -29,7 +29,7 @@ module Mom
class TestObjectMissing < BootTest class TestObjectMissing < BootTest
def setup def setup
super super
@method = get_compiler(:method_missing) @method = get_object_compiler(:_method_missing)
end end
def test_has_get_internal def test_has_get_internal
assert_equal Mom::MethodCompiler , @method.class assert_equal Mom::MethodCompiler , @method.class
@ -41,7 +41,7 @@ module Mom
class TestObjectExit < BootTest class TestObjectExit < BootTest
def setup def setup
super super
@method = get_compiler(:exit) @method = get_object_compiler(:exit)
end end
def test_has_get_internal def test_has_get_internal
assert_equal Mom::MethodCompiler , @method.class assert_equal Mom::MethodCompiler , @method.class
@ -53,7 +53,7 @@ module Mom
class TestObjectInit < BootTest class TestObjectInit < BootTest
def setup def setup
super super
@method = get_compiler(:__init__) @method = get_object_compiler(:__init__)
end end
def test_has_get_internal def test_has_get_internal
assert_equal Mom::MethodCompiler , @method.class assert_equal Mom::MethodCompiler , @method.class

View File

@ -8,7 +8,7 @@ module Mom
end end
def each_method &block def each_method &block
Risc.operators.each do |name| Risc.operators.each do |name|
method = get_compiler(name) method = get_operator_compiler(name)
block.yield(method) block.yield(method)
end end
end end
@ -19,7 +19,7 @@ module Mom
end end
def test_risc_length def test_risc_length
each_method do |method| each_method do |method|
assert_equal 49 , method.to_risc.risc_instructions.length assert_equal 48 , method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -5,7 +5,7 @@ module Mom
class TestWordPutRisc < BootTest class TestWordPutRisc < BootTest
def setup def setup
super super
@method = get_compiler(:putstring) @method = get_word_compiler(:putstring)
end end
def test_compile def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class

View File

@ -5,13 +5,13 @@ module Mom
class TestWordSetRisc < BootTest class TestWordSetRisc < BootTest
def setup def setup
super super
@method = get_compiler(:set_internal_byte) @method = get_word_compiler(:set_internal_byte)
end end
def test_compile def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class
end end
def test_risc_length def test_risc_length
assert_equal 22 , @method.to_risc.risc_instructions.length assert_equal 21 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -5,13 +5,13 @@ module Mom
class TestWordSetRisc < BootTest class TestWordSetRisc < BootTest
def setup def setup
super super
@method = get_compiler(:set_internal_byte) @method = get_object_compiler(:set_internal_word)
end end
def test_compile def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class
end end
def test_risc_length def test_risc_length
assert_equal 22 , @method.to_risc.risc_instructions.length assert_equal 20 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -5,7 +5,7 @@ module Mom
class TestWordPut < BootTest class TestWordPut < BootTest
def setup def setup
super super
@method = get_compiler(:putstring) @method = get_word_compiler(:putstring)
end end
def test_has_get_internal def test_has_get_internal
assert_equal Mom::MethodCompiler , @method.class assert_equal Mom::MethodCompiler , @method.class
@ -17,7 +17,7 @@ module Mom
class TestWordGet < BootTest class TestWordGet < BootTest
def setup def setup
super super
@method = get_compiler(:get_internal_byte) @method = get_word_compiler(:get_internal_byte)
end end
def test_has_get_internal def test_has_get_internal
assert_equal Mom::MethodCompiler , @method.class assert_equal Mom::MethodCompiler , @method.class
@ -29,7 +29,7 @@ module Mom
class TestWordSet < BootTest class TestWordSet < BootTest
def setup def setup
super super
@method = get_compiler(:set_internal_byte) @method = get_word_compiler(:set_internal_byte)
end end
def test_has_get_internal def test_has_get_internal
assert_equal Mom::MethodCompiler , @method.class assert_equal Mom::MethodCompiler , @method.class