From 8d369dbfa1206d7e2abf1e2c57a131c71121c9fb Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 24 Jun 2018 13:37:36 +0300 Subject: [PATCH] automate mains test more move sources and include exit code and stdout in filename --- test/mains/helper.rb | 9 ++++++++- test/mains/{adds.rb => source/adds__10.rb} | 0 test/mains/{fibo.rb => source/fibo__8.rb} | 0 test/mains/source/puts_Hello-there_11.rb | 1 + test/mains/{subs.rb => source/subs__0.rb} | 0 test/mains/test_adds.rb | 3 --- test/mains/test_puts.rb | 8 +++----- 7 files changed, 12 insertions(+), 9 deletions(-) rename test/mains/{adds.rb => source/adds__10.rb} (100%) rename test/mains/{fibo.rb => source/fibo__8.rb} (100%) create mode 100644 test/mains/source/puts_Hello-there_11.rb rename test/mains/{subs.rb => source/subs__0.rb} (100%) diff --git a/test/mains/helper.rb b/test/mains/helper.rb index 024f30fc..2b90c8a7 100644 --- a/test/mains/helper.rb +++ b/test/mains/helper.rb @@ -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 diff --git a/test/mains/adds.rb b/test/mains/source/adds__10.rb similarity index 100% rename from test/mains/adds.rb rename to test/mains/source/adds__10.rb diff --git a/test/mains/fibo.rb b/test/mains/source/fibo__8.rb similarity index 100% rename from test/mains/fibo.rb rename to test/mains/source/fibo__8.rb diff --git a/test/mains/source/puts_Hello-there_11.rb b/test/mains/source/puts_Hello-there_11.rb new file mode 100644 index 00000000..dbd6612b --- /dev/null +++ b/test/mains/source/puts_Hello-there_11.rb @@ -0,0 +1 @@ +return "Hello-there".putstring diff --git a/test/mains/subs.rb b/test/mains/source/subs__0.rb similarity index 100% rename from test/mains/subs.rb rename to test/mains/source/subs__0.rb diff --git a/test/mains/test_adds.rb b/test/mains/test_adds.rb index 4470b088..ea7c22d5 100644 --- a/test/mains/test_adds.rb +++ b/test/mains/test_adds.rb @@ -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 diff --git a/test/mains/test_puts.rb b/test/mains/test_puts.rb index 74d2cf55..eb520de4 100644 --- a/test/mains/test_puts.rb +++ b/test/mains/test_puts.rb @@ -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