mains tests can include any code

not wrapping as main anymore
(must still include mains)
first part of #11
This commit is contained in:
Torsten Ruger 2018-08-18 19:42:14 +03:00
parent 233b83510f
commit 80264c5322
7 changed files with 52 additions and 24 deletions

View File

@ -1 +1,5 @@
class Space
def main(arg)
return 2 +2 return 2 +2
end
end

View File

@ -1,3 +1,5 @@
class Space
def main(arg)
a = 0 a = 0
b = 20 b = 20
while( a < b ) while( a < b )
@ -5,3 +7,5 @@ while( a < b )
b = b - 1 b = b - 1
end end
return a return a
end
end

View File

@ -1,3 +1,5 @@
class Space
def main(arg)
n = 6 n = 6
a = 0 a = 0
b = 1 b = 1
@ -9,3 +11,5 @@ while( i < n )
i = i + 1 i = i + 1
end end
return result return result
end
end

View File

@ -1 +1,5 @@
class Space
def main(arg)
return "Hello-there".putstring return "Hello-there".putstring
end
end

View File

@ -1,5 +1,9 @@
class Space
def main(arg)
b = 10 b = 10
while( b >= 1 ) while( b >= 1 )
b = b - 1 b = b - 1
end end
return b return b
end
end

View File

@ -16,7 +16,7 @@ module Mains
tests << method_name tests << method_name
input = File.read(file_name) input = File.read(file_name)
self.send(:define_method, method_name ) do self.send(:define_method, method_name ) do
ticks = run_main(input) ticks = run_input(input)
#puts "Ticks for #{method_name}=#{ticks}" #puts "Ticks for #{method_name}=#{ticks}"
assert_equal stdout , @interpreter.stdout , "Wrong stdout #{name}" assert_equal stdout , @interpreter.stdout , "Wrong stdout #{name}"
assert_equal exit_code , get_return.to_s , "Wrong exit code #{name}" assert_equal exit_code , get_return.to_s , "Wrong exit code #{name}"

View File

@ -92,8 +92,16 @@ module Risc
def get_message_return def get_message_return
@interpreter.get_register(:r8).return_value @interpreter.get_register(:r8).return_value
end end
# wrap the input so it is a main, compile and run it
def run_main(input) def run_main(input)
@string_input = as_main(input) run_input as_main(input)
end
# use the input as it, compile and run it
# input muts contain a Space.main, but may contain more classes and methods
def run_input(input)
@string_input = input
do_setup do_setup
run_all run_all
end end