Imported minitest 3.3.0 (r7676)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ba661182a4
commit
17dde49326
@ -1,3 +1,8 @@
|
|||||||
|
Tue Aug 21 09:32:41 2012 Ryan Davis <ryand-ruby@zenspider.com>
|
||||||
|
|
||||||
|
* lib/minitest/*: Imported minitest 3.3.0 (r7676)
|
||||||
|
* test/minitest/*: ditto
|
||||||
|
|
||||||
Tue Aug 21 09:05:32 2012 NAKAMURA Usaku <usa@ruby-lang.org>
|
Tue Aug 21 09:05:32 2012 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* test/testunit/tests_for_parallel/ptest_forth.rb: added a test case
|
* test/testunit/tests_for_parallel/ptest_forth.rb: added a test case
|
||||||
|
@ -57,7 +57,7 @@ module MiniTest
|
|||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def __call name, data
|
def __call name, data # :nodoc:
|
||||||
case data
|
case data
|
||||||
when Hash then
|
when Hash then
|
||||||
"#{name}(#{data[:args].inspect[1..-2]}) => #{data[:retval].inspect}"
|
"#{name}(#{data[:args].inspect[1..-2]}) => #{data[:retval].inspect}"
|
||||||
|
@ -162,10 +162,11 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
|||||||
#
|
#
|
||||||
# Equivalent to MiniTest::Unit::TestCase#setup.
|
# Equivalent to MiniTest::Unit::TestCase#setup.
|
||||||
|
|
||||||
def self.before type = :each, &block
|
def self.before type = nil, &block
|
||||||
raise "unsupported before type: #{type}" unless type == :each
|
define_method :setup do
|
||||||
|
super()
|
||||||
add_setup_hook {|tc| tc.instance_eval(&block) }
|
self.instance_eval(&block)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -175,10 +176,11 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
|||||||
#
|
#
|
||||||
# Equivalent to MiniTest::Unit::TestCase#teardown.
|
# Equivalent to MiniTest::Unit::TestCase#teardown.
|
||||||
|
|
||||||
def self.after type = :each, &block
|
def self.after type = nil, &block
|
||||||
raise "unsupported after type: #{type}" unless type == :each
|
define_method :teardown do
|
||||||
|
self.instance_eval(&block)
|
||||||
add_teardown_hook {|tc| tc.instance_eval(&block) }
|
super()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -247,14 +249,6 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
# :stopdoc:
|
# :stopdoc:
|
||||||
def after_setup
|
|
||||||
run_setup_hooks
|
|
||||||
end
|
|
||||||
|
|
||||||
def before_teardown
|
|
||||||
run_teardown_hooks
|
|
||||||
end
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
attr_reader :desc
|
attr_reader :desc
|
||||||
alias :specify :it
|
alias :specify :it
|
||||||
@ -290,11 +284,11 @@ module MiniTest::Expectations
|
|||||||
#
|
#
|
||||||
# n.must_be_close_to m [, delta]
|
# n.must_be_close_to m [, delta]
|
||||||
#
|
#
|
||||||
# :method: must_be_within_delta
|
# :method: must_be_close_to
|
||||||
|
|
||||||
infect_an_assertion :assert_in_delta, :must_be_close_to
|
infect_an_assertion :assert_in_delta, :must_be_close_to
|
||||||
|
|
||||||
alias :must_be_within_delta :must_be_close_to
|
alias :must_be_within_delta :must_be_close_to # :nodoc:
|
||||||
|
|
||||||
##
|
##
|
||||||
# See MiniTest::Assertions#assert_in_epsilon
|
# See MiniTest::Assertions#assert_in_epsilon
|
||||||
@ -450,12 +444,11 @@ module MiniTest::Expectations
|
|||||||
#
|
#
|
||||||
# n.wont_be_close_to m [, delta]
|
# n.wont_be_close_to m [, delta]
|
||||||
#
|
#
|
||||||
# :method: wont_be_within_delta
|
# :method: wont_be_close_to
|
||||||
|
|
||||||
infect_an_assertion :refute_in_delta, :wont_be_within_delta
|
infect_an_assertion :refute_in_delta, :wont_be_close_to
|
||||||
|
|
||||||
alias :wont_be_close_to :wont_be_within_delta
|
alias :wont_be_within_delta :wont_be_close_to # :nodoc:
|
||||||
# FIX: reverse aliases
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# See MiniTest::Assertions#refute_in_epsilon
|
# See MiniTest::Assertions#refute_in_epsilon
|
||||||
|
@ -191,9 +191,12 @@ module MiniTest
|
|||||||
|
|
||||||
##
|
##
|
||||||
# Fails unless the block returns a true value.
|
# Fails unless the block returns a true value.
|
||||||
|
#
|
||||||
|
# NOTE: This method is deprecated, use assert. It will be removed
|
||||||
|
# on 2013-01-01."
|
||||||
|
|
||||||
def assert_block msg = nil
|
def assert_block msg = nil
|
||||||
warn "NOTE: MiniTest::Unit::TestCase#assert_block is deprecated, use assert. It will be removed on or after 2012-06-01. Called from #{caller.first}"
|
warn "NOTE: MiniTest::Unit::TestCase#assert_block is deprecated, use assert. It will be removed on 2013-01-01. Called from #{caller.first}"
|
||||||
msg = message(msg) { "Expected block to return true value" }
|
msg = message(msg) { "Expected block to return true value" }
|
||||||
assert yield, msg
|
assert yield, msg
|
||||||
end
|
end
|
||||||
@ -652,7 +655,7 @@ module MiniTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Unit # :nodoc:
|
class Unit # :nodoc:
|
||||||
VERSION = "3.2.0" # :nodoc:
|
VERSION = "3.3.0" # :nodoc:
|
||||||
|
|
||||||
attr_accessor :report, :failures, :errors, :skips # :nodoc:
|
attr_accessor :report, :failures, :errors, :skips # :nodoc:
|
||||||
attr_accessor :test_count, :assertion_count # :nodoc:
|
attr_accessor :test_count, :assertion_count # :nodoc:
|
||||||
@ -674,8 +677,8 @@ module MiniTest
|
|||||||
@@after_tests = []
|
@@after_tests = []
|
||||||
|
|
||||||
##
|
##
|
||||||
# A simple hook allowing you to run a block of code after the
|
# A simple hook allowing you to run a block of code after _all_ of
|
||||||
# tests are done. Eg:
|
# the tests are done. Eg:
|
||||||
#
|
#
|
||||||
# MiniTest::Unit.after_tests { p $debugging_info }
|
# MiniTest::Unit.after_tests { p $debugging_info }
|
||||||
|
|
||||||
@ -1025,6 +1028,143 @@ module MiniTest
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Provides before/after hooks for setup and teardown. These are
|
||||||
|
# meant for library writers, NOT for regular test authors. See
|
||||||
|
# #before_setup for an example.
|
||||||
|
|
||||||
|
module LifecycleHooks
|
||||||
|
##
|
||||||
|
# Runs before every test, after setup. This hook is meant for
|
||||||
|
# libraries to extend minitest. It is not meant to be used by
|
||||||
|
# test developers.
|
||||||
|
#
|
||||||
|
# See #before_setup for an example.
|
||||||
|
|
||||||
|
def after_setup; end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Runs before every test, before setup. This hook is meant for
|
||||||
|
# libraries to extend minitest. It is not meant to be used by
|
||||||
|
# test developers.
|
||||||
|
#
|
||||||
|
# As a simplistic example:
|
||||||
|
#
|
||||||
|
# module MyMinitestPlugin
|
||||||
|
# def before_setup
|
||||||
|
# super
|
||||||
|
# # ... stuff to do before setup is run
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# def after_setup
|
||||||
|
# # ... stuff to do after setup is run
|
||||||
|
# super
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# def before_teardown
|
||||||
|
# super
|
||||||
|
# # ... stuff to do before teardown is run
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# def after_teardown
|
||||||
|
# # ... stuff to do after teardown is run
|
||||||
|
# super
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# class MiniTest::Unit::TestCase
|
||||||
|
# include MyMinitestPlugin
|
||||||
|
# end
|
||||||
|
|
||||||
|
def before_setup; end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Runs after every test, before teardown. This hook is meant for
|
||||||
|
# libraries to extend minitest. It is not meant to be used by
|
||||||
|
# test developers.
|
||||||
|
#
|
||||||
|
# See #before_setup for an example.
|
||||||
|
|
||||||
|
def before_teardown; end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Runs after every test, after teardown. This hook is meant for
|
||||||
|
# libraries to extend minitest. It is not meant to be used by
|
||||||
|
# test developers.
|
||||||
|
#
|
||||||
|
# See #before_setup for an example.
|
||||||
|
|
||||||
|
def after_teardown; end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Deprecated # :nodoc:
|
||||||
|
|
||||||
|
##
|
||||||
|
# This entire module is deprecated and slated for removal on 2013-01-01.
|
||||||
|
|
||||||
|
module Hooks
|
||||||
|
##
|
||||||
|
# Adds a block of code that will be executed before every
|
||||||
|
# TestCase is run.
|
||||||
|
#
|
||||||
|
# NOTE: This method is deprecated, use before/after_setup. It
|
||||||
|
# will be removed on 2013-01-01.
|
||||||
|
|
||||||
|
def self.add_setup_hook arg=nil, &block
|
||||||
|
warn "NOTE: MiniTest::Unit::TestCase.add_setup_hook is deprecated, use before/after_setup via a module (and call super!). It will be removed on 2013-01-01. Called from #{caller.first}"
|
||||||
|
hook = arg || block
|
||||||
|
@setup_hooks << hook
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.setup_hooks # :nodoc:
|
||||||
|
if superclass.respond_to? :setup_hooks then
|
||||||
|
superclass.setup_hooks
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end + @setup_hooks
|
||||||
|
end
|
||||||
|
|
||||||
|
def run_setup_hooks # :nodoc:
|
||||||
|
_run_hooks self.class.setup_hooks
|
||||||
|
end
|
||||||
|
|
||||||
|
def _run_hooks hooks # :nodoc:
|
||||||
|
hooks.each do |hook|
|
||||||
|
if hook.respond_to?(:arity) && hook.arity == 1
|
||||||
|
hook.call(self)
|
||||||
|
else
|
||||||
|
hook.call
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Adds a block of code that will be executed after every
|
||||||
|
# TestCase is run.
|
||||||
|
#
|
||||||
|
# NOTE: This method is deprecated, use before/after_teardown. It
|
||||||
|
# will be removed on 2013-01-01.
|
||||||
|
|
||||||
|
def self.add_teardown_hook arg=nil, &block
|
||||||
|
warn "NOTE: MiniTest::Unit::TestCase#add_teardown_hook is deprecated, use before/after_teardown. It will be removed on 2013-01-01. Called from #{caller.first}"
|
||||||
|
hook = arg || block
|
||||||
|
@teardown_hooks << hook
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.teardown_hooks # :nodoc:
|
||||||
|
if superclass.respond_to? :teardown_hooks then
|
||||||
|
superclass.teardown_hooks
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end + @teardown_hooks
|
||||||
|
end
|
||||||
|
|
||||||
|
def run_teardown_hooks # :nodoc:
|
||||||
|
_run_hooks self.class.teardown_hooks.reverse
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Subclass TestCase to create your own tests. Typically you'll want a
|
# Subclass TestCase to create your own tests. Typically you'll want a
|
||||||
# TestCase subclass per implementation class.
|
# TestCase subclass per implementation class.
|
||||||
@ -1032,6 +1172,8 @@ module MiniTest
|
|||||||
# See MiniTest::Assertions
|
# See MiniTest::Assertions
|
||||||
|
|
||||||
class TestCase
|
class TestCase
|
||||||
|
include LifecycleHooks
|
||||||
|
include Deprecated::Hooks
|
||||||
include Guard
|
include Guard
|
||||||
extend Guard
|
extend Guard
|
||||||
|
|
||||||
@ -1077,6 +1219,7 @@ module MiniTest
|
|||||||
rescue *PASSTHROUGH_EXCEPTIONS
|
rescue *PASSTHROUGH_EXCEPTIONS
|
||||||
raise
|
raise
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
@passed = false
|
||||||
result = runner.puke self.class, self.__name__, e
|
result = runner.puke self.class, self.__name__, e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1167,148 +1310,31 @@ module MiniTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Runs before every test. Use this to refactor test initialization.
|
# Runs before every test. Use this to set up before each test
|
||||||
|
# run.
|
||||||
|
|
||||||
def setup; end
|
def setup; end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Runs before every test after setup. Use this to refactor test
|
# Runs after every test. Use this to clean up after each test
|
||||||
# initialization.
|
# run.
|
||||||
|
|
||||||
def after_setup; end
|
|
||||||
|
|
||||||
##
|
|
||||||
# Runs before every setup. Use this to refactor test initialization.
|
|
||||||
|
|
||||||
def before_setup; end
|
|
||||||
|
|
||||||
##
|
|
||||||
# Runs after every test. Use this to refactor test cleanup.
|
|
||||||
|
|
||||||
def teardown; end
|
def teardown; end
|
||||||
|
|
||||||
##
|
|
||||||
# Runs after every test before teardown. Use this to refactor test
|
|
||||||
# initialization.
|
|
||||||
|
|
||||||
def before_teardown; end
|
|
||||||
|
|
||||||
##
|
|
||||||
# Runs after every teardown. Use this to refactor test cleanup.
|
|
||||||
|
|
||||||
def after_teardown; end
|
|
||||||
|
|
||||||
def self.reset_setup_teardown_hooks # :nodoc:
|
def self.reset_setup_teardown_hooks # :nodoc:
|
||||||
|
# also deprecated... believe it.
|
||||||
@setup_hooks = []
|
@setup_hooks = []
|
||||||
@teardown_hooks = []
|
@teardown_hooks = []
|
||||||
end
|
end
|
||||||
|
|
||||||
reset_setup_teardown_hooks
|
reset_setup_teardown_hooks
|
||||||
|
|
||||||
##
|
|
||||||
# Adds a block of code that will be executed before every TestCase is
|
|
||||||
# run. Equivalent to +setup+, but usable multiple times and without
|
|
||||||
# re-opening any classes.
|
|
||||||
#
|
|
||||||
# All of the setup hooks will run in order after the +setup+ method, if
|
|
||||||
# one is defined.
|
|
||||||
#
|
|
||||||
# The argument can be any object that responds to #call or a block.
|
|
||||||
# That means that this call,
|
|
||||||
#
|
|
||||||
# MiniTest::Unit::TestCase.add_setup_hook { puts "foo" }
|
|
||||||
#
|
|
||||||
# ... is equivalent to:
|
|
||||||
#
|
|
||||||
# module MyTestSetup
|
|
||||||
# def self.call
|
|
||||||
# puts "foo"
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
def self.add_setup_hook arg=nil, &block
|
|
||||||
hook = arg || block
|
|
||||||
@setup_hooks << hook
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.setup_hooks # :nodoc:
|
|
||||||
if superclass.respond_to? :setup_hooks then
|
|
||||||
superclass.setup_hooks
|
|
||||||
else
|
|
||||||
[]
|
|
||||||
end + @setup_hooks
|
|
||||||
end
|
|
||||||
|
|
||||||
def run_setup_hooks # :nodoc:
|
|
||||||
self.class.setup_hooks.each do |hook|
|
|
||||||
if hook.respond_to?(:arity) && hook.arity == 1
|
|
||||||
hook.call(self)
|
|
||||||
else
|
|
||||||
hook.call
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
##
|
|
||||||
# Adds a block of code that will be executed after every TestCase is
|
|
||||||
# run. Equivalent to +teardown+, but usable multiple times and without
|
|
||||||
# re-opening any classes.
|
|
||||||
#
|
|
||||||
# All of the teardown hooks will run in reverse order after the
|
|
||||||
# +teardown+ method, if one is defined.
|
|
||||||
#
|
|
||||||
# The argument can be any object that responds to #call or a block.
|
|
||||||
# That means that this call,
|
|
||||||
#
|
|
||||||
# MiniTest::Unit::TestCase.add_teardown_hook { puts "foo" }
|
|
||||||
#
|
|
||||||
# ... is equivalent to:
|
|
||||||
#
|
|
||||||
# module MyTestTeardown
|
|
||||||
# def self.call
|
|
||||||
# puts "foo"
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
def self.add_teardown_hook arg=nil, &block
|
|
||||||
hook = arg || block
|
|
||||||
@teardown_hooks << hook
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.teardown_hooks # :nodoc:
|
|
||||||
if superclass.respond_to? :teardown_hooks then
|
|
||||||
superclass.teardown_hooks
|
|
||||||
else
|
|
||||||
[]
|
|
||||||
end + @teardown_hooks
|
|
||||||
end
|
|
||||||
|
|
||||||
def run_teardown_hooks # :nodoc:
|
|
||||||
self.class.teardown_hooks.reverse.each do |hook|
|
|
||||||
if hook.respond_to?(:arity) && hook.arity == 1
|
|
||||||
hook.call(self)
|
|
||||||
else
|
|
||||||
hook.call
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
include MiniTest::Assertions
|
include MiniTest::Assertions
|
||||||
end # class TestCase
|
end # class TestCase
|
||||||
end # class Unit
|
end # class Unit
|
||||||
end # module MiniTest
|
end # module MiniTest
|
||||||
|
|
||||||
Minitest = MiniTest # because ugh... I typo this all the time
|
Minitest = MiniTest # :nodoc: because ugh... I typo this all the time
|
||||||
|
|
||||||
if $DEBUG then
|
if $DEBUG then
|
||||||
module Test # :nodoc:
|
module Test # :nodoc:
|
||||||
|
@ -9,25 +9,29 @@ require 'tempfile'
|
|||||||
require 'stringio'
|
require 'stringio'
|
||||||
require 'minitest/autorun'
|
require 'minitest/autorun'
|
||||||
|
|
||||||
|
class MiniTest::Unit::TestCase
|
||||||
|
def clean s
|
||||||
|
s.gsub(/^ {6}/, '')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class MetaMetaMetaTestCase < MiniTest::Unit::TestCase
|
class MetaMetaMetaTestCase < MiniTest::Unit::TestCase
|
||||||
def assert_report expected = nil
|
def assert_report expected, flags = %w[--seed 42]
|
||||||
expected ||= <<-EOM.gsub(/^ {6}/, '')
|
header = clean <<-EOM
|
||||||
Run options: --seed 42
|
Run options: #{flags.map { |s| s =~ /\|/ ? s.inspect : s }.join " "}
|
||||||
|
|
||||||
# Running tests:
|
# Running tests:
|
||||||
|
|
||||||
.
|
|
||||||
|
|
||||||
Finished tests in 0.00
|
|
||||||
|
|
||||||
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
|
|
||||||
EOM
|
EOM
|
||||||
|
|
||||||
|
@tu.run flags
|
||||||
|
|
||||||
output = @output.string.dup
|
output = @output.string.dup
|
||||||
output.sub!(/Finished tests in .*/, "Finished tests in 0.00")
|
output.sub!(/Finished tests in .*/, "Finished tests in 0.00")
|
||||||
output.sub!(/Loaded suite .*/, 'Loaded suite blah')
|
output.sub!(/Loaded suite .*/, 'Loaded suite blah')
|
||||||
|
|
||||||
output.gsub!(/ = \d+.\d\d s = /, ' = 0.00 s = ')
|
output.gsub!(/ = \d+.\d\d s = /, ' = 0.00 s = ')
|
||||||
|
output.gsub!(/0x[A-Fa-f0-9]+/, '0xXXX')
|
||||||
|
|
||||||
if windows? then
|
if windows? then
|
||||||
output.gsub!(/\[(?:[A-Za-z]:)?[^\]:]+:\d+\]/, '[FILE:LINE]')
|
output.gsub!(/\[(?:[A-Za-z]:)?[^\]:]+:\d+\]/, '[FILE:LINE]')
|
||||||
@ -37,7 +41,7 @@ class MetaMetaMetaTestCase < MiniTest::Unit::TestCase
|
|||||||
output.gsub!(/^(\s+)[^:]+:\d+:in/, '\1FILE:LINE:in')
|
output.gsub!(/^(\s+)[^:]+:\d+:in/, '\1FILE:LINE:in')
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_equal(expected, output)
|
assert_equal header + expected, output
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
|
@ -637,20 +637,20 @@ class TestMeta < MiniTest::Unit::TestCase
|
|||||||
def test_structure
|
def test_structure
|
||||||
x, y, z, * = util_structure
|
x, y, z, * = util_structure
|
||||||
|
|
||||||
assert_equal "top-level thingy", x.to_s
|
assert_equal "top-level thingy", x.to_s
|
||||||
assert_equal "top-level thingy::inner thingy", y.to_s
|
assert_equal "top-level thingy::inner thingy", y.to_s
|
||||||
assert_equal "top-level thingy::inner thingy::very inner thingy", z.to_s
|
assert_equal "top-level thingy::inner thingy::very inner thingy", z.to_s
|
||||||
|
|
||||||
assert_equal "top-level thingy", x.desc
|
assert_equal "top-level thingy", x.desc
|
||||||
assert_equal "inner thingy", y.desc
|
assert_equal "inner thingy", y.desc
|
||||||
assert_equal "very inner thingy", z.desc
|
assert_equal "very inner thingy", z.desc
|
||||||
|
|
||||||
top_methods = %w(test_0001_top-level-it)
|
top_methods = %w(setup teardown test_0001_top-level-it)
|
||||||
inner_methods1 = %w(test_0001_inner-it)
|
inner_methods1 = %w(setup teardown test_0001_inner-it)
|
||||||
inner_methods2 = inner_methods1 +
|
inner_methods2 = inner_methods1 +
|
||||||
%w(test_0002_anonymous test_0003_anonymous)
|
%w(test_0002_anonymous test_0003_anonymous)
|
||||||
|
|
||||||
assert_equal top_methods, x.instance_methods(false).sort.map(&:to_s)
|
assert_equal top_methods, x.instance_methods(false).sort.map(&:to_s)
|
||||||
assert_equal inner_methods1, y.instance_methods(false).sort.map(&:to_s)
|
assert_equal inner_methods1, y.instance_methods(false).sort.map(&:to_s)
|
||||||
assert_equal inner_methods2, z.instance_methods(false).sort.map(&:to_s)
|
assert_equal inner_methods2, z.instance_methods(false).sort.map(&:to_s)
|
||||||
end
|
end
|
||||||
@ -658,13 +658,18 @@ class TestMeta < MiniTest::Unit::TestCase
|
|||||||
def test_setup_teardown_behavior
|
def test_setup_teardown_behavior
|
||||||
_, _, z, before_list, after_list = util_structure
|
_, _, z, before_list, after_list = util_structure
|
||||||
|
|
||||||
tc = z.new(nil)
|
@tu = MiniTest::Unit.new
|
||||||
|
@output = StringIO.new("")
|
||||||
|
MiniTest::Unit.runner = nil # protect the outer runner from the inner tests
|
||||||
|
MiniTest::Unit.output = @output
|
||||||
|
|
||||||
tc.run_setup_hooks
|
tc = z.new :test_0002_anonymous
|
||||||
tc.run_teardown_hooks
|
tc.run @tu
|
||||||
|
|
||||||
assert_equal [1, 2, 3], before_list
|
assert_equal [1, 2, 3], before_list
|
||||||
assert_equal [3, 2, 1], after_list
|
assert_equal [3, 2, 1], after_list
|
||||||
|
ensure
|
||||||
|
MiniTest::Unit.output = $stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_children
|
def test_children
|
||||||
|
@ -13,8 +13,8 @@ class AnError < StandardError; include MyModule; end
|
|||||||
class ImmutableString < String; def inspect; super.freeze; end; end
|
class ImmutableString < String; def inspect; super.freeze; end; end
|
||||||
|
|
||||||
class TestMiniTestUnit < MetaMetaMetaTestCase
|
class TestMiniTestUnit < MetaMetaMetaTestCase
|
||||||
pwd = Pathname.new(File.expand_path(Dir.pwd))
|
pwd = Pathname.new File.expand_path Dir.pwd
|
||||||
basedir = Pathname.new(File.expand_path("lib/minitest")) + 'mini'
|
basedir = Pathname.new(File.expand_path "lib/minitest") + 'mini'
|
||||||
basedir = basedir.relative_path_from(pwd).to_s
|
basedir = basedir.relative_path_from(pwd).to_s
|
||||||
MINITEST_BASE_DIR = basedir[/\A\./] ? basedir : "./#{basedir}"
|
MINITEST_BASE_DIR = basedir[/\A\./] ? basedir : "./#{basedir}"
|
||||||
BT_MIDDLE = ["#{MINITEST_BASE_DIR}/test.rb:161:in `each'",
|
BT_MIDDLE = ["#{MINITEST_BASE_DIR}/test.rb:161:in `each'",
|
||||||
@ -152,12 +152,12 @@ class TestMiniTestUnit < MetaMetaMetaTestCase
|
|||||||
bt = util_expand_bt bt
|
bt = util_expand_bt bt
|
||||||
|
|
||||||
ex = ["-e:1"]
|
ex = ["-e:1"]
|
||||||
fu = MiniTest::filter_backtrace(bt)
|
fu = MiniTest::filter_backtrace bt
|
||||||
assert_equal ex, fu
|
assert_equal ex, fu
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_run_test
|
def test_run_test
|
||||||
tc = Class.new(MiniTest::Unit::TestCase) do
|
Class.new MiniTest::Unit::TestCase do
|
||||||
attr_reader :foo
|
attr_reader :foo
|
||||||
|
|
||||||
def run_test name
|
def run_test name
|
||||||
@ -171,25 +171,19 @@ class TestMiniTestUnit < MetaMetaMetaTestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Object.const_set(:ATestCase, tc)
|
expected = clean <<-EOM
|
||||||
|
.
|
||||||
|
|
||||||
@tu.run %w[--seed 42]
|
Finished tests in 0.00
|
||||||
|
|
||||||
expected = "Run options: --seed 42
|
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
|
||||||
|
EOM
|
||||||
|
|
||||||
# Running tests:
|
|
||||||
|
|
||||||
.
|
|
||||||
|
|
||||||
Finished tests in 0.00
|
|
||||||
|
|
||||||
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
|
|
||||||
"
|
|
||||||
assert_report expected
|
assert_report expected
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_run_error
|
def test_run_error
|
||||||
tc = Class.new(MiniTest::Unit::TestCase) do
|
Class.new MiniTest::Unit::TestCase do
|
||||||
def test_something
|
def test_something
|
||||||
assert true
|
assert true
|
||||||
end
|
end
|
||||||
@ -199,21 +193,13 @@ Finished tests in 0.00
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Object.const_set(:ATestCase, tc)
|
expected = clean <<-EOM
|
||||||
|
|
||||||
@tu.run %w[--seed 42]
|
|
||||||
|
|
||||||
expected = <<-EOM.gsub(/^ {6}/, '')
|
|
||||||
Run options: --seed 42
|
|
||||||
|
|
||||||
# Running tests:
|
|
||||||
|
|
||||||
E.
|
E.
|
||||||
|
|
||||||
Finished tests in 0.00
|
Finished tests in 0.00
|
||||||
|
|
||||||
1) Error:
|
1) Error:
|
||||||
test_error(ATestCase):
|
test_error(#<Class:0xXXX>):
|
||||||
RuntimeError: unhandled exception
|
RuntimeError: unhandled exception
|
||||||
FILE:LINE:in `test_error'
|
FILE:LINE:in `test_error'
|
||||||
|
|
||||||
@ -224,7 +210,7 @@ Finished tests in 0.00
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_run_error_teardown
|
def test_run_error_teardown
|
||||||
tc = Class.new(MiniTest::Unit::TestCase) do
|
Class.new MiniTest::Unit::TestCase do
|
||||||
def test_something
|
def test_something
|
||||||
assert true
|
assert true
|
||||||
end
|
end
|
||||||
@ -234,30 +220,24 @@ Finished tests in 0.00
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Object.const_set(:ATestCase, tc)
|
expected = clean <<-EOM
|
||||||
|
E
|
||||||
|
|
||||||
@tu.run %w[--seed 42]
|
Finished tests in 0.00
|
||||||
|
|
||||||
expected = "Run options: --seed 42
|
1) Error:
|
||||||
|
test_something(#<Class:0xXXX>):
|
||||||
|
RuntimeError: unhandled exception
|
||||||
|
FILE:LINE:in `teardown'
|
||||||
|
|
||||||
# Running tests:
|
1 tests, 1 assertions, 0 failures, 1 errors, 0 skips
|
||||||
|
EOM
|
||||||
|
|
||||||
E
|
|
||||||
|
|
||||||
Finished tests in 0.00
|
|
||||||
|
|
||||||
1) Error:
|
|
||||||
test_something(ATestCase):
|
|
||||||
RuntimeError: unhandled exception
|
|
||||||
FILE:LINE:in `teardown'
|
|
||||||
|
|
||||||
1 tests, 1 assertions, 0 failures, 1 errors, 0 skips
|
|
||||||
"
|
|
||||||
assert_report expected
|
assert_report expected
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_run_failing
|
def test_run_failing
|
||||||
tc = Class.new(MiniTest::Unit::TestCase) do
|
Class.new MiniTest::Unit::TestCase do
|
||||||
def test_something
|
def test_something
|
||||||
assert true
|
assert true
|
||||||
end
|
end
|
||||||
@ -267,29 +247,23 @@ RuntimeError: unhandled exception
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Object.const_set(:ATestCase, tc)
|
expected = clean <<-EOM
|
||||||
|
F.
|
||||||
|
|
||||||
@tu.run %w[--seed 42]
|
Finished tests in 0.00
|
||||||
|
|
||||||
expected = "Run options: --seed 42
|
1) Failure:
|
||||||
|
test_failure(#<Class:0xXXX>) [FILE:LINE]:
|
||||||
|
Failed assertion, no message given.
|
||||||
|
|
||||||
# Running tests:
|
2 tests, 2 assertions, 1 failures, 0 errors, 0 skips
|
||||||
|
EOM
|
||||||
|
|
||||||
F.
|
|
||||||
|
|
||||||
Finished tests in 0.00
|
|
||||||
|
|
||||||
1) Failure:
|
|
||||||
test_failure(ATestCase) [FILE:LINE]:
|
|
||||||
Failed assertion, no message given.
|
|
||||||
|
|
||||||
2 tests, 2 assertions, 1 failures, 0 errors, 0 skips
|
|
||||||
"
|
|
||||||
assert_report expected
|
assert_report expected
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_run_failing_filtered
|
def test_run_failing_filtered
|
||||||
tc = Class.new(MiniTest::Unit::TestCase) do
|
Class.new MiniTest::Unit::TestCase do
|
||||||
def test_something
|
def test_something
|
||||||
assert true
|
assert true
|
||||||
end
|
end
|
||||||
@ -299,39 +273,37 @@ Failed assertion, no message given.
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Object.const_set(:ATestCase, tc)
|
expected = clean <<-EOM
|
||||||
|
.
|
||||||
|
|
||||||
@tu.run %w[--name /some|thing/ --seed 42]
|
Finished tests in 0.00
|
||||||
|
|
||||||
expected = "Run options: --name \"/some|thing/\" --seed 42
|
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
|
||||||
|
EOM
|
||||||
|
|
||||||
# Running tests:
|
assert_report expected, %w[--name /some|thing/ --seed 42]
|
||||||
|
|
||||||
.
|
|
||||||
|
|
||||||
Finished tests in 0.00
|
|
||||||
|
|
||||||
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
|
|
||||||
"
|
|
||||||
assert_report expected
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_run_passing
|
def test_run_passing
|
||||||
tc = Class.new(MiniTest::Unit::TestCase) do
|
Class.new MiniTest::Unit::TestCase do
|
||||||
def test_something
|
def test_something
|
||||||
assert true
|
assert true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Object.const_set(:ATestCase, tc)
|
expected = clean <<-EOM
|
||||||
|
.
|
||||||
|
|
||||||
@tu.run %w[--seed 42]
|
Finished tests in 0.00
|
||||||
|
|
||||||
assert_report
|
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
|
||||||
|
EOM
|
||||||
|
|
||||||
|
assert_report expected
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_run_skip
|
def test_run_skip
|
||||||
tc = Class.new(MiniTest::Unit::TestCase) do
|
Class.new MiniTest::Unit::TestCase do
|
||||||
def test_something
|
def test_something
|
||||||
assert true
|
assert true
|
||||||
end
|
end
|
||||||
@ -341,25 +313,19 @@ Finished tests in 0.00
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Object.const_set(:ATestCase, tc)
|
expected = clean <<-EOM
|
||||||
|
S.
|
||||||
|
|
||||||
@tu.run %w[--seed 42]
|
Finished tests in 0.00
|
||||||
|
|
||||||
expected = "Run options: --seed 42
|
2 tests, 1 assertions, 0 failures, 0 errors, 1 skips
|
||||||
|
EOM
|
||||||
|
|
||||||
# Running tests:
|
|
||||||
|
|
||||||
S.
|
|
||||||
|
|
||||||
Finished tests in 0.00
|
|
||||||
|
|
||||||
2 tests, 1 assertions, 0 failures, 0 errors, 1 skips
|
|
||||||
"
|
|
||||||
assert_report expected
|
assert_report expected
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_run_skip_verbose
|
def test_run_skip_verbose
|
||||||
tc = Class.new(MiniTest::Unit::TestCase) do
|
Class.new MiniTest::Unit::TestCase do
|
||||||
def test_something
|
def test_something
|
||||||
assert true
|
assert true
|
||||||
end
|
end
|
||||||
@ -369,27 +335,21 @@ Finished tests in 0.00
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Object.const_set(:ATestCase, tc)
|
expected = clean <<-EOM
|
||||||
|
#<Class:0xXXX>#test_skip = 0.00 s = S
|
||||||
@tu.run %w[--seed 42 --verbose]
|
#<Class:0xXXX>#test_something = 0.00 s = .
|
||||||
|
|
||||||
expected = "Run options: --seed 42 --verbose
|
|
||||||
|
|
||||||
# Running tests:
|
|
||||||
|
|
||||||
ATestCase#test_skip = 0.00 s = S
|
|
||||||
ATestCase#test_something = 0.00 s = .
|
|
||||||
|
|
||||||
|
|
||||||
Finished tests in 0.00
|
Finished tests in 0.00
|
||||||
|
|
||||||
1) Skipped:
|
1) Skipped:
|
||||||
test_skip(ATestCase) [FILE:LINE]:
|
test_skip(#<Class:0xXXX>) [FILE:LINE]:
|
||||||
not yet
|
not yet
|
||||||
|
|
||||||
2 tests, 1 assertions, 0 failures, 0 errors, 1 skips
|
2 tests, 1 assertions, 0 failures, 0 errors, 1 skips
|
||||||
"
|
EOM
|
||||||
assert_report expected
|
|
||||||
|
assert_report expected, %w[--seed 42 --verbose]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_default_runner_is_minitest_unit
|
def test_default_runner_is_minitest_unit
|
||||||
@ -397,18 +357,15 @@ not yet
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_run_with_other_runner
|
def test_run_with_other_runner
|
||||||
|
MiniTest::Unit.runner = Class.new MiniTest::Unit do
|
||||||
runner = Class.new(MiniTest::Unit) do
|
def _run_suite suite, type
|
||||||
# Run once before each suite
|
suite.before_suite # Run once before each suite
|
||||||
def _run_suite(suite, type)
|
super suite, type
|
||||||
begin
|
|
||||||
suite.before_suite
|
|
||||||
super(suite, type)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end.new
|
||||||
|
|
||||||
tc = Class.new(MiniTest::Unit::TestCase) do
|
Class.new MiniTest::Unit::TestCase do
|
||||||
|
def self.name; "wacky!" end
|
||||||
|
|
||||||
def self.before_suite
|
def self.before_suite
|
||||||
MiniTest::Unit.output.puts "Running #{self.name} tests"
|
MiniTest::Unit.output.puts "Running #{self.name} tests"
|
||||||
@ -424,22 +381,15 @@ not yet
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Object.const_set(:ATestCase, tc)
|
expected = clean <<-EOM
|
||||||
MiniTest::Unit.runner = runner.new
|
Running wacky! tests
|
||||||
@tu.run %w[--seed 42]
|
..
|
||||||
|
|
||||||
# We should only see 'running ATestCase tests' once
|
Finished tests in 0.00
|
||||||
expected = "Run options: --seed 42
|
|
||||||
|
|
||||||
# Running tests:
|
2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
|
||||||
|
EOM
|
||||||
|
|
||||||
Running ATestCase tests
|
|
||||||
..
|
|
||||||
|
|
||||||
Finished tests in 0.00
|
|
||||||
|
|
||||||
2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
|
|
||||||
"
|
|
||||||
assert_report expected
|
assert_report expected
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -455,7 +405,6 @@ Finished tests in 0.00
|
|||||||
end
|
end
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
ensure
|
ensure
|
||||||
Class.class_eval do
|
Class.class_eval do
|
||||||
alias inherited inherited_without_hacks
|
alias inherited inherited_without_hacks
|
||||||
@ -478,7 +427,7 @@ Finished tests in 0.00
|
|||||||
|
|
||||||
def test_before_setup
|
def test_before_setup
|
||||||
call_order = []
|
call_order = []
|
||||||
Class.new(MiniTest::Unit::TestCase) do
|
Class.new MiniTest::Unit::TestCase do
|
||||||
define_method :setup do
|
define_method :setup do
|
||||||
super()
|
super()
|
||||||
call_order << :setup
|
call_order << :setup
|
||||||
@ -497,9 +446,31 @@ Finished tests in 0.00
|
|||||||
assert_equal expected, call_order
|
assert_equal expected, call_order
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_passed_eh_teardown_good
|
||||||
|
test_class = Class.new MiniTest::Unit::TestCase do
|
||||||
|
def teardown; assert true; end
|
||||||
|
def test_omg; assert true; end
|
||||||
|
end
|
||||||
|
|
||||||
|
test = test_class.new :test_omg
|
||||||
|
test.run @tu
|
||||||
|
assert test.passed?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_passed_eh_teardown_flunked
|
||||||
|
test_class = Class.new MiniTest::Unit::TestCase do
|
||||||
|
def teardown; flunk; end
|
||||||
|
def test_omg; assert true; end
|
||||||
|
end
|
||||||
|
|
||||||
|
test = test_class.new :test_omg
|
||||||
|
test.run @tu
|
||||||
|
refute test.passed?
|
||||||
|
end
|
||||||
|
|
||||||
def test_after_teardown
|
def test_after_teardown
|
||||||
call_order = []
|
call_order = []
|
||||||
Class.new(MiniTest::Unit::TestCase) do
|
Class.new MiniTest::Unit::TestCase do
|
||||||
define_method :teardown do
|
define_method :teardown do
|
||||||
super()
|
super()
|
||||||
call_order << :teardown
|
call_order << :teardown
|
||||||
@ -520,7 +491,7 @@ Finished tests in 0.00
|
|||||||
|
|
||||||
def test_all_teardowns_are_guaranteed_to_run
|
def test_all_teardowns_are_guaranteed_to_run
|
||||||
call_order = []
|
call_order = []
|
||||||
Class.new(MiniTest::Unit::TestCase) do
|
Class.new MiniTest::Unit::TestCase do
|
||||||
define_method :after_teardown do
|
define_method :after_teardown do
|
||||||
super()
|
super()
|
||||||
call_order << :after_teardown
|
call_order << :after_teardown
|
||||||
@ -548,91 +519,15 @@ Finished tests in 0.00
|
|||||||
assert_equal expected, call_order
|
assert_equal expected, call_order
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_setup_hooks
|
def test_setup_and_teardown_survive_inheritance
|
||||||
call_order = []
|
call_order = []
|
||||||
|
|
||||||
tc = Class.new(MiniTest::Spec) do
|
parent = Class.new MiniTest::Spec do
|
||||||
define_method :setup do
|
before do
|
||||||
super()
|
|
||||||
call_order << :method
|
|
||||||
end
|
|
||||||
|
|
||||||
define_method :test2 do
|
|
||||||
call_order << :test2
|
|
||||||
end
|
|
||||||
|
|
||||||
define_method :test1 do
|
|
||||||
call_order << :test1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
tc.add_setup_hook lambda { call_order << :proc }
|
|
||||||
|
|
||||||
argument = nil
|
|
||||||
|
|
||||||
tc.add_setup_hook do |arg|
|
|
||||||
argument = arg
|
|
||||||
call_order << :block
|
|
||||||
end
|
|
||||||
|
|
||||||
@tu.run %w[--seed 42]
|
|
||||||
|
|
||||||
assert_kind_of tc, argument
|
|
||||||
|
|
||||||
expected = [:method, :proc, :block, :test1,
|
|
||||||
:method, :proc, :block, :test2]
|
|
||||||
|
|
||||||
assert_equal expected, call_order
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_teardown_hooks
|
|
||||||
call_order = []
|
|
||||||
|
|
||||||
tc = Class.new(MiniTest::Spec) do
|
|
||||||
define_method :teardown do
|
|
||||||
super()
|
|
||||||
call_order << :method
|
|
||||||
end
|
|
||||||
|
|
||||||
define_method :test2 do
|
|
||||||
call_order << :test2
|
|
||||||
end
|
|
||||||
|
|
||||||
define_method :test1 do
|
|
||||||
call_order << :test1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
tc.add_teardown_hook lambda { call_order << :proc }
|
|
||||||
|
|
||||||
argument = nil
|
|
||||||
|
|
||||||
tc.add_teardown_hook do |arg|
|
|
||||||
argument = arg
|
|
||||||
call_order << :block
|
|
||||||
end
|
|
||||||
|
|
||||||
@tu.run %w[--seed 42]
|
|
||||||
|
|
||||||
assert_kind_of tc, argument
|
|
||||||
|
|
||||||
expected = [:test1, :block, :proc, :method,
|
|
||||||
:test2, :block, :proc, :method]
|
|
||||||
|
|
||||||
assert_equal expected, call_order
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_setup_and_teardown_hooks_survive_inheritance
|
|
||||||
call_order = []
|
|
||||||
|
|
||||||
parent = Class.new(MiniTest::Spec) do
|
|
||||||
define_method :setup do
|
|
||||||
super()
|
|
||||||
call_order << :setup_method
|
call_order << :setup_method
|
||||||
end
|
end
|
||||||
|
|
||||||
define_method :teardown do
|
after do
|
||||||
super()
|
|
||||||
call_order << :teardown_method
|
call_order << :teardown_method
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -641,19 +536,12 @@ Finished tests in 0.00
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
parent.add_setup_hook { call_order << :setup_hook }
|
|
||||||
parent.add_teardown_hook { call_order << :teardown_hook }
|
|
||||||
|
|
||||||
_ = Class.new parent
|
_ = Class.new parent
|
||||||
|
|
||||||
parent.add_setup_hook { call_order << :setup_after }
|
|
||||||
parent.add_teardown_hook { call_order << :teardown_after }
|
|
||||||
|
|
||||||
@tu.run %w[--seed 42]
|
@tu.run %w[--seed 42]
|
||||||
|
|
||||||
# Once for the parent class, once for the child
|
# Once for the parent class, once for the child
|
||||||
expected = [:setup_method, :setup_hook, :setup_after, :test,
|
expected = [:setup_method, :test, :teardown_method] * 2
|
||||||
:teardown_after, :teardown_hook, :teardown_method] * 2
|
|
||||||
|
|
||||||
assert_equal expected, call_order
|
assert_equal expected, call_order
|
||||||
end
|
end
|
||||||
@ -683,7 +571,6 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|||||||
def teardown
|
def teardown
|
||||||
assert_equal(@assertion_count, @tc._assertions,
|
assert_equal(@assertion_count, @tc._assertions,
|
||||||
"expected #{@assertion_count} assertions to be fired during the test, not #{@tc._assertions}") if @tc._assertions
|
"expected #{@assertion_count} assertions to be fired during the test, not #{@tc._assertions}") if @tc._assertions
|
||||||
Object.send :remove_const, :ATestCase if defined? ATestCase
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_assert
|
def test_assert
|
||||||
@ -706,7 +593,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|||||||
|
|
||||||
def test_assert_block
|
def test_assert_block
|
||||||
exp = ["NOTE: MiniTest::Unit::TestCase#assert_block is deprecated,",
|
exp = ["NOTE: MiniTest::Unit::TestCase#assert_block is deprecated,",
|
||||||
"use assert. It will be removed on or after 2012-06-01."].join " "
|
"use assert. It will be removed on 2013-01-01."].join " "
|
||||||
|
|
||||||
out, err = capture_io do
|
out, err = capture_io do
|
||||||
@tc.assert_block do
|
@tc.assert_block do
|
||||||
@ -1104,12 +991,14 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
expected = "[RuntimeError] exception expected, not
|
expected = clean <<-EOM.chomp
|
||||||
Class: <SyntaxError>
|
[RuntimeError] exception expected, not
|
||||||
Message: <\"icky\">
|
Class: <SyntaxError>
|
||||||
---Backtrace---
|
Message: <\"icky\">
|
||||||
FILE:LINE:in `test_assert_raises_triggered_different'
|
---Backtrace---
|
||||||
---------------"
|
FILE:LINE:in `test_assert_raises_triggered_different'
|
||||||
|
---------------
|
||||||
|
EOM
|
||||||
|
|
||||||
actual = e.message.gsub(/^.+:\d+/, 'FILE:LINE')
|
actual = e.message.gsub(/^.+:\d+/, 'FILE:LINE')
|
||||||
actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION >= '1.9.0'
|
actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION >= '1.9.0'
|
||||||
@ -1124,7 +1013,7 @@ FILE:LINE:in `test_assert_raises_triggered_different'
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
expected = <<-EOM.gsub(/^ {6}/, '').chomp
|
expected = clean <<-EOM
|
||||||
XXX.
|
XXX.
|
||||||
[RuntimeError] exception expected, not
|
[RuntimeError] exception expected, not
|
||||||
Class: <SyntaxError>
|
Class: <SyntaxError>
|
||||||
@ -1137,7 +1026,7 @@ FILE:LINE:in `test_assert_raises_triggered_different'
|
|||||||
actual = e.message.gsub(/^.+:\d+/, 'FILE:LINE')
|
actual = e.message.gsub(/^.+:\d+/, 'FILE:LINE')
|
||||||
actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION >= '1.9.0'
|
actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION >= '1.9.0'
|
||||||
|
|
||||||
assert_equal expected, actual
|
assert_equal expected.chomp, actual
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_assert_raises_triggered_none
|
def test_assert_raises_triggered_none
|
||||||
@ -1171,12 +1060,14 @@ FILE:LINE:in `test_assert_raises_triggered_different'
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
expected = "[StandardError] exception expected, not
|
expected = clean <<-EOM.chomp
|
||||||
Class: <AnError>
|
[StandardError] exception expected, not
|
||||||
Message: <\"AnError\">
|
Class: <AnError>
|
||||||
---Backtrace---
|
Message: <\"AnError\">
|
||||||
FILE:LINE:in `test_assert_raises_triggered_subclass'
|
---Backtrace---
|
||||||
---------------"
|
FILE:LINE:in `test_assert_raises_triggered_subclass'
|
||||||
|
---------------
|
||||||
|
EOM
|
||||||
|
|
||||||
actual = e.message.gsub(/^.+:\d+/, 'FILE:LINE')
|
actual = e.message.gsub(/^.+:\d+/, 'FILE:LINE')
|
||||||
actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION >= '1.9.0'
|
actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION >= '1.9.0'
|
||||||
@ -1255,14 +1146,14 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_assert_throws
|
def test_assert_throws
|
||||||
@tc.assert_throws(:blah) do
|
@tc.assert_throws :blah do
|
||||||
throw :blah
|
throw :blah
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_assert_throws_different
|
def test_assert_throws_different
|
||||||
util_assert_triggered 'Expected :blah to have been thrown, not :not_blah.' do
|
util_assert_triggered 'Expected :blah to have been thrown, not :not_blah.' do
|
||||||
@tc.assert_throws(:blah) do
|
@tc.assert_throws :blah do
|
||||||
throw :not_blah
|
throw :not_blah
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1270,7 +1161,7 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
|
|||||||
|
|
||||||
def test_assert_throws_unthrown
|
def test_assert_throws_unthrown
|
||||||
util_assert_triggered 'Expected :blah to have been thrown.' do
|
util_assert_triggered 'Expected :blah to have been thrown.' do
|
||||||
@tc.assert_throws(:blah) do
|
@tc.assert_throws :blah do
|
||||||
# do nothing
|
# do nothing
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1315,21 +1206,13 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
|
|||||||
assert_empty asserts.map { |n| n.sub(/^assert/, 'refute') } - refutes
|
assert_empty asserts.map { |n| n.sub(/^assert/, 'refute') } - refutes
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_inherited
|
|
||||||
@assertion_count = 0
|
|
||||||
|
|
||||||
Object.const_set(:ATestCase, Class.new(MiniTest::Unit::TestCase))
|
|
||||||
|
|
||||||
assert_equal [ATestCase], MiniTest::Unit::TestCase.test_suites
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_class_test_suites
|
def test_class_test_suites
|
||||||
@assertion_count = 0
|
@assertion_count = 0
|
||||||
|
|
||||||
Object.const_set(:ATestCase, Class.new(MiniTest::Unit::TestCase))
|
tc = Class.new(MiniTest::Unit::TestCase)
|
||||||
|
|
||||||
assert_equal 1, MiniTest::Unit::TestCase.test_suites.size
|
assert_equal 1, MiniTest::Unit::TestCase.test_suites.size
|
||||||
assert_equal [ATestCase], MiniTest::Unit::TestCase.test_suites
|
assert_equal [tc], MiniTest::Unit::TestCase.test_suites
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_expectation
|
def test_expectation
|
||||||
@ -1565,7 +1448,7 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
|
|||||||
def test_test_methods_random
|
def test_test_methods_random
|
||||||
@assertion_count = 0
|
@assertion_count = 0
|
||||||
|
|
||||||
sample_test_case = Class.new(MiniTest::Unit::TestCase) do
|
sample_test_case = Class.new MiniTest::Unit::TestCase do
|
||||||
def test_test1; assert "does not matter" end
|
def test_test1; assert "does not matter" end
|
||||||
def test_test2; assert "does not matter" end
|
def test_test2; assert "does not matter" end
|
||||||
def test_test3; assert "does not matter" end
|
def test_test3; assert "does not matter" end
|
||||||
@ -1579,7 +1462,7 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
|
|||||||
def test_test_methods_sorted
|
def test_test_methods_sorted
|
||||||
@assertion_count = 0
|
@assertion_count = 0
|
||||||
|
|
||||||
sample_test_case = Class.new(MiniTest::Unit::TestCase) do
|
sample_test_case = Class.new MiniTest::Unit::TestCase do
|
||||||
def self.test_order; :sorted end
|
def self.test_order; :sorted end
|
||||||
def test_test3; assert "does not matter" end
|
def test_test3; assert "does not matter" end
|
||||||
def test_test2; assert "does not matter" end
|
def test_test2; assert "does not matter" end
|
||||||
@ -1613,7 +1496,7 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
|
|||||||
end
|
end
|
||||||
|
|
||||||
def util_assert_triggered expected, klass = MiniTest::Assertion
|
def util_assert_triggered expected, klass = MiniTest::Assertion
|
||||||
e = assert_raises(klass) do
|
e = assert_raises klass do
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user