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
def setup
Parfait.boot!(Parfait.default_test_options)
@functions = Builtin.boot_functions
Builtin.compiler_for( Parfait.object_space.get_class.instance_type , Space , :main)
end
def get_compiler( name )
@functions.each.find{|meth| meth.callable.name == name}
def get_int_compiler(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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,13 +5,13 @@ module Mom
class TestWordGetRisc < BootTest
def setup
super
@method = get_compiler(:get_internal_byte)
@method = get_word_compiler(:get_internal_byte)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
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

View File

@ -5,13 +5,13 @@ module Mom
class TestWordGetRisc < BootTest
def setup
super
@method = get_compiler(:get_internal_byte)
@method = get_object_compiler(:get_internal_word)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,7 +8,7 @@ module Mom
end
def each_method &block
Risc.operators.each do |name|
method = get_compiler(name)
method = get_operator_compiler(name)
block.yield(method)
end
end
@ -19,7 +19,7 @@ module Mom
end
def test_risc_length
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

View File

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

View File

@ -5,13 +5,13 @@ module Mom
class TestWordSetRisc < BootTest
def setup
super
@method = get_compiler(:set_internal_byte)
@method = get_word_compiler(:set_internal_byte)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
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

View File

@ -5,13 +5,13 @@ module Mom
class TestWordSetRisc < BootTest
def setup
super
@method = get_compiler(:set_internal_byte)
@method = get_object_compiler(:set_internal_word)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
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

View File

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