mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Imported minitest 1.3.0 r4429. Fixes issues reported by akira and nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fe7ce06150
commit
17358af75b
4 changed files with 67 additions and 32 deletions
|
@ -1,3 +1,8 @@
|
|||
Sun Oct 26 07:35:56 2008 Ryan Davis <ryan@wrath.local>
|
||||
|
||||
* lib/minitest/unit.rb: Imported minitest 1.3.0 r4429.
|
||||
* test/minitest/*: ditto.
|
||||
|
||||
Sun Oct 26 02:16:29 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
||||
|
||||
* configure.in ($MANTYPE): followed ruby.1, which had moved.
|
||||
|
|
|
@ -87,7 +87,7 @@ module MiniTest
|
|||
def assert_in_delta exp, act, delta = 0.001, msg = nil
|
||||
n = (exp - act).abs
|
||||
msg = message(msg) { "Expected #{exp} - #{act} (#{n}) to be < #{delta}" }
|
||||
assert delta > n, msg
|
||||
assert delta >= n, msg
|
||||
end
|
||||
|
||||
def assert_in_epsilon a, b, epsilon = 0.001, msg = nil
|
||||
|
@ -139,7 +139,10 @@ module MiniTest
|
|||
yield
|
||||
should_raise = true
|
||||
rescue Exception => e
|
||||
assert_includes(exp, e.class, exception_details(e, "<#{mu_pp(exp)}> exception expected, not"))
|
||||
assert(exp.any? { |ex|
|
||||
ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class
|
||||
}, exception_details(e, "#{mu_pp(exp)} exception expected, not"))
|
||||
|
||||
return e
|
||||
end
|
||||
|
||||
|
@ -191,7 +194,7 @@ module MiniTest
|
|||
def capture_io
|
||||
require 'stringio'
|
||||
|
||||
orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
|
||||
orig_stdout, orig_stderr = $stdout, $stderr
|
||||
captured_stdout, captured_stderr = StringIO.new, StringIO.new
|
||||
$stdout, $stderr = captured_stdout, captured_stderr
|
||||
|
||||
|
@ -303,14 +306,14 @@ module MiniTest
|
|||
refute exp.equal?(act), msg
|
||||
end
|
||||
|
||||
def skip msg = nil
|
||||
def skip msg = nil, bt = caller
|
||||
msg ||= "Skipped, no message given"
|
||||
raise MiniTest::Skip, msg
|
||||
raise MiniTest::Skip, msg, bt
|
||||
end
|
||||
end
|
||||
|
||||
class Unit
|
||||
VERSION = "1.3.0"
|
||||
VERSION = "1.3.1"
|
||||
|
||||
attr_accessor :report, :failures, :errors, :skips
|
||||
attr_accessor :test_count, :assertion_count
|
||||
|
|
|
@ -10,7 +10,7 @@ MiniTest::Unit.autorun
|
|||
|
||||
describe MiniTest::Spec do
|
||||
before do
|
||||
@assertion_count = 5
|
||||
@assertion_count = 4
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -65,7 +65,7 @@ describe MiniTest::Spec do
|
|||
end
|
||||
|
||||
it "needs to verify kinds of objects" do
|
||||
@assertion_count = 7
|
||||
@assertion_count = 6
|
||||
|
||||
(6 * 7).must_be_kind_of(Fixnum).must_equal true
|
||||
(6 * 7).must_be_kind_of(Numeric).must_equal true
|
||||
|
@ -73,7 +73,8 @@ describe MiniTest::Spec do
|
|||
end
|
||||
|
||||
it "needs to verify regexp matches" do
|
||||
@assertion_count = 7
|
||||
@assertion_count = 6
|
||||
|
||||
"blah".must_match(/\w+/).must_equal true
|
||||
proc { "blah".must_match(/\d+/) }.must_raise MiniTest::Assertion
|
||||
end
|
||||
|
@ -89,14 +90,14 @@ describe MiniTest::Spec do
|
|||
end
|
||||
|
||||
it "needs to catch an expected exception" do
|
||||
@assertion_count = 4
|
||||
@assertion_count = 2
|
||||
|
||||
proc { raise "blah" }.must_raise RuntimeError
|
||||
proc { raise MiniTest::Assertion }.must_raise MiniTest::Assertion
|
||||
end
|
||||
|
||||
it "needs to catch an unexpected exception" do
|
||||
@assertion_count = 4
|
||||
@assertion_count = 2
|
||||
|
||||
proc {
|
||||
proc { raise MiniTest::Assertion }.must_raise(RuntimeError)
|
||||
|
@ -104,13 +105,13 @@ describe MiniTest::Spec do
|
|||
end
|
||||
|
||||
it "needs raise if an expected exception is not raised" do
|
||||
@assertion_count = 3
|
||||
@assertion_count = 2
|
||||
|
||||
proc { proc { 42 }.must_raise(RuntimeError) }.must_raise MiniTest::Assertion
|
||||
end
|
||||
|
||||
it "needs to be able to catch a MiniTest::Assertion exception" do
|
||||
@assertion_count = 3
|
||||
@assertion_count = 2
|
||||
|
||||
proc { 1.wont_equal 1 }.must_raise MiniTest::Assertion
|
||||
end
|
||||
|
@ -126,7 +127,7 @@ describe MiniTest::Spec do
|
|||
end
|
||||
|
||||
it "needs to verify throw" do
|
||||
@assertion_count = 8
|
||||
@assertion_count = 6
|
||||
|
||||
proc { throw :blah }.must_throw(:blah).must_equal true
|
||||
proc { proc { }.must_throw(:blah) }.must_raise MiniTest::Assertion
|
||||
|
|
|
@ -9,8 +9,10 @@ require 'minitest/unit'
|
|||
|
||||
MiniTest::Unit.autorun
|
||||
|
||||
class TestMiniTest < MiniTest::Unit::TestCase
|
||||
module M; end
|
||||
class E < StandardError; include M; end
|
||||
|
||||
class TestMiniTest < MiniTest::Unit::TestCase
|
||||
def setup
|
||||
srand 42
|
||||
MiniTest::Unit::TestCase.reset
|
||||
|
@ -248,10 +250,10 @@ Finished in 0.00
|
|||
"
|
||||
output = @output.string.sub(/Finished in .*/, "Finished in 0.00")
|
||||
output.sub!(/Loaded suite .*/, 'Loaded suite blah')
|
||||
output.sub!(/[\w\/\.]+:\d+/, 'FILE:LINE')
|
||||
output.sub!(/^(\s+)(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+:/o, '\1FILE:LINE:')
|
||||
output.sub!(/\[(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+\]/o, '[FILE:LINE]')
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
def test_run_failing_filtered
|
||||
tc = Class.new(MiniTest::Unit::TestCase) do
|
||||
def test_something
|
||||
|
@ -426,7 +428,7 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_assert_includes_triggered
|
||||
@assertion_count = 4
|
||||
@assertion_count = 3
|
||||
|
||||
e = @tc.assert_raises MiniTest::Assertion do
|
||||
@tc.assert_includes [true], false
|
||||
|
@ -489,31 +491,35 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_assert_raises
|
||||
@assertion_count = 2
|
||||
|
||||
@tc.assert_raises RuntimeError do
|
||||
raise "blah"
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_raises_triggered_different
|
||||
@assertion_count = 2
|
||||
def test_assert_raises_module
|
||||
@tc.assert_raises M do
|
||||
raise E
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_raises_triggered_different
|
||||
e = assert_raises MiniTest::Assertion do
|
||||
@tc.assert_raises RuntimeError do
|
||||
raise SyntaxError, "icky"
|
||||
end
|
||||
end
|
||||
|
||||
expected = "<[RuntimeError]> exception expected, not
|
||||
expected = "[RuntimeError] exception expected, not
|
||||
Class: <SyntaxError>
|
||||
Message: <\"icky\">
|
||||
---Backtrace---
|
||||
FILE:LINE:in `test_assert_raises_triggered_different'
|
||||
---------------.
|
||||
Expected [RuntimeError] to include SyntaxError."
|
||||
---------------"
|
||||
|
||||
assert_equal expected, expected.gsub(/[\w\/\.]+:\d+/, 'FILE:LINE')
|
||||
actual = e.message.gsub(/[\w\/\.]+:\d+/, 'FILE:LINE')
|
||||
actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION =~ /^1\.9/
|
||||
|
||||
assert_equal expected, actual
|
||||
end
|
||||
|
||||
def test_assert_raises_triggered_none
|
||||
|
@ -528,6 +534,26 @@ Expected [RuntimeError] to include SyntaxError."
|
|||
assert_equal expected, e.message
|
||||
end
|
||||
|
||||
def test_assert_raises_triggered_subclass
|
||||
e = assert_raises MiniTest::Assertion do
|
||||
@tc.assert_raises StandardError do
|
||||
raise E
|
||||
end
|
||||
end
|
||||
|
||||
expected = "[StandardError] exception expected, not
|
||||
Class: <E>
|
||||
Message: <\"E\">
|
||||
---Backtrace---
|
||||
FILE:LINE:in `test_assert_raises_triggered_subclass'
|
||||
---------------"
|
||||
|
||||
actual = e.message.gsub(/[\w\/\.]+:\d+/, 'FILE:LINE')
|
||||
actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION =~ /^1\.9/
|
||||
|
||||
assert_equal expected, actual
|
||||
end
|
||||
|
||||
def test_assert_respond_to
|
||||
@tc.assert_respond_to "blah", :empty?
|
||||
end
|
||||
|
@ -733,7 +759,7 @@ Expected [RuntimeError] to include SyntaxError."
|
|||
end
|
||||
|
||||
def test_refute_includes_triggered
|
||||
@assertion_count = 4
|
||||
@assertion_count = 3
|
||||
|
||||
e = @tc.assert_raises MiniTest::Assertion do
|
||||
@tc.refute_includes [true], true
|
||||
|
|
Loading…
Reference in a new issue