generate mains test methods according to file name

This commit is contained in:
Torsten Ruger 2018-06-24 16:48:23 +03:00
parent 8d369dbfa1
commit ae976c8fb9
3 changed files with 31 additions and 25 deletions

View File

@ -5,16 +5,10 @@ module Mains
include Risc::Ticker
def setup;end
def run_main_file(file)
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
def run_main_check(input , stdout , exit_code)
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}"
assert_equal stdout , @interpreter.stdout , "Wrong stdout"
assert_equal exit_code , get_return.to_s , "Wrong exit code"
end
end
end

View File

@ -1,16 +0,0 @@
require_relative 'helper'
module Mains
class TestAdds < MainsTest
def test_ruby_adds
run_main_file "adds"
end
def test_ruby_subs
run_main_file "subs"
end
def test_ruby_adds_fibo
run_main_file "fibo"
end
end
end

View File

@ -0,0 +1,28 @@
require_relative 'helper'
module Mains
class TestInterpreted < MiniTest::Test
include Risc::Ticker
def setup;end
# runnable_methods is called by minitest to determine which tests to run
def self.runnable_methods
all = Dir["test/mains/source/*.rb"]
tests =[]
all.each do |file_name|
fullname = file_name.split("/").last.split(".").first
name , stdout , exit_code = fullname.split("_")
method_name = "test_#{name}"
tests << method_name
input = File.read(file_name)
self.send(:define_method, method_name ) do
run_main(input)
assert_equal stdout , @interpreter.stdout , "Wrong stdout #{name}"
assert_equal exit_code , get_return.to_s , "Wrong exit code #{name}"
end
end
tests
end
end
end