mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/test/: [DOC] Document Test::Unit, hide most submodules and
classes from rdoc. Since lib/test is only present as a compatibility layer with the legacy test suite many test/unit users will be using minitest or the test/unit gem instead. It is recommended to use one of these alternatives for writing new tests. This patch was based on a patch submitted by Steve Klabnik. [ruby-core:56694] [Bug #8778] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2572a9bf83
commit
b8ef79884b
5 changed files with 50 additions and 26 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
Tue Aug 20 02:32:52 2013 Zachary Scott <e@zzak.io>
|
||||||
|
|
||||||
|
* lib/test/: [DOC] Document Test::Unit, hide most submodules and
|
||||||
|
classes from rdoc. Since lib/test is only present as a compatibility
|
||||||
|
layer with the legacy test suite many test/unit users will be using
|
||||||
|
minitest or the test/unit gem instead. It is recommended to use one
|
||||||
|
of these alternatives for writing new tests.
|
||||||
|
|
||||||
|
This patch was based on a patch submitted by Steve Klabnik.
|
||||||
|
[ruby-core:56694] [Bug #8778]
|
||||||
|
|
||||||
Tue Aug 20 02:10:19 2013 Zachary Scott <e@zzak.io>
|
Tue Aug 20 02:10:19 2013 Zachary Scott <e@zzak.io>
|
||||||
|
|
||||||
* lib/rss/rss.rb: [DOC] Document for constants by Steve Klabnik
|
* lib/rss/rss.rb: [DOC] Document for constants by Steve Klabnik
|
||||||
|
|
|
@ -1,15 +1,21 @@
|
||||||
# test/unit compatibility layer using minitest.
|
|
||||||
|
|
||||||
require 'minitest/unit'
|
require 'minitest/unit'
|
||||||
require 'test/unit/assertions'
|
require 'test/unit/assertions'
|
||||||
require 'test/unit/testcase'
|
require 'test/unit/testcase'
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
|
|
||||||
|
# See Test::Unit
|
||||||
module Test
|
module Test
|
||||||
|
##
|
||||||
|
# Test::Unit is an implementation of the xUnit testing framework for Ruby.
|
||||||
|
#
|
||||||
|
# If you are writing new test code, please use MiniTest instead of Test::Unit.
|
||||||
|
#
|
||||||
|
# Test::Unit has been left in the standard library to support legacy test
|
||||||
|
# suites.
|
||||||
module Unit
|
module Unit
|
||||||
TEST_UNIT_IMPLEMENTATION = 'test/unit compatibility layer using minitest'
|
TEST_UNIT_IMPLEMENTATION = 'test/unit compatibility layer using minitest' # :nodoc:
|
||||||
|
|
||||||
module RunCount
|
module RunCount # :nodoc: all
|
||||||
@@run_count = 0
|
@@run_count = 0
|
||||||
|
|
||||||
def self.have_run?
|
def self.have_run?
|
||||||
|
@ -29,7 +35,7 @@ module Test
|
||||||
module_function :run_once
|
module_function :run_once
|
||||||
end
|
end
|
||||||
|
|
||||||
module Options
|
module Options # :nodoc: all
|
||||||
def initialize(*, &block)
|
def initialize(*, &block)
|
||||||
@init_hook = block
|
@init_hook = block
|
||||||
@options = nil
|
@options = nil
|
||||||
|
@ -151,7 +157,7 @@ module Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module GlobOption
|
module GlobOption # :nodoc: all
|
||||||
@@testfile_prefix = "test"
|
@@testfile_prefix = "test"
|
||||||
|
|
||||||
def setup_options(parser, options)
|
def setup_options(parser, options)
|
||||||
|
@ -197,7 +203,7 @@ module Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module LoadPathOption
|
module LoadPathOption # :nodoc: all
|
||||||
def setup_options(parser, options)
|
def setup_options(parser, options)
|
||||||
super
|
super
|
||||||
parser.on '-Idirectory', 'Add library load path' do |dirs|
|
parser.on '-Idirectory', 'Add library load path' do |dirs|
|
||||||
|
@ -206,7 +212,7 @@ module Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module GCStressOption
|
module GCStressOption # :nodoc: all
|
||||||
def setup_options(parser, options)
|
def setup_options(parser, options)
|
||||||
super
|
super
|
||||||
parser.on '--[no-]gc-stress', 'Set GC.stress as true' do |flag|
|
parser.on '--[no-]gc-stress', 'Set GC.stress as true' do |flag|
|
||||||
|
@ -232,7 +238,7 @@ module Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module RequireFiles
|
module RequireFiles # :nodoc: all
|
||||||
def non_options(files, options)
|
def non_options(files, options)
|
||||||
return false if !super
|
return false if !super
|
||||||
result = false
|
result = false
|
||||||
|
@ -252,7 +258,7 @@ module Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Runner < MiniTest::Unit
|
class Runner < MiniTest::Unit # :nodoc: all
|
||||||
include Test::Unit::Options
|
include Test::Unit::Options
|
||||||
include Test::Unit::GlobOption
|
include Test::Unit::GlobOption
|
||||||
include Test::Unit::LoadPathOption
|
include Test::Unit::LoadPathOption
|
||||||
|
@ -759,7 +765,7 @@ module Test
|
||||||
rep
|
rep
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize # :nodoc:
|
def initialize
|
||||||
super
|
super
|
||||||
@tty = $stdout.tty?
|
@tty = $stdout.tty?
|
||||||
end
|
end
|
||||||
|
@ -777,7 +783,7 @@ module Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class StatusLineOutput < Struct.new(:runner)
|
class StatusLineOutput < Struct.new(:runner) # :nodoc: all
|
||||||
def puts(*a) $stdout.puts(*a) unless a.empty? end
|
def puts(*a) $stdout.puts(*a) unless a.empty? end
|
||||||
def respond_to_missing?(*a) $stdout.respond_to?(*a) end
|
def respond_to_missing?(*a) $stdout.respond_to?(*a) end
|
||||||
def method_missing(*a, &b) $stdout.__send__(*a, &b) end
|
def method_missing(*a, &b) $stdout.__send__(*a, &b) end
|
||||||
|
@ -798,7 +804,7 @@ module Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class AutoRunner
|
class AutoRunner # :nodoc: all
|
||||||
class Runner < Test::Unit::Runner
|
class Runner < Test::Unit::Runner
|
||||||
include Test::Unit::RequireFiles
|
include Test::Unit::RequireFiles
|
||||||
end
|
end
|
||||||
|
@ -839,7 +845,7 @@ module Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ProxyError < StandardError
|
class ProxyError < StandardError # :nodoc: all
|
||||||
def initialize(ex)
|
def initialize(ex)
|
||||||
@message = ex.message
|
@message = ex.message
|
||||||
@backtrace = ex.backtrace
|
@backtrace = ex.backtrace
|
||||||
|
@ -850,7 +856,12 @@ module Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class MiniTest::Unit::TestCase
|
module MiniTest # :nodoc: all
|
||||||
|
module Unit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class MiniTest::Unit::TestCase # :nodoc: all
|
||||||
undef run_test
|
undef run_test
|
||||||
RUN_TEST_TRACE = "#{__FILE__}:#{__LINE__+3}:in `run_test'".freeze
|
RUN_TEST_TRACE = "#{__FILE__}:#{__LINE__+3}:in `run_test'".freeze
|
||||||
def run_test(name)
|
def run_test(name)
|
||||||
|
|
|
@ -358,7 +358,7 @@ EOT
|
||||||
template.gsub(/\G((?:[^\\]|\\.)*?)(\\)?\?/) { $1 + ($2 ? "?" : mu_pp(arguments.shift)) }
|
template.gsub(/\G((?:[^\\]|\\.)*?)(\\)?\?/) { $1 + ($2 ? "?" : mu_pp(arguments.shift)) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def message(msg = nil, *args, &default)
|
def message(msg = nil, *args, &default) # :nodoc:
|
||||||
if Proc === msg
|
if Proc === msg
|
||||||
super(nil, *args) do
|
super(nil, *args) do
|
||||||
[msg.call, (default.call if default)].compact.reject(&:empty?).join(".\n")
|
[msg.call, (default.call if default)].compact.reject(&:empty?).join(".\n")
|
||||||
|
|
|
@ -2,7 +2,7 @@ require 'test/unit'
|
||||||
|
|
||||||
module Test
|
module Test
|
||||||
module Unit
|
module Unit
|
||||||
class Worker < Runner
|
class Worker < Runner # :nodoc:
|
||||||
class << self
|
class << self
|
||||||
undef autorun
|
undef autorun
|
||||||
end
|
end
|
||||||
|
@ -12,19 +12,19 @@ module Test
|
||||||
undef _run_suites
|
undef _run_suites
|
||||||
undef run
|
undef run
|
||||||
|
|
||||||
def increment_io(orig)
|
def increment_io(orig) # :nodoc:
|
||||||
*rest, io = 32.times.inject([orig.dup]){|ios, | ios << ios.last.dup }
|
*rest, io = 32.times.inject([orig.dup]){|ios, | ios << ios.last.dup }
|
||||||
rest.each(&:close)
|
rest.each(&:close)
|
||||||
io
|
io
|
||||||
end
|
end
|
||||||
|
|
||||||
def _run_suites(suites, type)
|
def _run_suites(suites, type) # :nodoc:
|
||||||
suites.map do |suite|
|
suites.map do |suite|
|
||||||
_run_suite(suite, type)
|
_run_suite(suite, type)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def _run_suite(suite, type)
|
def _run_suite(suite, type) # :nodoc:
|
||||||
@partial_report = []
|
@partial_report = []
|
||||||
orig_testout = MiniTest::Unit.output
|
orig_testout = MiniTest::Unit.output
|
||||||
i,o = IO.pipe
|
i,o = IO.pipe
|
||||||
|
@ -81,7 +81,7 @@ module Test
|
||||||
i.close if i && !i.closed?
|
i.close if i && !i.closed?
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(args = [])
|
def run(args = []) # :nodoc:
|
||||||
process_args args
|
process_args args
|
||||||
@@stop_auto_run = true
|
@@stop_auto_run = true
|
||||||
@opts = @options.dup
|
@opts = @options.dup
|
||||||
|
@ -149,12 +149,12 @@ module Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def _report(res, *args)
|
def _report(res, *args) # :nodoc:
|
||||||
res = "#{res} #{args.pack("m0")}" unless args.empty?
|
res = "#{res} #{args.pack("m0")}" unless args.empty?
|
||||||
@stdout.puts(res)
|
@stdout.puts(res)
|
||||||
end
|
end
|
||||||
|
|
||||||
def puke(klass, meth, e)
|
def puke(klass, meth, e) # :nodoc:
|
||||||
@partial_report << [klass.name, meth, e.is_a?(MiniTest::Assertion) ? e : ProxyError.new(e)]
|
@partial_report << [klass.name, meth, e.is_a?(MiniTest::Assertion) ? e : ProxyError.new(e)]
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
@ -165,7 +165,7 @@ end
|
||||||
if $0 == __FILE__
|
if $0 == __FILE__
|
||||||
module Test
|
module Test
|
||||||
module Unit
|
module Unit
|
||||||
class TestCase < MiniTest::Unit::TestCase
|
class TestCase < MiniTest::Unit::TestCase # :nodoc: all
|
||||||
undef on_parallel_worker?
|
undef on_parallel_worker?
|
||||||
def on_parallel_worker?
|
def on_parallel_worker?
|
||||||
true
|
true
|
||||||
|
@ -174,7 +174,9 @@ if $0 == __FILE__
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
class Gem::TestCase < MiniTest::Unit::TestCase
|
module Gem # :nodoc:
|
||||||
|
end
|
||||||
|
class Gem::TestCase < MiniTest::Unit::TestCase # :nodoc:
|
||||||
@@project_dir = File.expand_path('../../../..', __FILE__)
|
@@project_dir = File.expand_path('../../../..', __FILE__)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Test
|
||||||
# remove silly TestCase class
|
# remove silly TestCase class
|
||||||
remove_const(:TestCase) if defined?(self::TestCase)
|
remove_const(:TestCase) if defined?(self::TestCase)
|
||||||
|
|
||||||
class TestCase < MiniTest::Unit::TestCase
|
class TestCase < MiniTest::Unit::TestCase # :nodoc: all
|
||||||
include Assertions
|
include Assertions
|
||||||
|
|
||||||
def on_parallel_worker?
|
def on_parallel_worker?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue