From d05383812adf86e6c6a536246c03a2d401f10058 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 10 Sep 2021 20:56:07 +0900 Subject: [PATCH] Replace Test::Assertion and Test::Skip to Test::Unit::AssertionFailedError and Test::Unit::PendedError --- tool/lib/core_assertions.rb | 14 ++++---- tool/lib/test/unit.rb | 30 ++++++++--------- tool/lib/test/unit/assertions.rb | 4 +-- tool/lib/test/unit/parallel.rb | 10 +++--- tool/lib/test/unit/testcase.rb | 4 +-- tool/test/testunit/test_assertion.rb | 2 +- tool/test/testunit/test_minitest_unit.rb | 42 ++++++++++++------------ tool/test/testunit/test_parallel.rb | 6 ++-- 8 files changed, 54 insertions(+), 58 deletions(-) diff --git a/tool/lib/core_assertions.rb b/tool/lib/core_assertions.rb index f94a5dff66..8800487971 100644 --- a/tool/lib/core_assertions.rb +++ b/tool/lib/core_assertions.rb @@ -103,7 +103,7 @@ module Test pend 'assert_no_memory_leak may consider MJIT memory usage as leak' if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? require_relative 'memory_status' - raise Test::Skip, "unsupported platform" unless defined?(Memory::Status) + raise Test::Unit::PendedError, "unsupported platform" unless defined?(Memory::Status) token = "\e[7;1m#{$$.to_s}:#{Time.now.strftime('%s.%L')}:#{rand(0x10000).to_s(16)}:\e[m" token_dump = token.dump @@ -168,11 +168,11 @@ module Test end begin line = __LINE__; yield - rescue Test::Skip + rescue Test::Unit::PendedError raise rescue Exception => e bt = e.backtrace - as = e.instance_of?(Test::Assertion) + as = e.instance_of?(Test::Unit::AssertionFailedError) if as ans = /\A#{Regexp.quote(__FILE__)}:#{line}:in /o bt.reject! {|ln| ans =~ ln} @@ -184,7 +184,7 @@ module Test "Backtrace:\n" + e.backtrace.map{|frame| " #{frame}"}.join("\n") } - raise Test::Assertion, msg.call, bt + raise Test::Unit::AssertionFailedError, msg.call, bt else raise end @@ -387,8 +387,8 @@ eom begin yield - rescue Test::Skip => e - return e if exp.include? Test::Skip + rescue Test::Unit::PendedError => e + return e if exp.include? Test::Unit::PendedError raise e rescue Exception => e expected = exp.any? { |ex| @@ -699,7 +699,7 @@ eom if message msg = "#{message}\n#{msg}" end - raise Test::Assertion, msg + raise Test::Unit::AssertionFailedError, msg end end diff --git a/tool/lib/test/unit.rb b/tool/lib/test/unit.rb index 36cfc349f4..35aeed6c21 100644 --- a/tool/lib/test/unit.rb +++ b/tool/lib/test/unit.rb @@ -9,16 +9,6 @@ require "leakchecker" # See Test::Unit module Test - ## - # Assertion base class - - class Assertion < Exception; end - - ## - # Assertion raised when skipping a test - - class Skip < Assertion; end - class << self ## # Filter object for backtraces. @@ -62,9 +52,15 @@ module Test # Test::Unit has been left in the standard library to support legacy test # suites. module Unit - # Compatibility hack for assert_raise - AssertionFailedError = Test::Assertion - PendedError = Test::Skip + ## + # Assertion base class + + class AssertionFailedError < Exception; end + + ## + # Assertion raised when skipping a test + + class PendedError < AssertionFailedError; end module RunCount # :nodoc: all @@run_count = 0 @@ -630,7 +626,7 @@ module Test unless @interrupt || !@options[:retry] || @need_quit parallel = @options[:parallel] @options[:parallel] = false - suites, rep = rep.partition {|r| r[:testcase] && r[:file] && r[:report].any? {|e| !e[2].is_a?(Test::Skip)}} + suites, rep = rep.partition {|r| r[:testcase] && r[:file] && r[:report].any? {|e| !e[2].is_a?(Test::Unit::PendedError)}} suites.map {|r| File.realpath(r[:file])}.uniq.each {|file| require file} suites.map! {|r| eval("::"+r[:testcase])} del_status_line or puts @@ -1535,11 +1531,11 @@ module Test # hidden when not verbose (-v), note this is temporally. n = report.size e = case e - when Test::Skip then + when Test::Unit::PendedError then @skips += 1 return "S" unless @verbose "Skipped:\n#{klass}##{meth} [#{location e}]:\n#{e.message}\n" - when Test::Assertion then + when Test::Unit::AssertionFailedError then @failures += 1 "Failure:\n#{klass}##{meth} [#{location e}]:\n#{e.message}\n" else @@ -1549,7 +1545,7 @@ module Test end @report << e rep = e[0, 1] - if Test::Skip === e and /no message given\z/ =~ e.message + if Test::Unit::PendedError === e and /no message given\z/ =~ e.message report.slice!(n..-1) rep = "." end diff --git a/tool/lib/test/unit/assertions.rb b/tool/lib/test/unit/assertions.rb index bdb25d0d85..335247458a 100644 --- a/tool/lib/test/unit/assertions.rb +++ b/tool/lib/test/unit/assertions.rb @@ -117,7 +117,7 @@ module Test self._assertions += 1 unless test then msg = msg.call if Proc === msg - raise Test::Assertion, msg + raise Test::Unit::AssertionFailedError, msg end true end @@ -578,7 +578,7 @@ module Test def skip msg = nil, bt = caller msg ||= "Skipped, no message given" @skip = true - raise Test::Skip, msg, bt + raise Test::Unit::PendedError, msg, bt end alias omit skip diff --git a/tool/lib/test/unit/parallel.rb b/tool/lib/test/unit/parallel.rb index 84bf0c3e25..5163220a2f 100644 --- a/tool/lib/test/unit/parallel.rb +++ b/tool/lib/test/unit/parallel.rb @@ -160,21 +160,21 @@ module Test end def puke(klass, meth, e) # :nodoc: - if e.is_a?(Test::Skip) - new_e = Test::Skip.new(e.message) + if e.is_a?(Test::Unit::PendedError) + new_e = Test::Unit::PendedError.new(e.message) new_e.set_backtrace(e.backtrace) e = new_e end - @partial_report << [klass.name, meth, e.is_a?(Test::Assertion) ? e : ProxyError.new(e)] + @partial_report << [klass.name, meth, e.is_a?(Test::Unit::AssertionFailedError) ? e : ProxyError.new(e)] super end def record(suite, method, assertions, time, error) # :nodoc: case error when nil - when Test::Assertion, Test::Skip + when Test::Unit::AssertionFailedError, Test::Unit::PendedError case error.cause - when nil, Test::Assertion, Test::Skip + when nil, Test::Unit::AssertionFailedError, Test::Unit::PendedError else bt = error.backtrace error = error.class.new(error.message) diff --git a/tool/lib/test/unit/testcase.rb b/tool/lib/test/unit/testcase.rb index ea3092a4b3..19d90c58eb 100644 --- a/tool/lib/test/unit/testcase.rb +++ b/tool/lib/test/unit/testcase.rb @@ -141,7 +141,7 @@ module Test # Subclass TestCase to create your own tests. Typically you'll want a # TestCase subclass per implementation class. # - # See MiniTest::Assertions + # See MiniTest::Unit::AssertionFailedErrors class TestCase include Assertions @@ -195,7 +195,7 @@ module Test rescue *PASSTHROUGH_EXCEPTIONS raise rescue Exception => e - @passed = Test::Skip === e + @passed = Test::Unit::PendedError === e time = Time.now - start_time runner.record self.class, self.__name__, self._assertions, time, e result = runner.puke self.class, self.__name__, e diff --git a/tool/test/testunit/test_assertion.rb b/tool/test/testunit/test_assertion.rb index 91c2fc1e21..8c83b447a7 100644 --- a/tool/test/testunit/test_assertion.rb +++ b/tool/test/testunit/test_assertion.rb @@ -22,7 +22,7 @@ class TestAssertion < Test::Unit::TestCase end def test_assert_raise - assert_raise(Test::Assertion) do + assert_raise(Test::Unit::AssertionFailedError) do return_in_assert_raise end end diff --git a/tool/test/testunit/test_minitest_unit.rb b/tool/test/testunit/test_minitest_unit.rb index ae55b04a0c..6cb63e6aad 100644 --- a/tool/test/testunit/test_minitest_unit.rb +++ b/tool/test/testunit/test_minitest_unit.rb @@ -19,7 +19,7 @@ class TestMiniTestUnit < MetaMetaMetaTestCase "#{MINITEST_BASE_DIR}/test.rb:106:in `run'"] def test_class_puke_with_assertion_failed - exception = Test::Assertion.new "Oh no!" + exception = Test::Unit::AssertionFailedError.new "Oh no!" exception.set_backtrace ["unhappy"] assert_equal 'F', @tu.puke('SomeClass', 'method_name', exception) assert_equal 1, @tu.failures @@ -39,7 +39,7 @@ class TestMiniTestUnit < MetaMetaMetaTestCase ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first - exception = Test::Assertion.new "Oh no!" + exception = Test::Unit::AssertionFailedError.new "Oh no!" exception.set_backtrace bt assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception) assert_equal 1, @tu.failures @@ -62,7 +62,7 @@ class TestMiniTestUnit < MetaMetaMetaTestCase ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first - exception = Test::Assertion.new "Oh no!" + exception = Test::Unit::AssertionFailedError.new "Oh no!" exception.set_backtrace bt assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception) assert_equal 1, @tu.failures @@ -73,7 +73,7 @@ class TestMiniTestUnit < MetaMetaMetaTestCase def test_class_puke_with_failure_and_flunk_in_backtrace exception = begin Test::Unit::TestCase.new('fake tc').flunk - rescue Test::Assertion => failure + rescue Test::Unit::AssertionFailedError => failure failure end assert_equal 'F', @tu.puke('SomeClass', 'method_name', exception) @@ -95,7 +95,7 @@ class TestMiniTestUnit < MetaMetaMetaTestCase ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first - exception = Test::Assertion.new "Oh no!" + exception = Test::Unit::AssertionFailedError.new "Oh no!" exception.set_backtrace bt assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception) assert_equal 1, @tu.failures @@ -704,7 +704,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase def test_assert_includes_triggered @assertion_count = 3 - e = @tc.assert_raise Test::Assertion do + e = @tc.assert_raise Test::Unit::AssertionFailedError do @tc.assert_includes [true], false end @@ -895,7 +895,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase def test_assert_raise_skip @assertion_count = 0 - util_assert_triggered "skipped", Test::Skip do + util_assert_triggered "skipped", Test::Unit::PendedError do @tc.assert_raise ArgumentError do begin raise "blah" @@ -907,7 +907,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase end def test_assert_raise_triggered_different - e = assert_raise Test::Assertion do + e = assert_raise Test::Unit::AssertionFailedError do @tc.assert_raise RuntimeError do raise SyntaxError, "icky" end @@ -924,7 +924,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase end def test_assert_raise_triggered_different_msg - e = assert_raise Test::Assertion do + e = assert_raise Test::Unit::AssertionFailedError do @tc.assert_raise RuntimeError, "XXX" do raise SyntaxError, "icky" end @@ -942,31 +942,31 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase end def test_assert_raise_triggered_none - e = assert_raise Test::Assertion do - @tc.assert_raise Test::Assertion do + e = assert_raise Test::Unit::AssertionFailedError do + @tc.assert_raise Test::Unit::AssertionFailedError do # do nothing end end - expected = "Test::Assertion expected but nothing was raised." + expected = "Test::Unit::AssertionFailedError expected but nothing was raised." assert_equal expected, e.message end def test_assert_raise_triggered_none_msg - e = assert_raise Test::Assertion do - @tc.assert_raise Test::Assertion, "XXX" do + e = assert_raise Test::Unit::AssertionFailedError do + @tc.assert_raise Test::Unit::AssertionFailedError, "XXX" do # do nothing end end - expected = "XXX.\nTest::Assertion expected but nothing was raised." + expected = "XXX.\nTest::Unit::AssertionFailedError expected but nothing was raised." assert_equal expected, e.message end def test_assert_raise_triggered_subclass - e = assert_raise Test::Assertion do + e = assert_raise Test::Unit::AssertionFailedError do @tc.assert_raise StandardError do raise AnError end @@ -1223,7 +1223,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase def test_refute_includes_triggered @assertion_count = 3 - e = @tc.assert_raise Test::Assertion do + e = @tc.assert_raise Test::Unit::AssertionFailedError do @tc.refute_includes [true], true end @@ -1344,7 +1344,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase def test_skip @assertion_count = 0 - util_assert_triggered "haha!", Test::Skip do + util_assert_triggered "haha!", Test::Unit::PendedError do @tc.skip "haha!" end end @@ -1379,7 +1379,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase assert_equal expected, sample_test_case.test_methods end - def assert_triggered expected, klass = Test::Assertion + def assert_triggered expected, klass = Test::Unit::AssertionFailedError e = assert_raise klass do yield end @@ -1465,7 +1465,7 @@ class TestMiniTestUnitRecording < MetaMetaMetaTestCase end def test_record_failing - assert_run_record Test::Assertion do + assert_run_record Test::Unit::AssertionFailedError do def test_method assert false end @@ -1505,7 +1505,7 @@ class TestMiniTestUnitRecording < MetaMetaMetaTestCase end def test_record_skip - assert_run_record Test::Skip do + assert_run_record Test::Unit::PendedError do def test_method skip "not yet" end diff --git a/tool/test/testunit/test_parallel.rb b/tool/test/testunit/test_parallel.rb index 2bb7888d2b..2b76ee3f1d 100644 --- a/tool/test/testunit/test_parallel.rb +++ b/tool/test/testunit/test_parallel.rb @@ -120,9 +120,9 @@ module TestParallel assert_kind_of(Array,result[3]) assert_kind_of(Array,result[4]) assert_kind_of(Array,result[2][1]) - assert_kind_of(Test::Assertion,result[2][0][2]) - assert_kind_of(Test::Skip,result[2][1][2]) - assert_kind_of(Test::Skip,result[2][2][2]) + assert_kind_of(Test::Unit::AssertionFailedError,result[2][0][2]) + assert_kind_of(Test::Unit::PendedError,result[2][1][2]) + assert_kind_of(Test::Unit::PendedError,result[2][2][2]) assert_kind_of(Exception, result[2][3][2]) assert_equal(result[5], "TestE") end