[前][次][番号順一覧][スレッド一覧]

ruby-changes:67913

From: Hiroshi <ko1@a...>
Date: Sat, 11 Sep 2021 08:48:56 +0900 (JST)
Subject: [ruby-changes:67913] d05383812a (master): Replace Test::Assertion and Test::Skip to Test::Unit::AssertionFailedError and Test::Unit::PendedError

https://git.ruby-lang.org/ruby.git/commit/?id=d05383812a

From d05383812adf86e6c6a536246c03a2d401f10058 Mon Sep 17 00:00:00 2001
From: Hiroshi SHIBATA <hsbt@r...>
Date: Fri, 10 Sep 2021 20:56:07 +0900
Subject: 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 f94a5df..8800487 100644
--- a/tool/lib/core_assertions.rb
+++ b/tool/lib/core_assertions.rb
@@ -103,7 +103,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/tool/lib/core_assertions.rb#L103
         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 https://github.com/ruby/ruby/blob/trunk/tool/lib/core_assertions.rb#L168
         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 https://github.com/ruby/ruby/blob/trunk/tool/lib/core_assertions.rb#L184
               "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 https://github.com/ruby/ruby/blob/trunk/tool/lib/core_assertions.rb#L387
 
         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 https://github.com/ruby/ruby/blob/trunk/tool/lib/core_assertions.rb#L699
           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 36cfc34..35aeed6 100644
--- a/tool/lib/test/unit.rb
+++ b/tool/lib/test/unit.rb
@@ -9,16 +9,6 @@ require "leakchecker" https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit.rb#L9
 # 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 https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit.rb#L52
   # 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 https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit.rb#L626
           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 https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit.rb#L1531
         #   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 https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit.rb#L1545
             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 bdb25d0..3352474 100644
--- a/tool/lib/test/unit/assertions.rb
+++ b/tool/lib/test/unit/assertions.rb
@@ -117,7 +117,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit/assertions.rb#L117
         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 https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit/assertions.rb#L578
       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 84bf0c3..5163220 100644
--- a/tool/lib/test/unit/parallel.rb
+++ b/tool/lib/test/unit/parallel.rb
@@ -160,21 +160,21 @@ module Test https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit/parallel.rb#L160
       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 ea3092a..19d90c5 100644
--- a/tool/lib/test/unit/testcase.rb
+++ b/tool/lib/test/unit/testcase.rb
@@ -141,7 +141,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit/testcase.rb#L141
     # 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 https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit/testcase.rb#L195
         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 91c2fc1..8c83b44 100644
--- a/tool/test/testunit/test_assertion.rb
+++ b/tool/test/testunit/test_assertion.rb
@@ -22,7 +22,7 @@ class TestAssertion < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/tool/test/testunit/test_assertion.rb#L22
   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 ae55b04..6cb63e6 100644
--- a/tool/test/testunit/test_minitest_unit.rb
+++ b/tool/test/testunit/test_minitest_unit.rb
@@ -19,7 +19,7 @@ class TestMiniTestUnit < MetaMetaMetaTestCase https://github.com/ruby/ruby/ (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]