1
0
Fork 0
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:
ryan 2008-10-25 22:38:09 +00:00
parent fe7ce06150
commit 17358af75b
4 changed files with 67 additions and 32 deletions

View file

@ -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> Sun Oct 26 02:16:29 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp>
* configure.in ($MANTYPE): followed ruby.1, which had moved. * configure.in ($MANTYPE): followed ruby.1, which had moved.

View file

@ -87,7 +87,7 @@ module MiniTest
def assert_in_delta exp, act, delta = 0.001, msg = nil def assert_in_delta exp, act, delta = 0.001, msg = nil
n = (exp - act).abs n = (exp - act).abs
msg = message(msg) { "Expected #{exp} - #{act} (#{n}) to be < #{delta}" } msg = message(msg) { "Expected #{exp} - #{act} (#{n}) to be < #{delta}" }
assert delta > n, msg assert delta >= n, msg
end end
def assert_in_epsilon a, b, epsilon = 0.001, msg = nil def assert_in_epsilon a, b, epsilon = 0.001, msg = nil
@ -139,7 +139,10 @@ module MiniTest
yield yield
should_raise = true should_raise = true
rescue Exception => e 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 return e
end end
@ -188,12 +191,12 @@ module MiniTest
assert caught, message(msg) { default } assert caught, message(msg) { default }
end end
def capture_io def capture_io
require 'stringio' require 'stringio'
orig_stdout, orig_stderr = $stdout.dup, $stderr.dup orig_stdout, orig_stderr = $stdout, $stderr
captured_stdout, captured_stderr = StringIO.new, StringIO.new captured_stdout, captured_stderr = StringIO.new, StringIO.new
$stdout, $stderr = captured_stdout, captured_stderr $stdout, $stderr = captured_stdout, captured_stderr
yield yield
@ -303,14 +306,14 @@ module MiniTest
refute exp.equal?(act), msg refute exp.equal?(act), msg
end end
def skip msg = nil def skip msg = nil, bt = caller
msg ||= "Skipped, no message given" msg ||= "Skipped, no message given"
raise MiniTest::Skip, msg raise MiniTest::Skip, msg, bt
end end
end end
class Unit class Unit
VERSION = "1.3.0" VERSION = "1.3.1"
attr_accessor :report, :failures, :errors, :skips attr_accessor :report, :failures, :errors, :skips
attr_accessor :test_count, :assertion_count attr_accessor :test_count, :assertion_count

View file

