automate mains test more
move sources and include exit code and stdout in filename
This commit is contained in:
parent
563ed4647a
commit
8d369dbfa1
@ -6,8 +6,15 @@ module Mains
|
||||
def setup;end
|
||||
|
||||
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)
|
||||
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
|
||||
|
1
test/mains/source/puts_Hello-there_11.rb
Normal file
1
test/mains/source/puts_Hello-there_11.rb
Normal file
@ -0,0 +1 @@
|
||||
return "Hello-there".putstring
|
@ -5,15 +5,12 @@ module Mains
|
||||
|
||||
def test_ruby_adds
|
||||
run_main_file "adds"
|
||||
assert_equal 10 , get_return
|
||||
end
|
||||
def test_ruby_subs
|
||||
run_main_file "subs"
|
||||
assert_equal 0 , get_return
|
||||
end
|
||||
def test_ruby_adds_fibo
|
||||
run_main_file "fibo"
|
||||
assert_equal 8 , get_return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,11 +3,9 @@ require_relative 'helper'
|
||||
module Mains
|
||||
class TestPuts < MainsTest
|
||||
|
||||
def test_say_hi
|
||||
hi = "Hello there"
|
||||
run_main_return "'#{hi}'.putstring"
|
||||
assert_equal hi.length , get_return
|
||||
assert_equal hi , @interpreter.stdout
|
||||
def test_ruby_puts
|
||||
run_main_file "puts"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user