This commit is contained in:
Hiroshi SHIBATA 2021-09-08 21:02:08 +09:00
Родитель 1e18f4e60f
Коммит 9b026ca39b
6 изменённых файлов: 73 добавлений и 101 удалений

Просмотреть файл

@ -112,7 +112,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 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
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
"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
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
if message
msg = "#{message}\n#{msg}"
end
raise MiniTest::Assertion, msg
raise Test::Assertion, msg
end
end

Просмотреть файл

@ -1,72 +0,0 @@
# 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

Просмотреть файл

@ -1,14 +1,60 @@
# 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
# 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
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
# 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

Просмотреть файл

@ -1,5 +1,4 @@
# frozen_string_literal: true
require 'minitest/unit'
require_relative '../../core_assertions'
require 'pp'
@ -119,7 +118,7 @@ module Test
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
"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
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
template.gsub(/\G((?:[^\\]|\\.)*?)(\\)?\?/) { $1 + ($2 ? "?" : mu_pp(arguments.shift)) }
end
end
# Compatibility hack for assert_raise
AssertionFailedError = MiniTest::Assertion
PendedError = MiniTest::Skip
end
end

Просмотреть файл

@ -160,21 +160,21 @@ module Test
end
def puke(klass, meth, e) # :nodoc:
if e.is_a?(MiniTest::Skip)
new_e = MiniTest::Skip.new(e.message)
if e.is_a?(Test::Skip)
new_e = Test::Skip.new(e.message)
new_e.set_backtrace(e.backtrace)
e = new_e
end
@partial_report << [klass.name, meth, e.is_a?(MiniTest::Assertion) ? e : ProxyError.new(e)]
@partial_report << [klass.name, meth, e.is_a?(Test::Assertion) ? e : ProxyError.new(e)]
super
end
def record(suite, method, assertions, time, error) # :nodoc:
case error
when nil
when MiniTest::Assertion, MiniTest::Skip
when Test::Assertion, Test::Skip
case error.cause
when nil, MiniTest::Assertion, MiniTest::Skip
when nil, Test::Assertion, Test::Skip
else
bt = error.backtrace
error = error.class.new(error.message)

Просмотреть файл

@ -191,7 +191,7 @@ module Test
rescue *PASSTHROUGH_EXCEPTIONS
raise
rescue Exception => e
@passed = MiniTest::Skip === e
@passed = Test::Skip === e
time = Time.now - start_time
runner.record self.class, self.__name__, self._assertions, time, e
result = runner.puke self.class, self.__name__, e