summaryrefslogtreecommitdiff
path: root/test/testunit
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2019-07-01 21:05:55 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2019-07-02 07:59:54 +0900
commitc68781e9181cb43af1bac29b3c974887205c3bf3 (patch)
tree34019fe4147362f117fdc0b23d2b3533a956ccb5 /test/testunit
parentc3c0e3f5c9444c197779cb242de46dfffda79dec (diff)
Split test files for test-framework that are test-unit and minitest to tool direcotry.
Diffstat (limited to 'test/testunit')
-rw-r--r--test/testunit/test4test_hideskip.rb10
-rw-r--r--test/testunit/test4test_redefinition.rb14
-rw-r--r--test/testunit/test4test_sorting.rb18
-rw-r--r--test/testunit/test_assertion.rb29
-rw-r--r--test/testunit/test_hideskip.rb21
-rw-r--r--test/testunit/test_parallel.rb203
-rw-r--r--test/testunit/test_redefinition.rb16
-rw-r--r--test/testunit/test_sorting.rb18
-rw-r--r--test/testunit/tests_for_parallel/ptest_first.rb8
-rw-r--r--test/testunit/tests_for_parallel/ptest_forth.rb30
-rw-r--r--test/testunit/tests_for_parallel/ptest_second.rb12
-rw-r--r--test/testunit/tests_for_parallel/ptest_third.rb11
-rw-r--r--test/testunit/tests_for_parallel/runner.rb14
13 files changed, 0 insertions, 404 deletions
diff --git a/test/testunit/test4test_hideskip.rb b/test/testunit/test4test_hideskip.rb
deleted file mode 100644
index b870c76..0000000
--- a/test/testunit/test4test_hideskip.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-# frozen_string_literal: false
-$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/test/testunit/test4test_redefinition.rb b/test/testunit/test4test_redefinition.rb
deleted file mode 100644
index 894bc3d..0000000
--- a/test/testunit/test4test_redefinition.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: false
-$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/test/testunit/test4test_sorting.rb b/test/testunit/test4test_sorting.rb
deleted file mode 100644
index 4848a78..0000000
--- a/test/testunit/test4test_sorting.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: false
-$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/test/testunit/test_assertion.rb b/test/testunit/test_assertion.rb
deleted file mode 100644
index 0c7c488..0000000
--- a/test/testunit/test_assertion.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: false
-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
-
- def test_timeout_separately
- assert_raise(Timeout::Error) do
- assert_separately([], <<~"end;", timeout: 0.1)
- sleep
- end;
- end
- end
-
- def return_in_assert_raise
- assert_raise(RuntimeError) do
- return
- end
- end
-
- def test_assert_raise
- assert_raise(MiniTest::Assertion) do
- return_in_assert_raise
- end
- end
-end
diff --git a/test/testunit/test_hideskip.rb b/test/testunit/test_hideskip.rb
deleted file mode 100644
index 0188316..0000000
--- a/test/testunit/test_hideskip.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# frozen_string_literal: false
-require 'test/unit'
-
-class TestHideSkip < Test::Unit::TestCase
- def test_hideskip
- assert_not_match(/^ *1\) Skipped/, hideskip)
- assert_match(/^ *1\) Skipped/, hideskip("--show-skip"))
- output = hideskip("--hide-skip")
- output.gsub!(/Successful MJIT finish\n/, '') if RubyVM::MJIT.enabled?
- assert_match(/assertions\/s.\n+1 tests, 0 assertions, 0 failures, 0 errors, 1 skips/, output)
- end
-
- private
-
- 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/test/testunit/test_parallel.rb b/test/testunit/test_parallel.rb
deleted file mode 100644
index 6bbe71a..0000000
--- a/test/testunit/test_parallel.rb
+++ /dev/null
@@ -1,203 +0,0 @@
-# frozen_string_literal: false
-require 'test/unit'
-require 'timeout'
-
-module TestParallel
- PARALLEL_RB = "#{File.dirname(__FILE__)}/../lib/test/unit/parallel.rb"
- TESTS = "#{File.dirname(__FILE__)}/tests_for_parallel"
- # use large timeout for --jit-wait
- TIMEOUT = EnvUtil.apply_timeout_scale(RubyVM::MJIT.enabled? ? 100 : 30)
-
- 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.timeout(2) do
- Process.waitpid(@worker_pid)
- end
- rescue Timeout::Error
- begin
- Process.kill(:KILL, @worker_pid)
- rescue Errno::ESRCH
- end
- end
- end
- ensure
- begin
- @worker_in.close
- @worker_out.close
- rescue Errno::EPIPE
- # may already broken and rescue'ed in above code
- end
- end
-
- def test_run
- Timeout.timeout(TIMEOUT) do
- assert_match(/^ready/,@worker_out.gets)
- @worker_in.puts "run #{TESTS}/ptest_first.rb test"
- assert_match(/^okay/,@worker_out.gets)
- assert_match(/^record/,@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.timeout(TIMEOUT) do
- assert_match(/^ready/,@worker_out.gets)
- @worker_in.puts "run #{TESTS}/ptest_second.rb test"
- assert_match(/^okay/,@worker_out.gets)
- assert_match(/^record/,@worker_out.gets)
- assert_match(/^p/,@worker_out.gets)
- assert_match(/^done/,@worker_out.gets)
- assert_match(/^record/,@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.timeout(TIMEOUT) do
- assert_match(/^ready/,@worker_out.gets)
- @worker_in.puts "run #{TESTS}/ptest_first.rb test"
- assert_match(/^okay/,@worker_out.gets)
- assert_match(/^record/,@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(/^record/,@worker_out.gets)
- assert_match(/^p/,@worker_out.gets)
- assert_match(/^done/,@worker_out.gets)
- assert_match(/^record/,@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.timeout(TIMEOUT) 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.timeout(TIMEOUT) do
- @worker_in.puts "run #{TESTS}/ptest_forth.rb test"
- while buf = @worker_out.gets
- break if /^done (.+?)$/ =~ buf
- end
-
- 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.timeout(TIMEOUT) 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.timeout(2) do
- Process.waitpid(@test_pid)
- end
- end
- rescue Timeout::Error
- Process.kill(:KILL, @test_pid) if @test_pid
- ensure
- @test_out&.close
- 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.timeout(TIMEOUT) {
- 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.timeout(TIMEOUT) {@test_out.read}
- assert_match(/^9 tests/,buf)
- end
-
- def test_should_retry_failed_on_workers
- spawn_runner
- buf = Timeout.timeout(TIMEOUT) {@test_out.read}
- assert_match(/^Retrying\.+$/,buf)
- end
-
- def test_no_retry_option
- spawn_runner "--no-retry"
- buf = Timeout.timeout(TIMEOUT) {@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.timeout(TIMEOUT) {@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.timeout(TIMEOUT) {@test_out.read}
- assert(buf.scan(/^\[\s*\d+\/\d+\]\s*(\d+?)=/).flatten.uniq.size > 1,
- message("retried tests should run in different processes") {buf})
- end
- end
-end
diff --git a/test/testunit/test_redefinition.rb b/test/testunit/test_redefinition.rb
deleted file mode 100644
index 9129e55..0000000
--- a/test/testunit/test_redefinition.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: false
-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/test/testunit/test_sorting.rb b/test/testunit/test_sorting.rb
deleted file mode 100644
index f9de3ec..0000000
--- a/test/testunit/test_sorting.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: false
-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/test/testunit/tests_for_parallel/ptest_first.rb b/test/testunit/tests_for_parallel/ptest_first.rb
deleted file mode 100644
index f868733..0000000
--- a/test/testunit/tests_for_parallel/ptest_first.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-# frozen_string_literal: false
-require 'test/unit'
-
-class TestA < Test::Unit::TestCase
- def test_nothing_test
- end
-end
-
diff --git a/test/testunit/tests_for_parallel/ptest_forth.rb b/test/testunit/tests_for_parallel/ptest_forth.rb
deleted file mode 100644
index 8831676..0000000
--- a/test/testunit/tests_for_parallel/ptest_forth.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# frozen_string_literal: false
-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/test/testunit/tests_for_parallel/ptest_second.rb b/test/testunit/tests_for_parallel/ptest_second.rb
deleted file mode 100644
index a793c17..0000000
--- a/test/testunit/tests_for_parallel/ptest_second.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-# frozen_string_literal: false
-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/test/testunit/tests_for_parallel/ptest_third.rb b/test/testunit/tests_for_parallel/ptest_third.rb
deleted file mode 100644
index 3f448ec..0000000
--- a/test/testunit/tests_for_parallel/ptest_third.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# frozen_string_literal: false
-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/test/testunit/tests_for_parallel/runner.rb b/test/testunit/tests_for_parallel/runner.rb
deleted file mode 100644
index bece739..0000000
--- a/test/testunit/tests_for_parallel/runner.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: false
-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)