diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-09-10 20:56:07 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-09-11 08:48:03 +0900 |
commit | d05383812adf86e6c6a536246c03a2d401f10058 (patch) | |
tree | e45fbc574fb2b93b1426a5f258005e98f4f1ac72 /tool/lib | |
parent | 7cec81e073ed1d29910b3e1dc4dd5d7e9d2b490f (diff) | |
download | ruby-d05383812adf86e6c6a536246c03a2d401f10058.tar.gz |
Replace Test::Assertion and Test::Skip to Test::Unit::AssertionFailedError and Test::Unit::PendedError
Diffstat (limited to 'tool/lib')
-rw-r--r-- | tool/lib/core_assertions.rb | 14 | ||||
-rw-r--r-- | tool/lib/test/unit.rb | 30 | ||||
-rw-r--r-- | tool/lib/test/unit/assertions.rb | 4 | ||||
-rw-r--r-- | tool/lib/test/unit/parallel.rb | 10 | ||||
-rw-r--r-- | tool/lib/test/unit/testcase.rb | 4 |
5 files changed, 29 insertions, 33 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 |