aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-30 04:14:09 +0000
committerryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-30 04:14:09 +0000
commit64e2d46fa140a88b7f6769b6fc99ba685a9cc8f7 (patch)
treeaf0e52885c4f7338801013184dc336693e80ba20 /lib
parenta42df5094dd78b883ee346cc8b48945de212aa8d (diff)
downloadruby-64e2d46fa140a88b7f6769b6fc99ba685a9cc8f7.tar.gz
Updated to 1.3.0 r4255.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/mini/test.rb86
1 files changed, 51 insertions, 35 deletions
diff --git a/lib/mini/test.rb b/lib/mini/test.rb
index 53715ef088..e19029c465 100644
--- a/lib/mini/test.rb
+++ b/lib/mini/test.rb
@@ -12,6 +12,7 @@
module Mini
class Assertion < Exception; end
+ class Skip < Assertion; end
MINI_DIR = File.expand_path("../..", __FILE__)
@@ -89,14 +90,15 @@ module Mini
end
def assert_instance_of cls, obj, msg = nil
- msg = message(msg) { "Expected #{mu_pp(obj)} to be an instance of #{cls}" }
+ msg = message(msg) { "Expected #{mu_pp(obj)} to be an instance of #{cls}, not #{obj.class}" }
flip = (Module === obj) && ! (Module === cls) # HACK for specs
obj, cls = cls, obj if flip
assert cls === obj, msg
end
def assert_kind_of cls, obj, msg = nil # TODO: merge with instance_of
- msg = message(msg) { "Expected #{mu_pp(obj)} to be a kind of #{cls}" }
+ msg = message(msg) {
+ "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
@@ -104,7 +106,7 @@ module Mini
def assert_match exp, act, msg = nil
msg = message(msg) { "Expected #{mu_pp(act)} to match #{mu_pp(exp)}" }
- assert_respond_to(act, :"=~")
+ assert_respond_to act, :"=~"
(exp = /#{exp}/) if String === exp && String === act
assert act =~ exp, msg
end
@@ -126,31 +128,36 @@ module Mini
yield
should_raise = true
rescue Exception => e
- assert_includes exp, e.class
- exception_details(e, "<#{mu_pp(exp)}> exception expected, not")
+ assert_includes(exp, e.class, exception_details(e, "<#{mu_pp(exp)}> exception expected, not"))
return e
end
exp = exp.first if exp.size == 1
- fail "#{mu_pp(exp)} expected but nothing was raised." if should_raise
+ flunk "#{mu_pp(exp)} expected but nothing was raised." if should_raise
end
def assert_respond_to obj, meth, msg = nil
- msg = message(msg) { "Expected #{mu_pp(obj)} to respond to #{meth}" }
+ msg = message(msg) {
+ "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
end
def assert_same exp, act, msg = nil
- msg = message(msg) { "Expected #{mu_pp(act)} to be the same as #{mu_pp(exp)}" }
+ msg = message(msg) {
+ data = [mu_pp(act), act.object_id, mu_pp(exp), exp.object_id]
+ "Expected %s (0x%x) to be the same as %s (0x%x)" % data
+ }
assert exp.equal?(act), msg
end
- def assert_send send_ary, msg = nil
+ def assert_send send_ary, m = nil
recv, msg, *args = send_ary
- msg = message(msg) { "Expected ##{msg} on #{mu_pp(recv)} to return true" }
- assert recv.__send__(msg, *args), msg
+ m = message(m) {
+ "Expected #{mu_pp(recv)}.#{msg}(*#{mu_pp(args)}) to return true" }
+ assert recv.__send__(msg, *args), m
end
def assert_throws sym, msg = nil
@@ -189,13 +196,11 @@ module Mini
"#{msg}\nClass: <#{e.class}>\nMessage: <#{e.message.inspect}>\n---Backtrace---\n#{Mini::filter_backtrace(e.backtrace).join("\n")}\n---------------"
end
- def fail msg = nil
+ def flunk msg = nil
msg ||= "Epic Fail!"
assert false, msg
end
- alias :flunk :fail
-
def message msg = nil, &default
proc {
if msg then
@@ -286,12 +291,18 @@ module Mini
msg = message(msg) { "Expected #{mu_pp(act)} to not be the same as #{mu_pp(exp)}" }
refute exp.equal?(act), msg
end
+
+ def skip msg = nil
+ msg ||= "Skipped, no message given"
+ raise Mini::Skip, msg
+ end
end
class Test
VERSION = "1.3.0"
- attr_reader :report, :failures, :errors
+ attr_accessor :report, :failures, :errors, :skips
+ attr_accessor :test_count, :assertion_count
@@installed_at_exit ||= false
@@out = $stdout
@@ -299,7 +310,7 @@ module Mini
def self.autorun
at_exit {
exit_code = Mini::Test.new.run(ARGV)
- exit exit_code if exit_code
+ exit false if exit_code
} unless @@installed_at_exit
@@installed_at_exit = true
end
@@ -308,34 +319,39 @@ module Mini
@@out = stream
end
+ def location e
+ e.backtrace.find { |s|
+ s !~ /in .(assert|refute|flunk|pass|fail|raise)/
+ }.sub(/:in .*$/, '')
+ end
+
def puke klass, meth, e
- if Mini::Assertion === e then
- @failures += 1
-
- loc = e.backtrace.find { |s| s !~ /in .(assert|refute|flunk|pass|fail|raise)/ }
- loc.sub!(/:in .*$/, '')
-
- @report << "Failure:\n#{meth}(#{klass}) [#{loc}]:\n#{e.message}\n"
- 'F'
- else
- @errors += 1
- bt = Mini::filter_backtrace(e.backtrace).join("\n ")
- e = "Error:\n#{meth}(#{klass}):\n#{e.class}: #{e.message}\n #{bt}\n"
- @report << e
- 'E'
- end
+ e = case e
+ when Mini::Skip then
+ @skips += 1
+ "Skipped:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
+ when Mini::Assertion then
+ @failures += 1
+ "Failure:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
+ else
+ @errors += 1
+ bt = Mini::filter_backtrace(e.backtrace).join("\n ")
+ "Error:\n#{meth}(#{klass}):\n#{e.class}: #{e.message}\n #{bt}\n"
+ end
+ @report << e
+ e[0, 1]
end
def initialize
@report = []
- @errors = @failures = 0
+ @errors = @failures = @skips = 0
@verbose = false
end
##
# Top level driver, controls all output and filtering.
- def run args
+ def run args = []
@verbose = args.delete('-v')
filter = if args.first =~ /^(-n|--name)$/ then
@@ -360,8 +376,8 @@ module Mini
@@out.puts
- format = "%d tests, %d assertions, %d failures, %d errors"
- @@out.puts format % [@test_count, @assertion_count, failures, errors]
+ format = "%d tests, %d assertions, %d failures, %d errors, %d skips"
+ @@out.puts format % [test_count, assertion_count, failures, errors, skips]
return failures + errors if @test_count > 0 # or return nil...
end