mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Imported minitest 1.5.0 r5596
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
74972dcc6f
commit
06925a0952
4 changed files with 106 additions and 42 deletions
|
|
@ -1,3 +1,8 @@
|
||||||
|
Thu Jan 7 07:56:09 2010 Ryan Davis <ryand-ruby@zenspider.com>
|
||||||
|
|
||||||
|
* lib/minitest/*.rb: Imported minitest 1.5.0 r5596.
|
||||||
|
* test/minitest/*.rb: ditto.
|
||||||
|
|
||||||
Tue Jan 5 19:30:53 2010 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
|
Tue Jan 5 19:30:53 2010 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
|
||||||
|
|
||||||
* test/ruby/test_exception.rb: add a test. cf [ruby-dev:39116]
|
* test/ruby/test_exception.rb: add a test. cf [ruby-dev:39116]
|
||||||
|
|
@ -50496,7 +50501,7 @@ Sun Jul 9 18:06:47 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
* lib/mkmf.rb (create_makefile): prevent substitution of macro
|
* lib/mkmf.rb (create_makefile): prevent substitution of macro
|
||||||
definition. fixed: http://www.yotabanana.com/lab/20060624.html#p02
|
definition. fixed: http://www.yotabanana.com/lab/20060624.html#p02
|
||||||
|
|
||||||
Sun Jul 9 07:58:48 2006 Ryan Davis <ryand@zenspider.com>
|
Sun Jul 9 07:58:48 2006 Ryan Davis <ryand-ruby@zenspider.com>
|
||||||
|
|
||||||
* lib/rdoc/parsers/parse_f95.rb: massive overhaul from Yasuhiro
|
* lib/rdoc/parsers/parse_f95.rb: massive overhaul from Yasuhiro
|
||||||
Morikawa including new file suffixes, function support, public
|
Morikawa including new file suffixes, function support, public
|
||||||
|
|
@ -65904,7 +65909,7 @@ Wed Mar 10 16:00:14 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
* struct.c (rb_struct_s_def): Struct::new executes block with
|
* struct.c (rb_struct_s_def): Struct::new executes block with
|
||||||
generated struct class. [ruby-talk:02606]
|
generated struct class. [ruby-talk:02606]
|
||||||
|
|
||||||
Wed Mar 10 15:58:43 2004 Ryan Davis <ryand@zenspider.com>
|
Wed Mar 10 15:58:43 2004 Ryan Davis <ryand-ruby@zenspider.com>
|
||||||
|
|
||||||
* eval.c (eval): Only print backtrace if generating the backtrace
|
* eval.c (eval): Only print backtrace if generating the backtrace
|
||||||
doesn't generate an exception. [ruby-core:02621]
|
doesn't generate an exception. [ruby-core:02621]
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,23 @@
|
||||||
require 'minitest/unit'
|
require 'minitest/unit'
|
||||||
|
|
||||||
class Module
|
class Module
|
||||||
def infect_with_assertions pos_prefix, neg_prefix, skip_re, map = {}
|
def infect_an_assertion meth, new_name, dont_flip = false
|
||||||
|
# warn "%-22p -> %p %p" % [meth, new_name, dont_flip]
|
||||||
|
self.class_eval <<-EOM
|
||||||
|
def #{new_name} *args, &block
|
||||||
|
return MiniTest::Spec.current.#{meth}(*args, &self) if
|
||||||
|
Proc === self
|
||||||
|
return MiniTest::Spec.current.#{meth}(args.first, self) if
|
||||||
|
args.size == 1 unless #{!!dont_flip}
|
||||||
|
return MiniTest::Spec.current.#{meth}(self, *args)
|
||||||
|
end
|
||||||
|
EOM
|
||||||
|
end
|
||||||
|
|
||||||
|
def infect_with_assertions(pos_prefix, neg_prefix,
|
||||||
|
skip_re,
|
||||||
|
dont_flip_re = /\c0/,
|
||||||
|
map = {})
|
||||||
MiniTest::Assertions.public_instance_methods(false).each do |meth|
|
MiniTest::Assertions.public_instance_methods(false).each do |meth|
|
||||||
meth = meth.to_s
|
meth = meth.to_s
|
||||||
|
|
||||||
|
|
@ -25,14 +41,7 @@ class Module
|
||||||
regexp, replacement = map.find { |re, _| new_name =~ re }
|
regexp, replacement = map.find { |re, _| new_name =~ re }
|
||||||
new_name.sub! regexp, replacement if replacement
|
new_name.sub! regexp, replacement if replacement
|
||||||
|
|
||||||
# warn "%-22p -> %p %p" % [meth, new_name, regexp]
|
infect_an_assertion meth, new_name, new_name =~ dont_flip_re
|
||||||
self.class_eval <<-EOM
|
|
||||||
def #{new_name} *args, &block
|
|
||||||
return MiniTest::Spec.current.#{meth}(*args, &self) if Proc === self
|
|
||||||
return MiniTest::Spec.current.#{meth}(args.first, self) if args.size == 1
|
|
||||||
return MiniTest::Spec.current.#{meth}(self, *args)
|
|
||||||
end
|
|
||||||
EOM
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -40,6 +49,7 @@ end
|
||||||
Object.infect_with_assertions(:must, :wont,
|
Object.infect_with_assertions(:must, :wont,
|
||||||
/^(must|wont)$|wont_(throw)|
|
/^(must|wont)$|wont_(throw)|
|
||||||
must_(block|not?_|nothing|raise$)/x,
|
must_(block|not?_|nothing|raise$)/x,
|
||||||
|
/(must|wont)_(include|respond_to)/,
|
||||||
/(must_throw)s/ => '\1',
|
/(must_throw)s/ => '\1',
|
||||||
/(?!not)_same/ => '_be_same_as',
|
/(?!not)_same/ => '_be_same_as',
|
||||||
/_in_/ => '_be_within_',
|
/_in_/ => '_be_within_',
|
||||||
|
|
@ -57,7 +67,9 @@ module Kernel
|
||||||
def describe desc, &block
|
def describe desc, &block
|
||||||
stack = MiniTest::Spec.describe_stack
|
stack = MiniTest::Spec.describe_stack
|
||||||
name = desc.to_s.split(/\W+/).map { |s| s.capitalize }.join + "Spec"
|
name = desc.to_s.split(/\W+/).map { |s| s.capitalize }.join + "Spec"
|
||||||
cls = Object.class_eval "class #{name} < #{stack.last}; end; #{name}"
|
prev = stack.last
|
||||||
|
name = "#{prev == MiniTest::Spec ? nil : prev}::#{name}"
|
||||||
|
cls = Object.class_eval "class #{name} < #{prev}; end; #{name}"
|
||||||
|
|
||||||
cls.nuke_test_methods!
|
cls.nuke_test_methods!
|
||||||
|
|
||||||
|
|
@ -85,7 +97,7 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
||||||
|
|
||||||
def self.nuke_test_methods!
|
def self.nuke_test_methods!
|
||||||
self.public_instance_methods.grep(/^test_/).each do |name|
|
self.public_instance_methods.grep(/^test_/).each do |name|
|
||||||
send :remove_method, name rescue nil
|
self.send :undef_method, name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -99,11 +111,19 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.before(type = :each, &block)
|
def self.before(type = :each, &block)
|
||||||
|
if type == :all
|
||||||
|
warn "change before :all to before :each"
|
||||||
|
type = :each
|
||||||
|
end
|
||||||
raise "unsupported before type: #{type}" unless type == :each
|
raise "unsupported before type: #{type}" unless type == :each
|
||||||
define_inheritable_method :setup, &block
|
define_inheritable_method :setup, &block
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.after(type = :each, &block)
|
def self.after(type = :each, &block)
|
||||||
|
if type == :all # REFACTOR
|
||||||
|
warn "change before :all to before :each"
|
||||||
|
type = :each
|
||||||
|
end
|
||||||
raise "unsupported after type: #{type}" unless type == :each
|
raise "unsupported after type: #{type}" unless type == :each
|
||||||
define_inheritable_method :teardown, &block
|
define_inheritable_method :teardown, &block
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -95,25 +95,25 @@ module MiniTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_includes collection, obj, msg = nil
|
def assert_includes collection, obj, msg = nil
|
||||||
msg = message(msg) { "Expected #{mu_pp(collection)} to include #{mu_pp(obj)}" }
|
msg = message(msg) {
|
||||||
flip = (obj.respond_to? :include?) && ! (collection.respond_to? :include?) # HACK for specs
|
"Expected #{mu_pp(collection)} to include #{mu_pp(obj)}"
|
||||||
obj, collection = collection, obj if flip
|
}
|
||||||
assert_respond_to collection, :include?
|
assert_respond_to collection, :include?
|
||||||
assert collection.include?(obj), msg
|
assert collection.include?(obj), msg
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_instance_of cls, obj, msg = nil
|
def assert_instance_of cls, obj, msg = nil
|
||||||
msg = message(msg) { "Expected #{mu_pp(obj)} to be an instance of #{cls}, not #{obj.class}" }
|
msg = message(msg) {
|
||||||
flip = (Module === obj) && ! (Module === cls) # HACK for specs
|
"Expected #{mu_pp(obj)} to be an instance of #{cls}, not #{obj.class}"
|
||||||
obj, cls = cls, obj if flip
|
}
|
||||||
|
|
||||||
assert obj.instance_of?(cls), msg
|
assert obj.instance_of?(cls), msg
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_kind_of cls, obj, msg = nil # TODO: merge with instance_of
|
def assert_kind_of cls, obj, msg = nil # TODO: merge with instance_of
|
||||||
msg = message(msg) {
|
msg = message(msg) {
|
||||||
"Expected #{mu_pp(obj)} to be a kind of #{cls}, not #{obj.class}" }
|
"Expected #{mu_pp(obj)} to be a kind of #{cls}, not #{obj.class}" }
|
||||||
flip = (Module === obj) && ! (Module === cls) # HACK for specs
|
|
||||||
obj, cls = cls, obj if flip
|
|
||||||
assert obj.kind_of?(cls), msg
|
assert obj.kind_of?(cls), msg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -136,28 +136,29 @@ module MiniTest
|
||||||
|
|
||||||
def assert_raises *exp
|
def assert_raises *exp
|
||||||
msg = String === exp.last ? exp.pop : nil
|
msg = String === exp.last ? exp.pop : nil
|
||||||
|
msg = msg.to_s + "\n" if msg
|
||||||
should_raise = false
|
should_raise = false
|
||||||
begin
|
begin
|
||||||
yield
|
yield
|
||||||
should_raise = true
|
should_raise = true
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
details = "#{msg}#{mu_pp(exp)} exception expected, not"
|
||||||
assert(exp.any? { |ex|
|
assert(exp.any? { |ex|
|
||||||
ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class
|
ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class
|
||||||
}, exception_details(e, "#{mu_pp(exp)} exception expected, not"))
|
}, exception_details(e, details))
|
||||||
|
|
||||||
return e
|
return e
|
||||||
end
|
end
|
||||||
|
|
||||||
exp = exp.first if exp.size == 1
|
exp = exp.first if exp.size == 1
|
||||||
flunk "#{mu_pp(exp)} expected but nothing was raised." if should_raise
|
flunk "#{msg}#{mu_pp(exp)} expected but nothing was raised." if
|
||||||
|
should_raise
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_respond_to obj, meth, msg = nil
|
def assert_respond_to obj, meth, msg = nil
|
||||||
msg = message(msg) {
|
msg = message(msg) {
|
||||||
"Expected #{mu_pp(obj)} (#{obj.class}) to respond to ##{meth}"
|
"Expected #{mu_pp(obj)} (#{obj.class}) to respond to ##{meth}"
|
||||||
}
|
}
|
||||||
flip = (Symbol === obj) && ! (Symbol === meth) # HACK for specs
|
|
||||||
obj, meth = meth, obj if flip
|
|
||||||
assert obj.respond_to?(meth), msg
|
assert obj.respond_to?(meth), msg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -247,13 +248,17 @@ module MiniTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def refute_equal exp, act, msg = nil
|
def refute_equal exp, act, msg = nil
|
||||||
msg = message(msg) { "Expected #{mu_pp(act)} to not be equal to #{mu_pp(exp)}" }
|
msg = message(msg) {
|
||||||
|
"Expected #{mu_pp(act)} to not be equal to #{mu_pp(exp)}"
|
||||||
|
}
|
||||||
refute exp == act, msg
|
refute exp == act, msg
|
||||||
end
|
end
|
||||||
|
|
||||||
def refute_in_delta exp, act, delta = 0.001, msg = nil
|
def refute_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 not be < #{delta}" }
|
msg = message(msg) {
|
||||||
|
"Expected #{exp} - #{act} (#{n}) to not be < #{delta}"
|
||||||
|
}
|
||||||
refute delta > n, msg
|
refute delta > n, msg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -262,24 +267,22 @@ module MiniTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def refute_includes collection, obj, msg = nil
|
def refute_includes collection, obj, msg = nil
|
||||||
msg = message(msg) { "Expected #{mu_pp(collection)} to not include #{mu_pp(obj)}" }
|
msg = message(msg) {
|
||||||
flip = (obj.respond_to? :include?) && ! (collection.respond_to? :include?) # HACK for specs
|
"Expected #{mu_pp(collection)} to not include #{mu_pp(obj)}"
|
||||||
obj, collection = collection, obj if flip
|
}
|
||||||
assert_respond_to collection, :include?
|
assert_respond_to collection, :include?
|
||||||
refute collection.include?(obj), msg
|
refute collection.include?(obj), msg
|
||||||
end
|
end
|
||||||
|
|
||||||
def refute_instance_of cls, obj, msg = nil
|
def refute_instance_of cls, obj, msg = nil
|
||||||
msg = message(msg) { "Expected #{mu_pp(obj)} to not be an instance of #{cls}" }
|
msg = message(msg) {
|
||||||
flip = (Module === obj) && ! (Module === cls) # HACK for specs
|
"Expected #{mu_pp(obj)} to not be an instance of #{cls}"
|
||||||
obj, cls = cls, obj if flip
|
}
|
||||||
refute obj.instance_of?(cls), msg
|
refute obj.instance_of?(cls), msg
|
||||||
end
|
end
|
||||||
|
|
||||||
def refute_kind_of cls, obj, msg = nil # TODO: merge with instance_of
|
def refute_kind_of cls, obj, msg = nil # TODO: merge with instance_of
|
||||||
msg = message(msg) { "Expected #{mu_pp(obj)} to not be a kind of #{cls}" }
|
msg = message(msg) { "Expected #{mu_pp(obj)} to not be a kind of #{cls}" }
|
||||||
flip = (Module === obj) && ! (Module === cls) # HACK for specs
|
|
||||||
obj, cls = cls, obj if flip
|
|
||||||
refute obj.kind_of?(cls), msg
|
refute obj.kind_of?(cls), msg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -296,19 +299,22 @@ module MiniTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def refute_operator o1, op, o2, msg = nil
|
def refute_operator o1, op, o2, msg = nil
|
||||||
msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op} #{mu_pp(o2)}" }
|
msg = message(msg) {
|
||||||
|
"Expected #{mu_pp(o1)} to not be #{op} #{mu_pp(o2)}"
|
||||||
|
}
|
||||||
refute o1.__send__(op, o2), msg
|
refute o1.__send__(op, o2), msg
|
||||||
end
|
end
|
||||||
|
|
||||||
def refute_respond_to obj, meth, msg = nil
|
def refute_respond_to obj, meth, msg = nil
|
||||||
msg = message(msg) { "Expected #{mu_pp(obj)} to not respond to #{meth}" }
|
msg = message(msg) { "Expected #{mu_pp(obj)} to not respond to #{meth}" }
|
||||||
flip = (Symbol === obj) && ! (Symbol === meth) # HACK for specs
|
|
||||||
obj, meth = meth, obj if flip
|
|
||||||
refute obj.respond_to?(meth), msg
|
refute obj.respond_to?(meth), msg
|
||||||
end
|
end
|
||||||
|
|
||||||
def refute_same exp, act, msg = nil
|
def refute_same exp, act, msg = nil
|
||||||
msg = message(msg) { "Expected #{mu_pp(act)} to not be the same as #{mu_pp(exp)}" }
|
msg = message(msg) {
|
||||||
|
"Expected #{mu_pp(act)} to not be the same as #{mu_pp(exp)}"
|
||||||
|
}
|
||||||
refute exp.equal?(act), msg
|
refute exp.equal?(act), msg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -319,7 +325,7 @@ module MiniTest
|
||||||
end
|
end
|
||||||
|
|
||||||
class Unit
|
class Unit
|
||||||
VERSION = "1.4.2"
|
VERSION = "1.5.0"
|
||||||
|
|
||||||
attr_accessor :report, :failures, :errors, :skips
|
attr_accessor :report, :failures, :errors, :skips
|
||||||
attr_accessor :test_count, :assertion_count
|
attr_accessor :test_count, :assertion_count
|
||||||
|
|
@ -520,8 +526,8 @@ module MiniTest
|
||||||
|
|
||||||
include MiniTest::Assertions
|
include MiniTest::Assertions
|
||||||
end # class TestCase
|
end # class TestCase
|
||||||
end # class Test
|
end # class Unit
|
||||||
end # module Mini
|
end # module MiniTest
|
||||||
|
|
||||||
if $DEBUG then
|
if $DEBUG then
|
||||||
# this helps me ferret out porting issues
|
# this helps me ferret out porting issues
|
||||||
|
|
|
||||||
|
|
@ -616,6 +616,27 @@ FILE:LINE:in `test_assert_raises_triggered_different'
|
||||||
assert_equal expected, actual
|
assert_equal expected, actual
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_assert_raises_triggered_different_msg
|
||||||
|
e = assert_raises MiniTest::Assertion do
|
||||||
|
@tc.assert_raises RuntimeError, "XXX" do
|
||||||
|
raise SyntaxError, "icky"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
expected = "XXX
|
||||||
|
[RuntimeError] exception expected, not
|
||||||
|
Class: <SyntaxError>
|
||||||
|
Message: <\"icky\">
|
||||||
|
---Backtrace---
|
||||||
|
FILE:LINE:in `test_assert_raises_triggered_different_msg'
|
||||||
|
---------------"
|
||||||
|
|
||||||
|
actual = e.message.gsub(/^.+:\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
|
def test_assert_raises_triggered_none
|
||||||
e = assert_raises MiniTest::Assertion do
|
e = assert_raises MiniTest::Assertion do
|
||||||
@tc.assert_raises MiniTest::Assertion do
|
@tc.assert_raises MiniTest::Assertion do
|
||||||
|
|
@ -628,6 +649,18 @@ FILE:LINE:in `test_assert_raises_triggered_different'
|
||||||
assert_equal expected, e.message
|
assert_equal expected, e.message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_assert_raises_triggered_none_msg
|
||||||
|
e = assert_raises MiniTest::Assertion do
|
||||||
|
@tc.assert_raises MiniTest::Assertion, "XXX" do
|
||||||
|
# do nothing
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
expected = "XXX\nMiniTest::Assertion expected but nothing was raised."
|
||||||
|
|
||||||
|
assert_equal expected, e.message
|
||||||
|
end
|
||||||
|
|
||||||
def test_assert_raises_triggered_subclass
|
def test_assert_raises_triggered_subclass
|
||||||
e = assert_raises MiniTest::Assertion do
|
e = assert_raises MiniTest::Assertion do
|
||||||
@tc.assert_raises StandardError do
|
@tc.assert_raises StandardError do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue