small test fixes

This commit is contained in:
Torsten Ruger 2018-06-25 20:21:15 +03:00
parent 67a6ef9f67
commit 4103da7490
5 changed files with 43 additions and 19 deletions

View File

@ -11,8 +11,14 @@ module Elf
Risc.machine.boot Risc.machine.boot
end end
def check(file) def in_space(input)
Vool::VoolCompiler.ruby_to_binary( "class Space;def main(arg);#{@input};end;end" ) "class Space; #{input} ; end"
end
def as_main(input)
in_space("def main(arg);#{input};end")
end
def check(input, file)
Vool::VoolCompiler.ruby_to_binary( input )
writer = Elf::ObjectWriter.new(Risc.machine) writer = Elf::ObjectWriter.new(Risc.machine)
writer.save "test/#{file}.o" writer.save "test/#{file}.o"
end end

View File

@ -1,12 +0,0 @@
require_relative "helper"
module Elf
class AddTest < FullTest
def test_add
@input = "return 2 + 2"
@exit_code = 4
check "add"
end
end
end

View File

@ -0,0 +1,28 @@
require_relative "helper"
module Elf
class SomethingTest < FullTest
def test_add
input = <<HERE
def fibo( n)
a = 0
b = 1
i = 1
while( i < n ) do
result = a + b
a = b
b = result
i += 1
end
return result
end
def main(arg)
return fibo(20)
end
HERE
@exit_code = 4
check in_space(input) , "fibo"
end
end
end

View File

@ -1,14 +1,14 @@
require_relative "helper" require_relative "helper"
module Elf module Elf
class HelloTest < FullTest class SomeOtherTest < FullTest
def test_string_put def test_string_put
hello = "Hello World!\n" hello = "Hello World!\n"
@input = "return '#{hello}'.putstring" input = "return '#{hello}'.putstring"
@stdout = hello @stdout = hello
@exit_code = hello.length @exit_code = hello.length
check "hello" check as_main(input), "hello"
end end
end end
end end

View File

@ -16,10 +16,12 @@ class TestZeroCode < MiniTest::Test
name == :main or name == :__init__ name == :main or name == :__init__
end end
def pest_empty_translate def test_empty_translate
assert_equal 2 , @space.get_all_methods.length assert_equal 2 , @space.get_all_methods.length
@machine.translate(:arm) @machine.translate(:arm)
writer = Elf::ObjectWriter.new(@machine , @objects ) @machine.position_all
@machine.create_binary
writer = Elf::ObjectWriter.new(@machine )
writer.save "test/zero.o" writer.save "test/zero.o"
end end