mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test/unit.rb: split Test::Unit
* test/lib/test/unit.rb (Test::Unit): split the large class into each modules. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3977fd332f
commit
42bb2c712e
2 changed files with 108 additions and 8 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sun Jan 4 22:32:09 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* test/lib/test/unit.rb (Test::Unit): split the large class into
|
||||||
|
each modules.
|
||||||
|
|
||||||
Sun Jan 4 21:32:52 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sun Jan 4 21:32:52 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* parse.y (f_label): return tLABEL value as it is.
|
* parse.y (f_label): return tLABEL value as it is.
|
||||||
|
|
|
@ -61,24 +61,29 @@ module Test
|
||||||
orig_args -= args
|
orig_args -= args
|
||||||
args = @init_hook.call(args, options) if @init_hook
|
args = @init_hook.call(args, options) if @init_hook
|
||||||
non_options(args, options)
|
non_options(args, options)
|
||||||
|
@run_options = orig_args
|
||||||
@help = orig_args.map { |s| s =~ /[\s|&<>$()]/ ? s.inspect : s }.join " "
|
@help = orig_args.map { |s| s =~ /[\s|&<>$()]/ ? s.inspect : s }.join " "
|
||||||
@options = options
|
@options = options
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Parallel # :nodoc: all
|
||||||
|
def process_args(args = [])
|
||||||
|
return @options if @options
|
||||||
|
options = super
|
||||||
if @options[:parallel]
|
if @options[:parallel]
|
||||||
@files = args
|
@files = args
|
||||||
@args = orig_args
|
|
||||||
end
|
end
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Options # :nodoc: all
|
||||||
private
|
private
|
||||||
def setup_options(opts, options)
|
def setup_options(opts, options)
|
||||||
opts.separator 'minitest options:'
|
opts.separator 'minitest options:'
|
||||||
opts.version = MiniTest::Unit::VERSION
|
opts.version = MiniTest::Unit::VERSION
|
||||||
|
|
||||||
options[:retry] = true
|
|
||||||
options[:job_status] = nil
|
|
||||||
options[:hide_skip] = true
|
|
||||||
|
|
||||||
opts.on '-h', '--help', 'Display this help.' do
|
opts.on '-h', '--help', 'Display this help.' do
|
||||||
puts opts
|
puts opts
|
||||||
exit
|
exit
|
||||||
|
@ -96,11 +101,45 @@ module Test
|
||||||
opts.on '-n', '--name PATTERN', "Filter test method names on pattern: /REGEXP/ or STRING" do |a|
|
opts.on '-n', '--name PATTERN', "Filter test method names on pattern: /REGEXP/ or STRING" do |a|
|
||||||
options[:filter] = a
|
options[:filter] = a
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def non_options(files, options)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Skipping # :nodoc: all
|
||||||
|
end
|
||||||
|
|
||||||
|
module Colorize # :nodoc: all
|
||||||
|
end
|
||||||
|
|
||||||
|
module StatusLine # :nodoc: all
|
||||||
|
prepend Colorize
|
||||||
|
|
||||||
|
private
|
||||||
|
def setup_options(opts, options)
|
||||||
|
super
|
||||||
|
|
||||||
|
opts.separator "status line options:"
|
||||||
|
|
||||||
|
options[:job_status] = nil
|
||||||
|
|
||||||
opts.on '--jobs-status [TYPE]', [:normal, :replace],
|
opts.on '--jobs-status [TYPE]', [:normal, :replace],
|
||||||
"Show status of jobs every file; Disabled when --jobs isn't specified." do |type|
|
"Show status of jobs every file; Disabled when --jobs isn't specified." do |type|
|
||||||
options[:job_status] = type || :normal
|
options[:job_status] = type || :normal
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Parallel # :nodoc: all
|
||||||
|
private
|
||||||
|
def setup_options(opts, options)
|
||||||
|
super
|
||||||
|
|
||||||
|
opts.separator "parallel test options:"
|
||||||
|
|
||||||
|
options[:retry] = true
|
||||||
|
|
||||||
opts.on '-j N', '--jobs N', "Allow run tests with N jobs at once" do |a|
|
opts.on '-j N', '--jobs N', "Allow run tests with N jobs at once" do |a|
|
||||||
if /^t/ =~ a
|
if /^t/ =~ a
|
||||||
|
@ -127,6 +166,17 @@ module Test
|
||||||
opts.on '--ruby VAL', "Path to ruby; It'll have used at -j option" do |a|
|
opts.on '--ruby VAL', "Path to ruby; It'll have used at -j option" do |a|
|
||||||
options[:ruby] = a.split(/ /).reject(&:empty?)
|
options[:ruby] = a.split(/ /).reject(&:empty?)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Skipping # :nodoc: all
|
||||||
|
private
|
||||||
|
def setup_options(opts, options)
|
||||||
|
super
|
||||||
|
|
||||||
|
opts.separator "skipping options:"
|
||||||
|
|
||||||
|
options[:hide_skip] = true
|
||||||
|
|
||||||
opts.on '-q', '--hide-skip', 'Hide skipped tests' do
|
opts.on '-q', '--hide-skip', 'Hide skipped tests' do
|
||||||
options[:hide_skip] = true
|
options[:hide_skip] = true
|
||||||
|
@ -135,6 +185,13 @@ module Test
|
||||||
opts.on '--show-skip', 'Show skipped tests' do
|
opts.on '--show-skip', 'Show skipped tests' do
|
||||||
options[:hide_skip] = false
|
options[:hide_skip] = false
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Colorize # :nodoc: all
|
||||||
|
private
|
||||||
|
def setup_options(opts, options)
|
||||||
|
super
|
||||||
|
|
||||||
opts.on '--color[=WHEN]',
|
opts.on '--color[=WHEN]',
|
||||||
[:always, :never, :auto],
|
[:always, :never, :auto],
|
||||||
|
@ -148,7 +205,9 @@ module Test
|
||||||
@tty = c != :no
|
@tty = c != :no
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module LoadPathOption # :nodoc: all
|
||||||
def non_options(files, options)
|
def non_options(files, options)
|
||||||
begin
|
begin
|
||||||
require "rbconfig"
|
require "rbconfig"
|
||||||
|
@ -159,7 +218,7 @@ module Test
|
||||||
options[:ruby] ||= [RbConfig.ruby]
|
options[:ruby] ||= [RbConfig.ruby]
|
||||||
end
|
end
|
||||||
|
|
||||||
true
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -168,6 +227,7 @@ module Test
|
||||||
|
|
||||||
def setup_options(parser, options)
|
def setup_options(parser, options)
|
||||||
super
|
super
|
||||||
|
parser.separator "globbing options:"
|
||||||
parser.on '-b', '--basedir=DIR', 'Base directory of test suites.' do |dir|
|
parser.on '-b', '--basedir=DIR', 'Base directory of test suites.' do |dir|
|
||||||
options[:base_directory] = dir
|
options[:base_directory] = dir
|
||||||
end
|
end
|
||||||
|
@ -179,7 +239,7 @@ module Test
|
||||||
def non_options(files, options)
|
def non_options(files, options)
|
||||||
paths = [options.delete(:base_directory), nil].uniq
|
paths = [options.delete(:base_directory), nil].uniq
|
||||||
if reject = options.delete(:reject)
|
if reject = options.delete(:reject)
|
||||||
reject_pat = Regexp.union(reject.map {|r| /#{r}/ })
|
reject_pat = Regexp.union(reject.map {|r| %r"#{r}"})
|
||||||
end
|
end
|
||||||
files.map! {|f|
|
files.map! {|f|
|
||||||
f = f.tr(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
f = f.tr(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
||||||
|
@ -212,6 +272,7 @@ module Test
|
||||||
module LoadPathOption # :nodoc: all
|
module LoadPathOption # :nodoc: all
|
||||||
def setup_options(parser, options)
|
def setup_options(parser, options)
|
||||||
super
|
super
|
||||||
|
parser.separator "load path options:"
|
||||||
parser.on '-Idirectory', 'Add library load path' do |dirs|
|
parser.on '-Idirectory', 'Add library load path' do |dirs|
|
||||||
dirs.split(':').each { |d| $LOAD_PATH.unshift d }
|
dirs.split(':').each { |d| $LOAD_PATH.unshift d }
|
||||||
end
|
end
|
||||||
|
@ -221,6 +282,7 @@ module Test
|
||||||
module GCStressOption # :nodoc: all
|
module GCStressOption # :nodoc: all
|
||||||
def setup_options(parser, options)
|
def setup_options(parser, options)
|
||||||
super
|
super
|
||||||
|
parser.separator "GC options:"
|
||||||
parser.on '--[no-]gc-stress', 'Set GC.stress as true' do |flag|
|
parser.on '--[no-]gc-stress', 'Set GC.stress as true' do |flag|
|
||||||
options[:gc_stress] = flag
|
options[:gc_stress] = flag
|
||||||
end
|
end
|
||||||
|
@ -269,11 +331,16 @@ module Test
|
||||||
|
|
||||||
class Runner < MiniTest::Unit # :nodoc: all
|
class Runner < MiniTest::Unit # :nodoc: all
|
||||||
include Test::Unit::Options
|
include Test::Unit::Options
|
||||||
|
include Test::Unit::StatusLine
|
||||||
|
include Test::Unit::Parallel
|
||||||
|
include Test::Unit::Skipping
|
||||||
include Test::Unit::GlobOption
|
include Test::Unit::GlobOption
|
||||||
include Test::Unit::LoadPathOption
|
include Test::Unit::LoadPathOption
|
||||||
include Test::Unit::GCStressOption
|
include Test::Unit::GCStressOption
|
||||||
include Test::Unit::RunCount
|
include Test::Unit::RunCount
|
||||||
|
end
|
||||||
|
|
||||||
|
module Parallel # :nodoc: all
|
||||||
class Worker
|
class Worker
|
||||||
def self.launch(ruby,args=[])
|
def self.launch(ruby,args=[])
|
||||||
io = IO.popen([*ruby,
|
io = IO.popen([*ruby,
|
||||||
|
@ -371,7 +438,9 @@ module Test
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Runner < MiniTest::Unit # :nodoc: all
|
||||||
class << self; undef autorun; end
|
class << self; undef autorun; end
|
||||||
|
|
||||||
@@stop_auto_run = false
|
@@stop_auto_run = false
|
||||||
|
@ -383,7 +452,9 @@ module Test
|
||||||
} unless @@installed_at_exit
|
} unless @@installed_at_exit
|
||||||
@@installed_at_exit = true
|
@@installed_at_exit = true
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Parallel # :nodoc: all
|
||||||
def after_worker_down(worker, e=nil, c=false)
|
def after_worker_down(worker, e=nil, c=false)
|
||||||
return unless @options[:parallel]
|
return unless @options[:parallel]
|
||||||
return if @interrupt
|
return if @interrupt
|
||||||
|
@ -397,7 +468,9 @@ module Test
|
||||||
STDERR.flush
|
STDERR.flush
|
||||||
exit c
|
exit c
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module StatusLine # :nodoc: all
|
||||||
def terminal_width
|
def terminal_width
|
||||||
unless @terminal_width ||= nil
|
unless @terminal_width ||= nil
|
||||||
begin
|
begin
|
||||||
|
@ -460,7 +533,9 @@ module Test
|
||||||
return unless @options[:job_status] == :replace && @status_line_size.nonzero?
|
return unless @options[:job_status] == :replace && @status_line_size.nonzero?
|
||||||
del_status_line
|
del_status_line
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Parallel # :nodoc: all
|
||||||
def after_worker_quit(worker)
|
def after_worker_quit(worker)
|
||||||
return unless @options[:parallel]
|
return unless @options[:parallel]
|
||||||
return if @interrupt
|
return if @interrupt
|
||||||
|
@ -471,7 +546,7 @@ module Test
|
||||||
|
|
||||||
def launch_worker
|
def launch_worker
|
||||||
begin
|
begin
|
||||||
worker = Worker.launch(@options[:ruby],@args)
|
worker = Worker.launch(@options[:ruby], @run_options)
|
||||||
rescue => e
|
rescue => e
|
||||||
abort "ERROR: Failed to launch job process - #{e.class}: #{e.message}"
|
abort "ERROR: Failed to launch job process - #{e.class}: #{e.message}"
|
||||||
end
|
end
|
||||||
|
@ -687,14 +762,26 @@ module Test
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Skipping # :nodoc: all
|
||||||
|
private
|
||||||
|
def _run_suites(suites, type)
|
||||||
|
result = super
|
||||||
report.reject!{|r| r.start_with? "Skipped:" } if @options[:hide_skip]
|
report.reject!{|r| r.start_with? "Skipped:" } if @options[:hide_skip]
|
||||||
report.sort_by!{|r| r.start_with?("Skipped:") ? 0 : \
|
report.sort_by!{|r| r.start_with?("Skipped:") ? 0 : \
|
||||||
(r.start_with?("Failure:") ? 1 : 2) }
|
(r.start_with?("Failure:") ? 1 : 2) }
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Runner < MiniTest::Unit # :nodoc: all
|
||||||
alias mini_run_suite _run_suite
|
alias mini_run_suite _run_suite
|
||||||
|
end
|
||||||
|
|
||||||
|
module StatusLine # :nodoc: all
|
||||||
def output
|
def output
|
||||||
(@output ||= nil) || super
|
(@output ||= nil) || super
|
||||||
end
|
end
|
||||||
|
@ -770,7 +857,9 @@ module Test
|
||||||
end
|
end
|
||||||
report.clear
|
report.clear
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Runner < MiniTest::Unit # :nodoc: all
|
||||||
# Overriding of MiniTest::Unit#puke
|
# Overriding of MiniTest::Unit#puke
|
||||||
def puke klass, meth, e
|
def puke klass, meth, e
|
||||||
# TODO:
|
# TODO:
|
||||||
|
@ -784,18 +873,24 @@ module Test
|
||||||
end
|
end
|
||||||
rep
|
rep
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module StatusLine # :nodoc: all
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
@tty = $stdout.tty?
|
@tty = $stdout.tty?
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Parallel # :nodoc: all
|
||||||
def status(*args)
|
def status(*args)
|
||||||
result = super
|
result = super
|
||||||
raise @interrupt if @interrupt
|
raise @interrupt if @interrupt
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module StatusLine # :nodoc: all
|
||||||
def run(*args)
|
def run(*args)
|
||||||
result = super
|
result = super
|
||||||
puts "\nruby -v: #{RUBY_DESCRIPTION}"
|
puts "\nruby -v: #{RUBY_DESCRIPTION}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue