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

ruby-changes:67887

From: Hiroshi <ko1@a...>
Date: Sat, 11 Sep 2021 08:48:28 +0900 (JST)
Subject: [ruby-changes:67887] 9b026ca39b (master): Integrate Minitest to Test

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

From 9b026ca39b27b1213758699555eb8e6d4874984c Mon Sep 17 00:00:00 2001
From: Hiroshi SHIBATA <hsbt@r...>
Date: Wed, 8 Sep 2021 21:02:08 +0900
Subject: Integrate Minitest to Test

---
 tool/lib/core_assertions.rb      | 14 ++++----
 tool/lib/minitest/unit.rb        | 72 ----------------------------------------
 tool/lib/test/unit.rb            | 64 +++++++++++++++++++++++++++++++----
 tool/lib/test/unit/assertions.rb | 12 ++-----
 tool/lib/test/unit/parallel.rb   | 10 +++---
 tool/lib/test/unit/testcase.rb   |  2 +-
 6 files changed, 73 insertions(+), 101 deletions(-)
 delete mode 100644 tool/lib/minitest/unit.rb

diff --git a/tool/lib/core_assertions.rb b/tool/lib/core_assertions.rb
index 36ff2a0..51aeebb 100644
--- a/tool/lib/core_assertions.rb
+++ b/tool/lib/core_assertions.rb
@@ -112,7 +112,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/tool/lib/core_assertions.rb#L112
         pend 'assert_no_memory_leak may consider MJIT memory usage as leak' if defined?(RubyVM::JIT) && RubyVM::JIT.enabled?
 
         require_relative 'memory_status'
-        raise MiniTest::Skip, "unsupported platform" unless defined?(Memory::Status)
+        raise Test::Skip, "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
@@ -177,11 +177,11 @@ module Test https://github.com/ruby/ruby/blob/trunk/tool/lib/core_assertions.rb#L177
         end
         begin
           line = __LINE__; yield
-        rescue MiniTest::Skip
+        rescue Test::Skip
           raise
         rescue Exception => e
           bt = e.backtrace
-          as = e.instance_of?(MiniTest::Assertion)
+          as = e.instance_of?(Test::Assertion)
           if as
             ans = /\A#{Regexp.quote(__FILE__)}:#{line}:in /o
             bt.reject! {|ln| ans =~ ln}
@@ -193,7 +193,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/tool/lib/core_assertions.rb#L193
               "Backtrace:\n" +
               e.backtrace.map{|frame| "  #{frame}"}.join("\n")
             }
-            raise MiniTest::Assertion, msg.call, bt
+            raise Test::Assertion, msg.call, bt
           else
             raise
           end
@@ -396,8 +396,8 @@ eom https://github.com/ruby/ruby/blob/trunk/tool/lib/core_assertions.rb#L396
 
         begin
           yield
-        rescue MiniTest::Skip => e
-          return e if exp.include? MiniTest::Skip
+        rescue Test::Skip => e
+          return e if exp.include? Test::Skip
           raise e
         rescue Exception => e
           expected = exp.any? { |ex|
@@ -708,7 +708,7 @@ eom https://github.com/ruby/ruby/blob/trunk/tool/lib/core_assertions.rb#L708
           if message
             msg = "#{message}\n#{msg}"
           end
-          raise MiniTest::Assertion, msg
+          raise Test::Assertion, msg
         end
       end
 
diff --git a/tool/lib/minitest/unit.rb b/tool/lib/minitest/unit.rb
deleted file mode 100644
index 6c72362..0000000
--- a/tool/lib/minitest/unit.rb
+++ /dev/null
@@ -1,72 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/tool/lib/core_assertions.rb#L0
-# encoding: utf-8
-# frozen_string_literal: true
-
-require "optparse"
-require "rbconfig"
-require "leakchecker"
-
-##
-# Minimal (mostly drop-in) replacement for test-unit.
-#
-# :include: README.txt
-
-module MiniTest
-
-  def self.const_missing name # :nodoc:
-    case name
-    when :MINI_DIR then
-      msg = "MiniTest::MINI_DIR was removed. Don't violate other's internals."
-      warn "WAR\NING: #{msg}"
-      warn "WAR\NING: Used by #{caller.first}."
-      const_set :MINI_DIR, "bad value"
-    else
-      super
-    end
-  end
-
-  ##
-  # Assertion base class
-
-  class Assertion < Exception; end
-
-  ##
-  # Assertion raised when skipping a test
-
-  class Skip < Assertion; end
-
-  class << self
-    ##
-    # Filter object for backtraces.
-
-    attr_accessor :backtrace_filter
-  end
-
-  class BacktraceFilter # :nodoc:
-    def filter bt
-      return ["No backtrace"] unless bt
-
-      new_bt = []
-
-      unless $DEBUG then
-        bt.each do |line|
-          break if line =~ /lib\/minitest/
-          new_bt << line
-        end
-
-        new_bt = bt.reject { |line| line =~ /lib\/minitest/ } if new_bt.empty?
-        new_bt = bt.dup if new_bt.empty?
-      else
-        new_bt = bt.dup
-      end
-
-      new_bt
-    end
-  end
-
-  self.backtrace_filter = BacktraceFilter.new
-
-  def self.filter_backtrace bt # :nodoc:
-    backtrace_filter.filter bt
-  end
-
-end # module MiniTest
diff --git a/tool/lib/test/unit.rb b/tool/lib/test/unit.rb
index ed4a376..78e7064 100644
--- a/tool/lib/test/unit.rb
+++ b/tool/lib/test/unit.rb
@@ -1,14 +1,60 @@ https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit.rb#L1
 # frozen_string_literal: true
 
-require_relative '../minitest/unit'
-require 'test/unit/assertions'
 require_relative '../envutil'
 require_relative '../colorize'
+require 'test/unit/assertions'
 require 'test/unit/testcase'
 require 'optparse'
+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.
+
+    attr_accessor :backtrace_filter
+  end
+
+  class BacktraceFilter # :nodoc:
+    def filter bt
+      return ["No backtrace"] unless bt
+
+      new_bt = []
+
+      unless $DEBUG then
+        bt.each do |line|
+          break if line =~ /lib\/minitest/
+          new_bt << line
+        end
+
+        new_bt = bt.reject { |line| line =~ /lib\/minitest/ } if new_bt.empty?
+        new_bt = bt.dup if new_bt.empty?
+      else
+        new_bt = bt.dup
+      end
+
+      new_bt
+    end
+  end
+
+  self.backtrace_filter = BacktraceFilter.new
+
+  def self.filter_backtrace bt # :nodoc:
+    backtrace_filter.filter bt
+  end
+
   ##
   # Test::Unit is an implementation of the xUnit testing framework for Ruby.
   #
@@ -17,6 +63,10 @@ module Test https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit.rb#L63
   # 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
+
     TEST_UNIT_IMPLEMENTATION = 'test/unit compatibility layer using minitest' # :nodoc:
 
     module RunCount # :nodoc: all
@@ -583,7 +633,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit.rb#L633
           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?(MiniTest::Skip)}}
+            suites, rep = rep.partition {|r| r[:testcase] && r[:file] && r[:report].any? {|e| !e[2].is_a?(Test::Skip)}}
             suites.map {|r| File.realpath(r[:file])}.uniq.each {|file| require file}
             suites.map! {|r| eval("::"+r[:testcase])}
             del_status_line or puts
@@ -1488,21 +1538,21 @@ module Test https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit.rb#L1538
         #   hidden when not verbose (-v), note this is temporally.
         n = report.size
         e = case e
-            when MiniTest::Skip then
+            when Test::Skip then
               @skips += 1
               return "S" unless @verbose
               "Skipped:\n#{klass}##{meth} [#{location e}]:\n#{e.message}\n"
-            when MiniTest::Assertion then
+            when Test::Assertion then
               @failures += 1
               "Failure:\n#{klass}##{meth} [#{location e}]:\n#{e.message}\n"
             else
               @errors += 1
-              bt = MiniTest::filter_backtrace(e.backtrace).join "\n    "
+              bt = Test::filter_backtrace(e.backtrace).join "\n    "
               "Error:\n#{klass}##{meth}:\n#{e.class}: #{e.message.b}\n    #{bt}\n"
             end
         @report << e
         rep = e[0, 1]
-        if MiniTest::Skip === e and /no message given\z/ =~ e.message
+        if Test::Skip === 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 711d8a6..db81285 100644
--- a/tool/lib/test/unit/assertions.rb
+++ b/tool/lib/test/unit/assertions.rb
@@ -1,5 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit/assertions.rb#L1
 # frozen_string_literal: true
-require 'minitest/unit'
 require_relative '../../core_assertions'
 require 'pp'
 
@@ -119,7 +118,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit/assertions.rb#L118
         self._assertions += 1
         unless test then
           msg = msg.call if Proc === msg
-          raise MiniTest::Assertion, msg
+          raise Test::Assertion, msg
         end
         true
       end
@@ -410,7 +409,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit/assertions.rb#L409
         "Class: <#{e.class}>",
         "Message: <#{e.message.inspect}>",
         "---Backtrace---",
-        "#{MiniTest::filter_backtrace(e.backtrace).join("\n")}",
+        "#{Test::filter_backtrace(e.backtrace).join("\n")}",
         "---------------",
         ].join "\n"
       end
@@ -580,7 +579,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit/assertions.rb#L579
       def skip msg = nil, bt = caller
         msg ||= "Skipped, no message given"
         @skip = true
-        raise MiniTest::Skip, msg, bt
+        raise Test::Skip, msg, bt
       end
 
       alias omit skip
@@ -883,10 +882,5 @@ EOT https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit/assertions.rb#L882
         template.gsub(/\G((?:[^\\]|\\.)*?)(\\)?\?/) { $1 + ($2 ? "?" : mu_pp (... truncated)

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

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