automate mains test more

move sources and include exit code and stdout in filename
This commit is contained in:
Torsten Ruger 2018-06-24 13:37:36 +03:00
parent 563ed4647a
commit 8d369dbfa1
7 changed files with 12 additions and 9 deletions

View File

@ -6,8 +6,15 @@ module Mains
def setup;end def setup;end
def run_main_file(file) def run_main_file(file)
input = File.read("test/mains/#{file}.rb") file_name = Dir["test/mains/source/#{file}*.rb"].first
assert file_name , "no file #{file_name}"
input = File.read(file_name)
basename = file_name.split("/").last.split(".").first
_ , stdout , exit_code = basename.split("_")
stdout = "" unless stdout
run_main(input) run_main(input)
assert_equal stdout , @interpreter.stdout , "Wrong stdout for #{file}"
assert_equal exit_code , get_return.to_s , "Wrong exit code for #{file}"
end end
end end
end end

View File

@ -0,0 +1 @@
return "Hello-there".putstring

View File

@ -5,15 +5,12 @@ module Mains
def test_ruby_adds def test_ruby_adds
run_main_file "adds" run_main_file "adds"
assert_equal 10 , get_return
end end
def test_ruby_subs def test_ruby_subs
run_main_file "subs" run_main_file "subs"
assert_equal 0 , get_return
end end
def test_ruby_adds_fibo def test_ruby_adds_fibo
run_main_file "fibo" run_main_file "fibo"
assert_equal 8 , get_return
end end
end end
end end

View File

@ -3,11 +3,9 @@ require_relative 'helper'
module Mains module Mains
class TestPuts < MainsTest class TestPuts < MainsTest
def test_say_hi def test_ruby_puts
hi = "Hello there" run_main_file "puts"
run_main_return "'#{hi}'.putstring"
assert_equal hi.length , get_return
assert_equal hi , @interpreter.stdout
end end
end end
end end