зеркало из https://github.com/github/ruby.git
Replace Test::Assertion and Test::Skip to Test::Unit::AssertionFailedError and Test::Unit::PendedError
This commit is contained in:
Родитель
7cec81e073
Коммит
d05383812a
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче