From ae976c8fb90febf71549e6ce1347938a87edba3c Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 24 Jun 2018 16:48:23 +0300 Subject: [PATCH] generate mains test methods according to file name --- test/mains/helper.rb | 12 +++--------- test/mains/test_adds.rb | 16 ---------------- test/mains/test_interpreted.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 25 deletions(-) delete mode 100644 test/mains/test_adds.rb create mode 100644 test/mains/test_interpreted.rb diff --git a/test/mains/helper.rb b/test/mains/helper.rb index 2b90c8a7..78073e8d 100644 --- a/test/mains/helper.rb +++ b/test/mains/helper.rb @@ -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 diff --git a/test/mains/test_adds.rb b/test/mains/test_adds.rb deleted file mode 100644 index ea7c22d5..00000000 --- a/test/mains/test_adds.rb +++ /dev/null @@ -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 diff --git a/test/mains/test_interpreted.rb b/test/mains/test_interpreted.rb new file mode 100644 index 00000000..367c07f9 --- /dev/null +++ b/test/mains/test_interpreted.rb @@ -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