rebooting tests for small compiles
This commit is contained in:
parent
7b1e89effb
commit
b83f50c57c
@ -71,10 +71,6 @@ module Virtual
|
|||||||
@codes.inject(0){|count , instruction| count += instruction.byte_length }
|
@codes.inject(0){|count , instruction| count += instruction.byte_length }
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
|
||||||
Sof.write(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
# helper for determining reachable blocks
|
# helper for determining reachable blocks
|
||||||
def add_next ret
|
def add_next ret
|
||||||
|
@ -9,9 +9,6 @@ module Virtual
|
|||||||
# instructions, thus defining a minimal set of instructions needed to implement oo.
|
# instructions, thus defining a minimal set of instructions needed to implement oo.
|
||||||
|
|
||||||
class Instruction
|
class Instruction
|
||||||
def to_s
|
|
||||||
Sof.write(self)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -128,13 +128,6 @@ module Parfait
|
|||||||
old_length = old_length - 1
|
old_length = old_length - 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
|
||||||
Sof.write(self)
|
|
||||||
end
|
|
||||||
def inspect
|
|
||||||
to_s
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
class List
|
class List
|
||||||
def to_sof_node(writer , level , ref )
|
def to_sof_node(writer , level , ref )
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
require_relative "test_foo"
|
require_relative "test_foo"
|
||||||
|
require_relative "test_if"
|
||||||
#require_relative "test_functions"
|
#require_relative "test_functions"
|
||||||
#require_relative "test_hello"
|
#require_relative "test_hello"
|
||||||
#require_relative "test_if"
|
|
||||||
#require_relative "test_putint"
|
#require_relative "test_putint"
|
||||||
#require_relative "test_recursive_fibo"
|
#require_relative "test_recursive_fibo"
|
||||||
#require_relative "test_while_fibo"
|
#require_relative "test_while_fibo"
|
||||||
|
@ -5,7 +5,7 @@ class TestFoo < MiniTest::Test
|
|||||||
|
|
||||||
def test_foo2
|
def test_foo2
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
def foo(x)
|
def foo2(x)
|
||||||
a = 5
|
a = 5
|
||||||
end
|
end
|
||||||
3.foo( 4 )
|
3.foo( 4 )
|
||||||
|
@ -3,7 +3,19 @@ require_relative 'helper'
|
|||||||
class TestIf < MiniTest::Test
|
class TestIf < MiniTest::Test
|
||||||
include Fragments
|
include Fragments
|
||||||
|
|
||||||
def test_if
|
def test_if_basic
|
||||||
|
@string_input = <<HERE
|
||||||
|
if( n < 12)
|
||||||
|
3
|
||||||
|
else
|
||||||
|
4
|
||||||
|
end
|
||||||
|
HERE
|
||||||
|
@expect = [Virtual::Return ]
|
||||||
|
check
|
||||||
|
end
|
||||||
|
|
||||||
|
def ttest_if_function
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
def itest(n)
|
def itest(n)
|
||||||
if( n < 12)
|
if( n < 12)
|
||||||
@ -15,11 +27,7 @@ end
|
|||||||
|
|
||||||
itest(20)
|
itest(20)
|
||||||
HERE
|
HERE
|
||||||
@should = [0x0,0x40,0x2d,0xe9,0xc,0x0,0x53,0xe3,0x3,0x0,0x0,0xba,0x34,0x20,0x8f,0xe2,0x8,0x30,0xa0,0xe3,0xd4,0xff,0xff,0xeb,0x2,0x0,0x0,0xea,0x2c,0x20,0x8f,0xe2,0x8,0x30,0xa0,0xe3,0xd0,0xff,0xff,0xeb,0x0,0x80,0xbd,0xe8]
|
@expect = [Virtual::Return ]
|
||||||
@output = "else "
|
check
|
||||||
@target = [:Object , :itest]
|
|
||||||
parse
|
|
||||||
write "if"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
require_relative "virtual_helper"
|
require_relative "virtual_helper"
|
||||||
|
|
||||||
|
|
||||||
class TestBasic < MiniTest::Test
|
class TestBasic < MiniTest::Test
|
||||||
include VirtualHelper
|
def check
|
||||||
|
expressions = Virtual.machine.boot.compile_main @string_input
|
||||||
|
if( expressions.first.is_a? Virtual::Self )
|
||||||
|
expressions.first.type.instance_variable_set :@of_class , nil
|
||||||
|
end
|
||||||
|
is = Sof.write(expressions)
|
||||||
|
#puts is
|
||||||
|
assert_equal @output , is
|
||||||
|
end
|
||||||
|
|
||||||
def test_number
|
def test_number
|
||||||
@string_input = '42 '
|
@string_input = '42 '
|
||||||
|
@ -1,16 +1,38 @@
|
|||||||
require_relative "virtual_helper"
|
require_relative "virtual_helper"
|
||||||
|
|
||||||
class TestMethods < MiniTest::Test
|
module Virtual
|
||||||
include VirtualHelper
|
class TestMethods < MiniTest::Test
|
||||||
#TODO need to rethink this approach
|
|
||||||
# Sof working as well as it is will serialize the whole space as everythink is reachable from a
|
def check
|
||||||
# method. Even ignoring the size and readability issues, it make sthe test to fragile:
|
Virtual.machine.boot.compile_main @string_input
|
||||||
# any small object change anywhere in parfait will cause a different output
|
produced = Virtual.machine.space.get_main.source
|
||||||
def ttest_simplest_function
|
assert @output , "No output given"
|
||||||
@string_input = <<HERE
|
assert_equal @output.length , produced.blocks.length , "Block length"
|
||||||
|
produced.blocks.each_with_index do |b,i|
|
||||||
|
codes = @output[i]
|
||||||
|
assert codes , "No codes for block #{i}"
|
||||||
|
assert_equal b.codes.length , codes.length , "Code length for block #{i}"
|
||||||
|
b.codes.each_with_index do |c , ii |
|
||||||
|
assert_equal codes[ii] , c.class , "Block #{i} , code #{ii}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_simplest_function
|
||||||
|
@string_input = <<HERE
|
||||||
def foo(x)
|
def foo(x)
|
||||||
5
|
5
|
||||||
end
|
end
|
||||||
|
HERE
|
||||||
|
@output = [[MethodEnter] ,[MethodReturn]]
|
||||||
|
check
|
||||||
|
end
|
||||||
|
|
||||||
|
def ttest_second_simplest_function
|
||||||
|
@string_input = <<HERE
|
||||||
|
def foo(x)
|
||||||
|
x
|
||||||
|
end
|
||||||
HERE
|
HERE
|
||||||
@output = nil
|
@output = nil
|
||||||
check
|
check
|
||||||
@ -142,3 +164,4 @@ HERE
|
|||||||
check
|
check
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
@ -1,37 +1,13 @@
|
|||||||
require_relative '../helper'
|
require_relative '../helper'
|
||||||
require 'parslet/convenience'
|
require 'parslet/convenience'
|
||||||
require "yaml"
|
|
||||||
|
|
||||||
Parfait::Object.class_eval do
|
|
||||||
def secret_layout_hammer
|
|
||||||
internal_object_set(Parfait::Object::LAYOUT_INDEX , nil)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module VirtualHelper
|
module VirtualHelper
|
||||||
# need a code generator, for arm
|
|
||||||
def setup
|
|
||||||
@machine = Virtual.machine.boot
|
|
||||||
end
|
|
||||||
|
|
||||||
def check
|
def check
|
||||||
expressions = @machine.compile_main @string_input
|
Virtual.machine.boot.compile_main @string_input
|
||||||
if( expressions.first.is_a? Parfait::Method )
|
produced = Virtual.machine.space.get_main.source
|
||||||
# stops the whole objectspace beeing tested
|
assert_equal @output , produced
|
||||||
# with the class comes superclass and all methods
|
|
||||||
expressions.first.instance_variable_set :@for_class , nil
|
|
||||||
expressions.first.secret_layout_hammer
|
|
||||||
expressions.first.code.secret_layout_hammer
|
|
||||||
end
|
|
||||||
if( expressions.first.is_a? Virtual::Self )
|
|
||||||
# stops the whole objectspace beeing tested
|
|
||||||
# with the class comes superclass and all methods
|
|
||||||
expressions.first.type.instance_variable_set :@of_class , nil
|
|
||||||
end
|
|
||||||
is = Sof.write(expressions)
|
|
||||||
#puts is
|
|
||||||
is.gsub!("\n" , "*^*")
|
|
||||||
assert_equal @output , is
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user