mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Imported minitest 1.4.0 r5083.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7fc9c4a4a0
commit
58cfb41d2a
5 changed files with 49 additions and 24 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Thu Jun 18 16:21:05 2009 Ryan Davis <ryand-ruby@zenspider.com>
|
||||||
|
|
||||||
|
* lib/minitest/*.rb: Imported minitest 1.4.0 r5083.
|
||||||
|
* test/minitest/*.rb: ditto.
|
||||||
|
|
||||||
Thu Jun 18 01:35:51 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Thu Jun 18 01:35:51 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* numeric.c (flo_cmp): Infinity is greater than any bignum
|
* numeric.c (flo_cmp): Infinity is greater than any bignum
|
||||||
|
|
|
@ -5,5 +5,7 @@
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
require 'minitest/unit'
|
require 'minitest/unit'
|
||||||
|
require 'minitest/spec'
|
||||||
|
require 'minitest/mock'
|
||||||
|
|
||||||
MiniTest::Unit.autorun
|
MiniTest::Unit.autorun
|
||||||
|
|
|
@ -55,15 +55,25 @@ end
|
||||||
|
|
||||||
module Kernel
|
module Kernel
|
||||||
def describe desc, &block
|
def describe desc, &block
|
||||||
cls = Class.new(MiniTest::Spec)
|
stack = MiniTest::Spec.describe_stack
|
||||||
Object.const_set desc.to_s.split(/\W+/).map { |s| s.capitalize }.join, cls
|
name = desc.to_s.split(/\W+/).map { |s| s.capitalize }.join + "Spec"
|
||||||
|
cls = Object.class_eval "class #{name} < #{stack.last}; end; #{name}"
|
||||||
|
|
||||||
|
cls.nuke_test_methods!
|
||||||
|
|
||||||
|
stack.push cls
|
||||||
cls.class_eval(&block)
|
cls.class_eval(&block)
|
||||||
|
stack.pop
|
||||||
end
|
end
|
||||||
private :describe
|
private :describe
|
||||||
end
|
end
|
||||||
|
|
||||||
class MiniTest::Spec < MiniTest::Unit::TestCase
|
class MiniTest::Spec < MiniTest::Unit::TestCase
|
||||||
|
@@describe_stack = [MiniTest::Spec]
|
||||||
|
def self.describe_stack
|
||||||
|
@@describe_stack
|
||||||
|
end
|
||||||
|
|
||||||
def self.current
|
def self.current
|
||||||
@@current_spec
|
@@current_spec
|
||||||
end
|
end
|
||||||
|
@ -73,14 +83,29 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
||||||
@@current_spec = self
|
@@current_spec = self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.nuke_test_methods!
|
||||||
|
self.public_instance_methods.grep(/^test_/).each do |name|
|
||||||
|
send :remove_method, name rescue nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.define_inheritable_method name, &block
|
||||||
|
super_method = self.superclass.instance_method name
|
||||||
|
|
||||||
|
define_method name do
|
||||||
|
super_method.bind(self).call if super_method # regular super() warns
|
||||||
|
instance_eval(&block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.before(type = :each, &block)
|
def self.before(type = :each, &block)
|
||||||
raise "unsupported before type: #{type}" unless type == :each
|
raise "unsupported before type: #{type}" unless type == :each
|
||||||
define_method :setup, &block
|
define_inheritable_method :setup, &block
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.after(type = :each, &block)
|
def self.after(type = :each, &block)
|
||||||
raise "unsupported after type: #{type}" unless type == :each
|
raise "unsupported after type: #{type}" unless type == :each
|
||||||
define_method :teardown, &block
|
define_inheritable_method :teardown, &block
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.it desc, &block
|
def self.it desc, &block
|
||||||
|
|
|
@ -343,7 +343,7 @@ module MiniTest
|
||||||
def location e
|
def location e
|
||||||
last_before_assertion = ""
|
last_before_assertion = ""
|
||||||
e.backtrace.reverse_each do |s|
|
e.backtrace.reverse_each do |s|
|
||||||
break if s =~ /in .(assert|refute|flunk|pass|fail|raise)/
|
break if s =~ /in .(assert|refute|flunk|pass|fail|raise|must|wont)/
|
||||||
last_before_assertion = s
|
last_before_assertion = s
|
||||||
end
|
end
|
||||||
last_before_assertion.sub(/:in .*$/, '')
|
last_before_assertion.sub(/:in .*$/, '')
|
||||||
|
@ -430,30 +430,30 @@ module MiniTest
|
||||||
end
|
end
|
||||||
|
|
||||||
class TestCase
|
class TestCase
|
||||||
attr_reader :name
|
attr_reader :__name__
|
||||||
|
|
||||||
def run runner
|
def run runner
|
||||||
result = '.'
|
result = '.'
|
||||||
begin
|
begin
|
||||||
@passed = nil
|
@passed = nil
|
||||||
self.setup
|
self.setup
|
||||||
self.__send__ self.name
|
self.__send__ self.__name__
|
||||||
@passed = true
|
@passed = true
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
@passed = false
|
@passed = false
|
||||||
result = runner.puke(self.class, self.name, e)
|
result = runner.puke(self.class, self.__name__, e)
|
||||||
ensure
|
ensure
|
||||||
begin
|
begin
|
||||||
self.teardown
|
self.teardown
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
result = runner.puke(self.class, self.name, e)
|
result = runner.puke(self.class, self.__name__, e)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize name
|
def initialize name
|
||||||
@name = name
|
@__name__ = name
|
||||||
@passed = nil
|
@passed = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -325,7 +325,8 @@ Finished in 0.00
|
||||||
output.sub!(/^(\s+)(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+:/o, '\1FILE: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]')
|
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
|
||||||
|
@ -468,10 +469,9 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_assert_in_delta_triggered
|
def test_assert_in_delta_triggered
|
||||||
e = assert_raises(MiniTest::Assertion) do
|
util_assert_triggered 'Expected 0.0 - 0.001 (0.001) to be < 1.0e-06.' do
|
||||||
@tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001
|
@tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001
|
||||||
end
|
end
|
||||||
assert_match /\AExpected 0\.0 - 0\.001 \(0\.001\) to be < (?:1\.0+\de-06|9\.9+\de-07).\z/, e.message
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_assert_in_epsilon
|
def test_assert_in_epsilon
|
||||||
|
@ -489,10 +489,9 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_assert_in_epsilon_triggered
|
def test_assert_in_epsilon_triggered
|
||||||
e = assert_raises(MiniTest::Assertion) do
|
util_assert_triggered 'Expected 10000 - 9990 (10) to be < 9.99.' do
|
||||||
@tc.assert_in_epsilon 10000, 9990
|
@tc.assert_in_epsilon 10000, 9990
|
||||||
end
|
end
|
||||||
assert_match(/\AExpected 10000 - 9990 \(10\) to be < 9\.99*\d*\.\z/, e.message)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_assert_includes
|
def test_assert_includes
|
||||||
|
@ -831,10 +830,9 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_refute_in_delta_triggered
|
def test_refute_in_delta_triggered
|
||||||
e = assert_raises(MiniTest::Assertion) do
|
util_assert_triggered 'Expected 0.0 - 0.001 (0.001) to not be < 0.1.' do
|
||||||
@tc.refute_in_delta 0.0, 1.0 / 1000, 0.1
|
@tc.refute_in_delta 0.0, 1.0 / 1000, 0.1
|
||||||
end
|
end
|
||||||
assert_match /\AExpected 0\.0 - 0\.001 \(0\.001\) to not be < 0\.10*\d*\.\z/, e.message
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_refute_in_epsilon
|
def test_refute_in_epsilon
|
||||||
|
@ -983,11 +981,6 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
|
||||||
msg = e.message.sub(/(---Backtrace---).*/m, '\1')
|
msg = e.message.sub(/(---Backtrace---).*/m, '\1')
|
||||||
msg.gsub!(/\(0x[0-9a-f]+\)/, '(0xXXX)')
|
msg.gsub!(/\(0x[0-9a-f]+\)/, '(0xXXX)')
|
||||||
|
|
||||||
begin
|
assert_equal expected, msg
|
||||||
assert_equal expected, msg
|
|
||||||
rescue MiniTest::Assertion => e
|
|
||||||
e.backtrace.shift(3)
|
|
||||||
raise
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue