1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Imported minitest 2.8.1

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ryan 2011-11-17 23:02:16 +00:00
parent 6b43a55611
commit d6c86e631d
9 changed files with 118 additions and 64 deletions

View file

@ -1,3 +1,9 @@
Fri Nov 18 08:00:41 2011 Ryan Davis <ryan@lust.zenspider.com>
* lib/minitest/*: Imported minitest 2.8.1 (r6750)
* test/minitest/*: ditto
* configure.in: Improved gcc-llvm error message to help people migrate.
Thu Nov 17 20:43:34 2011 Tanaka Akira <akr@fsij.org>
* ext/dbm/extconf.rb: revert a part of the patch in [ruby-dev:41531].
@ -1305,7 +1311,7 @@ Thu Oct 20 05:58:02 2011 Eric Hodel <drbrain@segment7.net>
* ext/openssl/ossl_ns_spki.c (Init_ossl_ns_spki): Stub documentation
for Netscape SPKI.
Thu Oct 20 05:13:39 2011 Ryan Davis <ryan@lust.zenspider.com>
Thu Oct 20 05:13:39 2011 Ryan Davis <ryand-ruby@zenspider.com>
* lib/minitest/*: Imported minitest 2.6.2 (r6712)
* test/minitest/*: ditto

View file

@ -129,9 +129,7 @@ benchmarks won't run.
# Override self.bench_range or default range is [1, 10, 100, 1_000, 10_000]
def bench_my_algorithm
assert_performance_linear 0.9999 do |n| # n is a range value
n.times do
@obj.my_algorithm
end
@obj.my_algorithm(n)
end
end
end

View file

@ -83,8 +83,8 @@ class MiniTest::Unit
#
# def bench_algorithm
# validation = proc { |x, y| ... }
# assert_performance validation do |x|
# @obj.algorithm
# assert_performance validation do |n|
# @obj.algorithm(n)
# end
# end
@ -127,8 +127,8 @@ class MiniTest::Unit
# Eg:
#
# def bench_algorithm
# assert_performance_constant 0.9999 do |x|
# @obj.algorithm
# assert_performance_constant 0.9999 do |n|
# @obj.algorithm(n)
# end
# end
@ -153,8 +153,8 @@ class MiniTest::Unit
# Eg:
#
# def bench_algorithm
# assert_performance_exponential 0.9999 do |x|
# @obj.algorithm
# assert_performance_exponential 0.9999 do |n|
# @obj.algorithm(n)
# end
# end
@ -173,8 +173,8 @@ class MiniTest::Unit
# Eg:
#
# def bench_algorithm
# assert_performance_linear 0.9999 do |x|
# @obj.algorithm
# assert_performance_linear 0.9999 do |n|
# @obj.algorithm(n)
# end
# end
@ -329,8 +329,8 @@ class MiniTest::Spec
# Create a benchmark that verifies that the performance is linear.
#
# describe "my class" do
# bench_performance_linear "fast_algorithm", 0.9999 do
# @obj.fast_algorithm
# bench_performance_linear "fast_algorithm", 0.9999 do |n|
# @obj.fast_algorithm(n)
# end
# end
@ -344,8 +344,8 @@ class MiniTest::Spec
# Create a benchmark that verifies that the performance is constant.
#
# describe "my class" do
# bench_performance_constant "zoom_algorithm!" do
# @obj.zoom_algorithm!
# bench_performance_constant "zoom_algorithm!" do |n|
# @obj.zoom_algorithm!(n)
# end
# end
@ -359,8 +359,8 @@ class MiniTest::Spec
# Create a benchmark that verifies that the performance is exponential.
#
# describe "my class" do
# bench_performance_exponential "algorithm" do
# @obj.algorithm
# bench_performance_exponential "algorithm" do |n|
# @obj.algorithm(n)
# end
# end

View file

@ -92,7 +92,7 @@ module MiniTest
@actual_calls[sym] << {
:retval => retval,
:args => expected_args.zip(args).map { |mod, a| mod if mod === a }
:args => expected_args.zip(args).map { |mod, a| mod === a ? mod : a }
}
retval

View file

@ -95,5 +95,5 @@ class PrideLOL < PrideIO # inspired by lolcat, but massively cleaned up
end
end
klass = ENV['TERM'] =~ /^xterm(-256color)?$/ ? PrideLOL : PrideIO
klass = ENV['TERM'] =~ /^xterm|-256color$/ ? PrideLOL : PrideIO
MiniTest::Unit.output = klass.new(MiniTest::Unit.output)

View file

@ -12,7 +12,7 @@ class Module # :nodoc:
def infect_an_assertion meth, new_name, dont_flip = false # :nodoc:
# warn "%-22p -> %p %p" % [meth, new_name, dont_flip]
self.class_eval <<-EOM
def #{new_name} *args, &block
def #{new_name} *args
return MiniTest::Spec.current.#{meth}(*args, &self) if
Proc === self
return MiniTest::Spec.current.#{meth}(args.first, self) if
@ -138,10 +138,6 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
@@describe_stack
end
def self.current # :nodoc:
@@current_spec
end
##
# Returns the children of this spec.
@ -149,11 +145,6 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
@children ||= []
end
def initialize name # :nodoc:
super
@@current_spec = self
end
def self.nuke_test_methods! # :nodoc:
self.public_instance_methods.grep(/^test_/).each do |name|
self.send :undef_method, name

View file

@ -14,6 +14,18 @@ require 'rbconfig'
module MiniTest
def self.const_missing name # :nodoc:
case name
when :MINI_DIR then
msg = "MiniTest::MINI_DIR was removed. Don't violate other's internals."
warn "WAR\NING: #{msg}"
warn "WAR\NING: Used by #{caller.first}."
const_set :MINI_DIR, "bad value"
else
super
end
end
##
# Assertion base class
@ -24,22 +36,6 @@ module MiniTest
class Skip < Assertion; end
file = if RUBY_VERSION >= '1.9.0' then # bt's expanded, but __FILE__ isn't :(
File.expand_path __FILE__
elsif __FILE__ =~ /^[^\.]/ then # assume both relative
require 'pathname'
pwd = Pathname.new Dir.pwd
pn = Pathname.new File.expand_path(__FILE__)
relpath = pn.relative_path_from(pwd) rescue pn
pn = File.join ".", relpath unless pn.relative?
pn.to_s
else # assume both are expanded
__FILE__
end
# './lib' in project dir, or '/usr/local/blahblah' if installed
MINI_DIR = File.dirname(File.dirname(file)) # :nodoc:
def self.filter_backtrace bt # :nodoc:
return ["No backtrace"] unless bt
@ -47,11 +43,11 @@ module MiniTest
unless $DEBUG then
bt.each do |line|
break if line.rindex MINI_DIR, 0
break if line =~ /lib\/minitest/
new_bt << line
end
new_bt = bt.reject { |line| line.rindex MINI_DIR, 0 } if new_bt.empty?
new_bt = bt.reject { |line| line =~ /lib\/minitest/ } if new_bt.empty?
new_bt = bt.dup if new_bt.empty?
else
new_bt = bt.dup
@ -357,10 +353,9 @@ module MiniTest
end
rescue Exception => e
details = "#{msg}#{mu_pp(exp)} exception expected, not"
bool = exp.any? { |ex|
ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class
}
assert(bool, bool ? '' : exception_details(e, details))
assert(exp.any? { |ex|
ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class
}, exception_details(e, details))
return e
end
@ -652,7 +647,7 @@ module MiniTest
end
class Unit
VERSION = "2.6.1" # :nodoc:
VERSION = "2.8.1" # :nodoc:
attr_accessor :report, :failures, :errors, :skips # :nodoc:
attr_accessor :test_count, :assertion_count # :nodoc:
@ -978,7 +973,7 @@ module MiniTest
@passed = nil
self.setup
self.run_setup_hooks
self.__send__ self.__name__
self.run_test self.__name__
result = "." unless io?
@passed = true
rescue *PASSTHROUGH_EXCEPTIONS
@ -1000,10 +995,17 @@ module MiniTest
result
end
alias :run_test :__send__
def initialize name # :nodoc:
@__name__ = name
@__io__ = nil
@passed = nil
@@current = self
end
def self.current # :nodoc:
@@current
end
def io
@ -1095,17 +1097,17 @@ module MiniTest
# The argument can be any object that responds to #call or a block.
# That means that this call,
#
# MiniTest::TestCase.add_setup_hook { puts "foo" }
# MiniTest::Unit::TestCase.add_setup_hook { puts "foo" }
#
# ... is equivalent to:
#
# module MyTestSetup
# def call
# def self.call
# puts "foo"
# end
# end
#
# MiniTest::TestCase.add_setup_hook MyTestSetup
# MiniTest::Unit::TestCase.add_setup_hook MyTestSetup
#
# The blocks passed to +add_setup_hook+ take an optional parameter that
# will be the TestCase instance that is executing the block.
@ -1144,17 +1146,17 @@ module MiniTest
# The argument can be any object that responds to #call or a block.
# That means that this call,
#
# MiniTest::TestCase.add_teardown_hook { puts "foo" }
# MiniTest::Unit::TestCase.add_teardown_hook { puts "foo" }
#
# ... is equivalent to:
#
# module MyTestTeardown
# def call
# def self.call
# puts "foo"
# end
# end
#
# MiniTest::TestCase.add_teardown_hook MyTestTeardown
# MiniTest::Unit::TestCase.add_teardown_hook MyTestTeardown
#
# The blocks passed to +add_teardown_hook+ take an optional parameter
# that will be the TestCase instance that is executing the block.

View file

@ -147,6 +147,21 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
util_verify_bad
end
def test_verify_shows_the_actual_arguments_in_the_message
mock = MiniTest::Mock.new
mock.expect :capitalized, true, ["a"]
mock.capitalized "b"
e = assert_raises MockExpectationError do
mock.verify
end
a = {:retval=>true, :args=>["a"]}
b = {:retval=>true, :args=>["b"]}
expected = "expected capitalized, #{a.inspect}, got [#{b.inspect}]"
assert_equal expected, e.message
end
def util_verify_bad
assert_raises MockExpectationError do
@mock.verify

View file

@ -6,9 +6,7 @@
require 'stringio'
require 'pathname'
require 'minitest/unit'
MiniTest::Unit.autorun
require 'minitest/autorun'
module MyModule; end
class AnError < StandardError; include MyModule; end
@ -16,7 +14,7 @@ class ImmutableString < String; def inspect; super.freeze; end; end
class TestMiniTestUnit < MiniTest::Unit::TestCase
pwd = Pathname.new(File.expand_path(Dir.pwd))
basedir = Pathname.new(File.expand_path(MiniTest::MINI_DIR)) + 'mini'
basedir = Pathname.new(File.expand_path("lib/minitest")) + 'mini'
basedir = basedir.relative_path_from(pwd).to_s
MINITEST_BASE_DIR = basedir[/\A\./] ? basedir : "./#{basedir}"
BT_MIDDLE = ["#{MINITEST_BASE_DIR}/test.rb:161:in `each'",
@ -190,6 +188,38 @@ Finished tests in 0.00
assert_equal ex, fu
end
def test_run_test
tc = Class.new(MiniTest::Unit::TestCase) do
attr_reader :foo
def run_test name
@foo = "hi mom!"
super
@foo = "okay"
end
def test_something
assert_equal "hi mom!", foo
end
end
Object.const_set(:ATestCase, tc)
@tu.run %w[--seed 42]
expected = "Run options: --seed 42
# Running tests:
.
Finished tests in 0.00
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
"
assert_report expected
end
def test_run_error
tc = Class.new(MiniTest::Unit::TestCase) do
def test_something
@ -1210,6 +1240,18 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
assert_equal [ATestCase], MiniTest::Unit::TestCase.test_suites
end
def test_expectation
@assertion_count = 2
@tc.assert_equal true, 1.must_equal(1)
end
def test_expectation_triggered
util_assert_triggered "Expected: 2\n Actual: 1" do
1.must_equal 2
end
end
def test_flunk
util_assert_triggered 'Epic Fail!' do
@tc.flunk