From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- jni/ruby/test/testunit/test4test_hideskip.rb | 9 + jni/ruby/test/testunit/test4test_redefinition.rb | 13 ++ jni/ruby/test/testunit/test4test_sorting.rb | 17 ++ jni/ruby/test/testunit/test_assertion.rb | 8 + jni/ruby/test/testunit/test_hideskip.rb | 16 ++ jni/ruby/test/testunit/test_parallel.rb | 191 +++++++++++++++++++++ jni/ruby/test/testunit/test_rake_integration.rb | 35 ++++ jni/ruby/test/testunit/test_redefinition.rb | 15 ++ jni/ruby/test/testunit/test_sorting.rb | 17 ++ .../testunit/tests_for_parallel/ptest_first.rb | 7 + .../testunit/tests_for_parallel/ptest_forth.rb | 29 ++++ .../testunit/tests_for_parallel/ptest_second.rb | 11 ++ .../testunit/tests_for_parallel/ptest_third.rb | 10 ++ .../test/testunit/tests_for_parallel/runner.rb | 13 ++ 14 files changed, 391 insertions(+) create mode 100644 jni/ruby/test/testunit/test4test_hideskip.rb create mode 100644 jni/ruby/test/testunit/test4test_redefinition.rb create mode 100644 jni/ruby/test/testunit/test4test_sorting.rb create mode 100644 jni/ruby/test/testunit/test_assertion.rb create mode 100644 jni/ruby/test/testunit/test_hideskip.rb create mode 100644 jni/ruby/test/testunit/test_parallel.rb create mode 100644 jni/ruby/test/testunit/test_rake_integration.rb create mode 100644 jni/ruby/test/testunit/test_redefinition.rb create mode 100644 jni/ruby/test/testunit/test_sorting.rb create mode 100644 jni/ruby/test/testunit/tests_for_parallel/ptest_first.rb create mode 100644 jni/ruby/test/testunit/tests_for_parallel/ptest_forth.rb create mode 100644 jni/ruby/test/testunit/tests_for_parallel/ptest_second.rb create mode 100644 jni/ruby/test/testunit/tests_for_parallel/ptest_third.rb create mode 100644 jni/ruby/test/testunit/tests_for_parallel/runner.rb (limited to 'jni/ruby/test/testunit') diff --git a/jni/ruby/test/testunit/test4test_hideskip.rb b/jni/ruby/test/testunit/test4test_hideskip.rb new file mode 100644 index 0000000..7dba6f5 --- /dev/null +++ b/jni/ruby/test/testunit/test4test_hideskip.rb @@ -0,0 +1,9 @@ +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" + +require 'test/unit' + +class TestForTestHideSkip < Test::Unit::TestCase + def test_skip + skip "do nothing" + end +end diff --git a/jni/ruby/test/testunit/test4test_redefinition.rb b/jni/ruby/test/testunit/test4test_redefinition.rb new file mode 100644 index 0000000..77cfd45 --- /dev/null +++ b/jni/ruby/test/testunit/test4test_redefinition.rb @@ -0,0 +1,13 @@ +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" + +require 'test/unit' + +class TestForTestRedefinition < Test::Unit::TestCase + def test_redefinition + skip "do nothing (1)" + end + + def test_redefinition + skip "do nothing (2)" + end +end diff --git a/jni/ruby/test/testunit/test4test_sorting.rb b/jni/ruby/test/testunit/test4test_sorting.rb new file mode 100644 index 0000000..b8bb943 --- /dev/null +++ b/jni/ruby/test/testunit/test4test_sorting.rb @@ -0,0 +1,17 @@ +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" + +require 'test/unit' + +class TestForTestHideSkip < Test::Unit::TestCase + def test_c + skip "do nothing" + end + + def test_b + assert_equal true, false + end + + def test_a + raise + end +end diff --git a/jni/ruby/test/testunit/test_assertion.rb b/jni/ruby/test/testunit/test_assertion.rb new file mode 100644 index 0000000..374d6e0 --- /dev/null +++ b/jni/ruby/test/testunit/test_assertion.rb @@ -0,0 +1,8 @@ +require 'test/unit' +class TestAssertion < Test::Unit::TestCase + def test_wrong_assertion + error, line = assert_raise(ArgumentError) {assert(true, true)}, __LINE__ + assert_match(/assertion message must be String or Proc, but TrueClass was given/, error.message) + assert_match(/\A#{Regexp.quote(__FILE__)}:#{line}:/, error.backtrace[0]) + end +end diff --git a/jni/ruby/test/testunit/test_hideskip.rb b/jni/ruby/test/testunit/test_hideskip.rb new file mode 100644 index 0000000..e696b5e --- /dev/null +++ b/jni/ruby/test/testunit/test_hideskip.rb @@ -0,0 +1,16 @@ +require 'test/unit' + +class TestHideSkip < Test::Unit::TestCase + def test_hideskip + assert_not_match(/assertions\/s.\n\n 1\) Skipped/, hideskip) + assert_match(/assertions\/s.\n\n 1\) Skipped/, hideskip("--show-skip")) + assert_match(/assertions\/s.\n\n1 tests, 0 assertions, 0 failures, 0 errors, 1 skips/, hideskip("--hide-skip")) + end + + def hideskip(*args) + IO.popen([*@options[:ruby], "#{File.dirname(__FILE__)}/test4test_hideskip.rb", + "--verbose", *args], err: [:child, :out]) {|f| + f.read + } + end +end diff --git a/jni/ruby/test/testunit/test_parallel.rb b/jni/ruby/test/testunit/test_parallel.rb new file mode 100644 index 0000000..db3f47e --- /dev/null +++ b/jni/ruby/test/testunit/test_parallel.rb @@ -0,0 +1,191 @@ +require 'test/unit' +require 'timeout' + +module TestParallel + PARALLEL_RB = "#{File.dirname(__FILE__)}/../lib/test/unit/parallel.rb" + TESTS = "#{File.dirname(__FILE__)}/tests_for_parallel" + + class TestParallelWorker < Test::Unit::TestCase + def setup + i, @worker_in = IO.pipe + @worker_out, o = IO.pipe + @worker_pid = spawn(*@options[:ruby], PARALLEL_RB, + "--ruby", @options[:ruby].join(" "), + "-j", "t1", "-v", out: o, in: i) + [i,o].each(&:close) + end + + def teardown + if @worker_pid && @worker_in + begin + begin + @worker_in.puts "quit" + rescue IOError, Errno::EPIPE + end + timeout(2) do + Process.waitpid(@worker_pid) + end + rescue Timeout::Error + begin + Process.kill(:KILL, @worker_pid) + rescue Errno::ESRCH + end + end + end + ensure + @worker_in.close + @worker_out.close + end + + def test_run + timeout(10) do + assert_match(/^ready/,@worker_out.gets) + @worker_in.puts "run #{TESTS}/ptest_first.rb test" + assert_match(/^okay/,@worker_out.gets) + assert_match(/^p/,@worker_out.gets) + assert_match(/^done/,@worker_out.gets) + assert_match(/^ready/,@worker_out.gets) + end + end + + def test_run_multiple_testcase_in_one_file + timeout(10) do + assert_match(/^ready/,@worker_out.gets) + @worker_in.puts "run #{TESTS}/ptest_second.rb test" + assert_match(/^okay/,@worker_out.gets) + assert_match(/^p/,@worker_out.gets) + assert_match(/^done/,@worker_out.gets) + assert_match(/^p/,@worker_out.gets) + assert_match(/^done/,@worker_out.gets) + assert_match(/^ready/,@worker_out.gets) + end + end + + def test_accept_run_command_multiple_times + timeout(10) do + assert_match(/^ready/,@worker_out.gets) + @worker_in.puts "run #{TESTS}/ptest_first.rb test" + assert_match(/^okay/,@worker_out.gets) + assert_match(/^p/,@worker_out.gets) + assert_match(/^done/,@worker_out.gets) + assert_match(/^ready/,@worker_out.gets) + @worker_in.puts "run #{TESTS}/ptest_second.rb test" + assert_match(/^okay/,@worker_out.gets) + assert_match(/^p/,@worker_out.gets) + assert_match(/^done/,@worker_out.gets) + assert_match(/^p/,@worker_out.gets) + assert_match(/^done/,@worker_out.gets) + assert_match(/^ready/,@worker_out.gets) + end + end + + def test_p + timeout(10) do + @worker_in.puts "run #{TESTS}/ptest_first.rb test" + while buf = @worker_out.gets + break if /^p (.+?)$/ =~ buf + end + assert_match(/TestA#test_nothing_test = \d+\.\d+ s = \.\n/, $1.chomp.unpack("m")[0]) + end + end + + def test_done + timeout(10) do + @worker_in.puts "run #{TESTS}/ptest_forth.rb test" + 7.times { @worker_out.gets } + buf = @worker_out.gets + assert_match(/^done (.+?)$/, buf) + + /^done (.+?)$/ =~ buf + + result = Marshal.load($1.chomp.unpack("m")[0]) + + assert_equal(5, result[0]) + assert_equal(2, result[1]) + assert_kind_of(Array,result[2]) + assert_kind_of(Array,result[3]) + assert_kind_of(Array,result[4]) + assert_kind_of(Array,result[2][1]) + assert_kind_of(MiniTest::Assertion,result[2][0][2]) + assert_kind_of(MiniTest::Skip,result[2][1][2]) + assert_kind_of(MiniTest::Skip,result[2][2][2]) + assert_kind_of(Exception, result[2][3][2]) + assert_equal(result[5], "TestE") + end + end + + def test_quit + timeout(10) do + @worker_in.puts "quit" + assert_match(/^bye$/m,@worker_out.read) + end + end + end + + class TestParallel < Test::Unit::TestCase + def spawn_runner(*opt_args) + @test_out, o = IO.pipe + @test_pid = spawn(*@options[:ruby], TESTS+"/runner.rb", + "--ruby", @options[:ruby].join(" "), + "-j","t1",*opt_args, out: o, err: o) + o.close + end + + def teardown + begin + if @test_pid + timeout(2) do + Process.waitpid(@test_pid) + end + end + rescue Timeout::Error + Process.kill(:KILL, @test_pid) if @test_pid + ensure + @test_out.close if @test_out + end + end + + def test_ignore_jzero + @test_out, o = IO.pipe + @test_pid = spawn(*@options[:ruby], TESTS+"/runner.rb", + "--ruby", @options[:ruby].join(" "), + "-j","0", out: File::NULL, err: o) + o.close + timeout(10) { + assert_match(/Error: parameter of -j option should be greater than 0/,@test_out.read) + } + end + + def test_should_run_all_without_any_leaks + spawn_runner + buf = timeout(10){@test_out.read} + assert_match(/^[SFE\.]{9}$/,buf) + end + + def test_should_retry_failed_on_workers + spawn_runner + buf = timeout(10){@test_out.read} + assert_match(/^Retrying\.+$/,buf) + end + + def test_no_retry_option + spawn_runner "--no-retry" + buf = timeout(10){@test_out.read} + refute_match(/^Retrying\.+$/,buf) + assert_match(/^ +\d+\) Failure:\nTestD#test_fail_at_worker/,buf) + end + + def test_jobs_status + spawn_runner "--jobs-status" + buf = timeout(10){@test_out.read} + assert_match(/\d+=ptest_(first|second|third|forth) */,buf) + end + + def test_separate + # this test depends to --jobs-status + spawn_runner "--jobs-status", "--separate" + buf = timeout(10){@test_out.read} + assert(buf.scan(/(\d+?)[:=]/).flatten.uniq.size > 1) + end + end +end diff --git a/jni/ruby/test/testunit/test_rake_integration.rb b/jni/ruby/test/testunit/test_rake_integration.rb new file mode 100644 index 0000000..0d0f8ef --- /dev/null +++ b/jni/ruby/test/testunit/test_rake_integration.rb @@ -0,0 +1,35 @@ +require 'minitest/autorun' +require 'tmpdir' + +class RakeIntegration < MiniTest::Unit::TestCase + include Test::Unit::Assertions + RAKE_LOADER = File.expand_path( + File.join( + File.dirname(__FILE__), + '..', + '..', + 'lib', + 'rake', + 'rake_test_loader.rb')) + + def test_with_rake_runner + Dir.mktmpdir do |dir| + filename = File.join dir, 'testing.rb' + File.open(filename, 'wb') do |f| + f.write <<-eotest +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" +require 'test/unit' +raise 'loaded twice' if defined?(FooTest) +class FooTest; end + eotest + end + + args = %w{ -w } + [RAKE_LOADER, filename] + bug3972 = "[ruby-core:32864]" + status = assert_in_out_err(args, "", + /0 tests, 0 assertions, 0 failures, 0 errors, 0 skips/, + [], bug3972) + assert_equal(true, status.success?, bug3972) + end + end +end diff --git a/jni/ruby/test/testunit/test_redefinition.rb b/jni/ruby/test/testunit/test_redefinition.rb new file mode 100644 index 0000000..ed11621 --- /dev/null +++ b/jni/ruby/test/testunit/test_redefinition.rb @@ -0,0 +1,15 @@ +require 'test/unit' + +class TestRedefinition < Test::Unit::TestCase + def test_redefinition + assert_match(/^test\/unit warning: method TestForTestRedefinition#test_redefinition is redefined$/, + redefinition) + end + + def redefinition(*args) + IO.popen([*@options[:ruby], "#{File.dirname(__FILE__)}/test4test_redefinition.rb", *args], + err: [:child, :out]) {|f| + f.read + } + end +end diff --git a/jni/ruby/test/testunit/test_sorting.rb b/jni/ruby/test/testunit/test_sorting.rb new file mode 100644 index 0000000..e13ca1f --- /dev/null +++ b/jni/ruby/test/testunit/test_sorting.rb @@ -0,0 +1,17 @@ +require 'test/unit' + +class TestTestUnitSorting < Test::Unit::TestCase + def test_sorting + result = sorting("--show-skip") + assert_match(/^ 1\) Skipped:/, result) + assert_match(/^ 2\) Failure:/, result) + assert_match(/^ 3\) Error:/, result) + end + + def sorting(*args) + IO.popen([*@options[:ruby], "#{File.dirname(__FILE__)}/test4test_sorting.rb", + "--verbose", *args], err: [:child, :out]) {|f| + f.read + } + end +end diff --git a/jni/ruby/test/testunit/tests_for_parallel/ptest_first.rb b/jni/ruby/test/testunit/tests_for_parallel/ptest_first.rb new file mode 100644 index 0000000..66c7704 --- /dev/null +++ b/jni/ruby/test/testunit/tests_for_parallel/ptest_first.rb @@ -0,0 +1,7 @@ +require 'test/unit' + +class TestA < Test::Unit::TestCase + def test_nothing_test + end +end + diff --git a/jni/ruby/test/testunit/tests_for_parallel/ptest_forth.rb b/jni/ruby/test/testunit/tests_for_parallel/ptest_forth.rb new file mode 100644 index 0000000..46c88da --- /dev/null +++ b/jni/ruby/test/testunit/tests_for_parallel/ptest_forth.rb @@ -0,0 +1,29 @@ +require 'test/unit' + +class TestE < Test::Unit::TestCase + class UnknownError < RuntimeError; end + + def test_not_fail + assert_equal(1,1) + end + + def test_always_skip + skip "always" + end + + def test_always_fail + assert_equal(0,1) + end + + def test_skip_after_unknown_error + begin + raise UnknownError, "unknown error" + rescue + skip "after raise" + end + end + + def test_unknown_error + raise UnknownError, "unknown error" + end +end diff --git a/jni/ruby/test/testunit/tests_for_parallel/ptest_second.rb b/jni/ruby/test/testunit/tests_for_parallel/ptest_second.rb new file mode 100644 index 0000000..7004d68 --- /dev/null +++ b/jni/ruby/test/testunit/tests_for_parallel/ptest_second.rb @@ -0,0 +1,11 @@ +require 'test/unit' + +class TestB < Test::Unit::TestCase + def test_nothing + end +end + +class TestC < Test::Unit::TestCase + def test_nothing + end +end diff --git a/jni/ruby/test/testunit/tests_for_parallel/ptest_third.rb b/jni/ruby/test/testunit/tests_for_parallel/ptest_third.rb new file mode 100644 index 0000000..338fc32 --- /dev/null +++ b/jni/ruby/test/testunit/tests_for_parallel/ptest_third.rb @@ -0,0 +1,10 @@ +require 'test/unit' + +class TestD < Test::Unit::TestCase + def test_fail_at_worker + #if /test\/unit\/parallel\.rb/ =~ $0 + if on_parallel_worker? + assert_equal(0,1) + end + end +end diff --git a/jni/ruby/test/testunit/tests_for_parallel/runner.rb b/jni/ruby/test/testunit/tests_for_parallel/runner.rb new file mode 100644 index 0000000..e262e1e --- /dev/null +++ b/jni/ruby/test/testunit/tests_for_parallel/runner.rb @@ -0,0 +1,13 @@ +require 'rbconfig' + +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib" + +require 'test/unit' + +src_testdir = File.dirname(File.expand_path(__FILE__)) + +class Test::Unit::Runner + @@testfile_prefix = "ptest" +end + +exit Test::Unit::AutoRunner.run(true, src_testdir) -- cgit v1.2.3-70-g09d2