summaryrefslogtreecommitdiff
path: root/lib/minitest
diff options
context:
space:
mode:
authorryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-17 23:02:16 +0000
committerryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-17 23:02:16 +0000
commitd6c86e631d030202f23b096a1659a495c0263c5a (patch)
tree641a37967f2626dc06001793266d4de29531a5d2 /lib/minitest
parent6b43a55611a8139a288e2550e933f84f80155245 (diff)
Imported minitest 2.8.1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/minitest')
-rw-r--r--lib/minitest/README.txt4
-rw-r--r--lib/minitest/benchmark.rb28
-rw-r--r--lib/minitest/mock.rb2
-rw-r--r--lib/minitest/pride.rb2
-rw-r--r--lib/minitest/spec.rb11
-rw-r--r--lib/minitest/unit.rb62
6 files changed, 50 insertions, 59 deletions
diff --git a/lib/minitest/README.txt b/lib/minitest/README.txt
index f55f7d9710..25c4dae1a9 100644
--- a/lib/minitest/README.txt
+++ b/lib/minitest/README.txt
@@ -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
diff --git a/lib/minitest/benchmark.rb b/lib/minitest/benchmark.rb
index 77c0afafb7..c6faa50770 100644
--- a/lib/minitest/benchmark.rb
+++ b/lib/minitest/benchmark.rb
@@ -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
diff --git a/lib/minitest/mock.rb b/lib/minitest/mock.rb
index f46eb15a27..0d86bfb847 100644
--- a/lib/minitest/mock.rb
+++ b/lib/minitest/mock.rb
@@ -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
diff --git a/lib/minitest/pride.rb b/lib/minitest/pride.rb
index ac7745695c..9cf16fdffa 100644
--- a/lib/minitest/pride.rb
+++ b/lib/minitest/pride.rb
@@ -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)
diff --git a/lib/minitest/spec.rb b/lib/minitest/spec.rb
index c6b6777acf..ac28b24c4a 100644
--- a/lib/minitest/spec.rb
+++ b/lib/minitest/spec.rb
@@ -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
diff --git a/lib/minitest/unit.rb b/lib/minitest/unit.rb
index 593708d4c9..07a92f22e8 100644
--- a/lib/minitest/unit.rb
+++ b/lib/minitest/unit.rb
@@ -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.