diff --git a/test/mains/source/add__4.rb b/test/mains/source/add__4.rb index 7758ea60..0b0fb26a 100644 --- a/test/mains/source/add__4.rb +++ b/test/mains/source/add__4.rb @@ -1 +1,5 @@ -return 2 +2 +class Space + def main(arg) + return 2 +2 + end +end diff --git a/test/mains/source/adds__10.rb b/test/mains/source/adds__10.rb index c65f5cca..55e782c3 100644 --- a/test/mains/source/adds__10.rb +++ b/test/mains/source/adds__10.rb @@ -1,7 +1,11 @@ -a = 0 -b = 20 -while( a < b ) - a = a + 1 - b = b - 1 +class Space + def main(arg) + a = 0 + b = 20 + while( a < b ) + a = a + 1 + b = b - 1 + end + return a + end end -return a diff --git a/test/mains/source/fibo__8.rb b/test/mains/source/fibo__8.rb index ba5f94ae..70f8aa58 100644 --- a/test/mains/source/fibo__8.rb +++ b/test/mains/source/fibo__8.rb @@ -1,11 +1,15 @@ -n = 6 -a = 0 -b = 1 -i = 1 -while( i < n ) - result = a + b - a = b - b = result - i = i + 1 +class Space + def main(arg) + n = 6 + a = 0 + b = 1 + i = 1 + while( i < n ) + result = a + b + a = b + b = result + i = i + 1 + end + return result + end end -return result diff --git a/test/mains/source/puts_Hello-there_11.rb b/test/mains/source/puts_Hello-there_11.rb index dbd6612b..59dcf17c 100644 --- a/test/mains/source/puts_Hello-there_11.rb +++ b/test/mains/source/puts_Hello-there_11.rb @@ -1 +1,5 @@ -return "Hello-there".putstring +class Space + def main(arg) + return "Hello-there".putstring + end +end diff --git a/test/mains/source/subs__0.rb b/test/mains/source/subs__0.rb index 65b3cf5f..e9823acb 100644 --- a/test/mains/source/subs__0.rb +++ b/test/mains/source/subs__0.rb @@ -1,5 +1,9 @@ -b = 10 -while( b >= 1 ) - b = b - 1 +class Space + def main(arg) + b = 10 + while( b >= 1 ) + b = b - 1 + end + return b + end end -return b diff --git a/test/mains/test_interpreted.rb b/test/mains/test_interpreted.rb index 7f1d3d61..832077e4 100644 --- a/test/mains/test_interpreted.rb +++ b/test/mains/test_interpreted.rb @@ -16,7 +16,7 @@ module Mains tests << method_name input = File.read(file_name) self.send(:define_method, method_name ) do - ticks = run_main(input) + ticks = run_input(input) #puts "Ticks for #{method_name}=#{ticks}" assert_equal stdout , @interpreter.stdout , "Wrong stdout #{name}" assert_equal exit_code , get_return.to_s , "Wrong exit code #{name}" diff --git a/test/support/risc_interpreter.rb b/test/support/risc_interpreter.rb index ba56ccc5..3f5fbd47 100644 --- a/test/support/risc_interpreter.rb +++ b/test/support/risc_interpreter.rb @@ -92,8 +92,16 @@ module Risc def get_message_return @interpreter.get_register(:r8).return_value end + + # wrap the input so it is a main, compile and run it 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 run_all end