@ -10,7 +10,7 @@ MiniTest::Unit.autorun
describe MiniTest::Spec do describe MiniTest::Spec do
before do before do
@assertion_count = 5 @assertion_count = 4
end end
after do after do
@ -65,7 +65,7 @@ describe MiniTest::Spec do
end end
it "needs to verify kinds of objects" do 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(Fixnum).must_equal true
(6 * 7).must_be_kind_of(Numeric).must_equal true (6 * 7).must_be_kind_of(Numeric).must_equal true
@ -73,7 +73,8 @@ describe MiniTest::Spec do
end end
it "needs to verify regexp matches" do it "needs to verify regexp matches" do
@assertion_count = 7 @assertion_count = 6
"blah".must_match(/\w+/).must_equal true "blah".must_match(/\w+/).must_equal true
proc { "blah".must_match(/\d+/) }.must_raise MiniTest::Assertion proc { "blah".must_match(/\d+/) }.must_raise MiniTest::Assertion
end end
@ -89,14 +90,14 @@ describe MiniTest::Spec do
end end
it "needs to catch an expected exception" do it "needs to catch an expected exception" do
@assertion_count = 4 @assertion_count = 2
proc { raise "blah" }.must_raise RuntimeError proc { raise "blah" }.must_raise RuntimeError
proc { raise MiniTest::Assertion }.must_raise MiniTest::Assertion proc { raise MiniTest::Assertion }.must_raise MiniTest::Assertion
end end
it "needs to catch an unexpected exception" do it "needs to catch an unexpected exception" do
@assertion_count = 4 @assertion_count = 2
proc { proc {
proc { raise MiniTest::Assertion }.must_raise(RuntimeError) proc { raise MiniTest::Assertion }.must_raise(RuntimeError)
@ -104,13 +105,13 @@ describe MiniTest::Spec do
end end
it "needs raise if an expected exception is not raised" do 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 proc { proc { 42 }.must_raise(RuntimeError) }.must_raise MiniTest::Assertion
end end
it "needs to be able to catch a MiniTest::Assertion exception" do 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 proc { 1.wont_equal 1 }.must_raise MiniTest::Assertion
end end
@ -126,7 +127,7 @@ describe MiniTest::Spec do
end end
it "needs to verify throw" do it "needs to verify throw" do
@assertion_count = 8 @assertion_count = 6
proc { throw :blah }.must_throw(:blah).must_equal true proc { throw :blah }.must_throw(:blah).must_equal true
proc { proc { }.must_throw(:blah) }.must_raise MiniTest::Assertion proc { proc { }.must_throw(:blah) }.must_raise MiniTest::Assertion

View file

@ -9,8 +9,10 @@ require 'minitest/unit'
MiniTest::Unit.autorun MiniTest::Unit.autorun
class TestMiniTest < MiniTest::Unit::TestCase module M; end
class E < StandardError; include M; end
class TestMiniTest < MiniTest::Unit::TestCase
def setup def setup
srand 42 srand 42
MiniTest::Unit::TestCase.reset MiniTest::Unit::TestCase.reset
@ -248,10 +250,10 @@ Finished in 0.00
" "
output = @output.string.sub(/Finished in .*/, "Finished in 0.00") output = @output.string.sub(/Finished in .*/, "Finished in 0.00")
output.sub!(/Loaded suite .*/, 'Loaded suite blah') 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) assert_equal(expected, output)
end end
def test_run_failing_filtered def test_run_failing_filtered
tc = Class.new(MiniTest::Unit::TestCase) do tc = Class.new(MiniTest::Unit::TestCase) do
def test_something def test_something
@ -426,7 +428,7 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
end end
def test_assert_includes_triggered def test_assert_includes_triggered
@assertion_count = 4 @assertion_count = 3
e = @tc.assert_raises MiniTest::Assertion do e = @tc.assert_raises MiniTest::Assertion do
@tc.assert_includes [true], false @tc.assert_includes [true], false
@ -489,31 +491,35 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
end end
def test_assert_raises def test_assert_raises
@assertion_count = 2
@tc.assert_raises RuntimeError do @tc.assert_raises RuntimeError do
raise "blah" raise "blah"
end end
end end
def test_assert_raises_triggered_different def test_assert_raises_module
@assertion_count = 2 @tc.assert_raises M do
raise E
end
end
def test_assert_raises_triggered_different
e = assert_raises MiniTest::Assertion do e = assert_raises MiniTest::Assertion do
@tc.assert_raises RuntimeError do @tc.assert_raises RuntimeError do
raise SyntaxError, "icky" raise SyntaxError, "icky"
end end
end end
expected = "<[RuntimeError]> exception expected, not expected = "[RuntimeError] exception expected, not
Class: <SyntaxError> Class: <SyntaxError>
Message: <\"icky\"> Message: <\"icky\">
---Backtrace--- ---Backtrace---
FILE:LINE:in `test_assert_raises_triggered_different' 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 end
def test_assert_raises_triggered_none def test_assert_raises_triggered_none
@ -528,6 +534,26 @@ Expected [RuntimeError] to include SyntaxError."
assert_equal expected, e.message assert_equal expected, e.message
end 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 def test_assert_respond_to
@tc.assert_respond_to "blah", :empty? @tc.assert_respond_to "blah", :empty?
end end
@ -733,7 +759,7 @@ Expected [RuntimeError] to include SyntaxError."
end end
def test_refute_includes_triggered def test_refute_includes_triggered
@assertion_count = 4 @assertion_count = 3
e = @tc.assert_raises MiniTest::Assertion do e = @tc.assert_raises MiniTest::Assertion do
@tc.refute_includes [true], true @tc.refute_includes [true], true