summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-02-11 12:41:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-02-11 12:41:58 +0000
commit9c560af1b74ef031ab990ba82362192981407c42 (patch)
treeda9fc68be0d02109e1883000d0b359fe1405e3ad /lib
parent96c078c34029bbc525085c4072b7e1ebcc9ec5a3 (diff)
* bin/testrb, test/runner.rb, lib/test/unit.rb: improve backward
compatibility. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/test/unit.rb75
1 files changed, 56 insertions, 19 deletions
diff --git a/lib/test/unit.rb b/lib/test/unit.rb
index 97d0da5ca5..25ff6cc980 100644
--- a/lib/test/unit.rb
+++ b/lib/test/unit.rb
@@ -30,28 +30,32 @@ module Test
end
module Options
- def initialize(&block)
+ def initialize(*, &block)
@init_hook = block
super(&nil)
end
+ def option_parser
+ @option_parser ||= OptionParser.new
+ end
+
def process_args(args = [])
+ return @options if @options
orig_args = args.dup
options = {}
- OptionParser.new do |opts|
- setup_options(opts, options)
- opts.parse!(args)
- orig_args -= args
- end
+ opts = option_parser
+ setup_options(opts, options)
+ opts.parse!(args)
+ orig_args -= args
args = @init_hook.call(args, options) if @init_hook
- non_options(args, options)
+ non_options(args, options) or return nil
@help = orig_args.map { |s| s =~ /[\s|&<>$()]/ ? s.inspect : s }.join " "
- options
+ @options = options
end
private
def setup_options(opts, options)
- opts.banner = 'minitest options:'
+ opts.separator 'minitest options:'
opts.version = MiniTest::Unit::VERSION
opts.on '-h', '--help', 'Display this help.' do
@@ -74,6 +78,7 @@ module Test
end
def non_options(files, options)
+ true
end
end
@@ -82,6 +87,9 @@ module Test
def setup_options(parser, options)
super
+ parser.on '-b', '--basedir=DIR', 'Base directory of test suites.' do |dir|
+ options[:base_directory] = dir
+ end
parser.on '-x', '--exclude PATTERN', 'Exclude test files on pattern.' do |pattern|
(options[:reject] ||= []) << pattern
end
@@ -94,8 +102,13 @@ module Test
end
files.map! {|f|
f = f.tr(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
- [*paths, nil].any? do |prefix|
- path = prefix ? "#{prefix}/#{f}" : f
+ [*(paths if /\A\.\.?(?:\z|\/)/ !~ f), nil].uniq.any? do |prefix|
+ if prefix
+ path = f.empty? ? prefix : "#{prefix}/#{f}"
+ else
+ next if f.empty?
+ path = f
+ end
if !(match = Dir["#{path}/**/test_*.rb"]).empty?
if reject
match.reject! {|n|
@@ -154,7 +167,7 @@ module Test
module RequireFiles
def non_options(files, options)
- super
+ return false if !super or files.empty?
files.each {|f|
d = File.dirname(path = File.expand_path(f))
unless $:.include? d
@@ -169,13 +182,6 @@ module Test
end
end
- def self.new(*args, &block)
- Mini.class_eval do
- include Test::Unit::RequireFiles
- end
- Mini.new(*args, &block)
- end
-
class Mini < MiniTest::Unit
include Test::Unit::GlobOption
include Test::Unit::LoadPathOption
@@ -213,6 +219,37 @@ module Test
result
end
end
+
+ class AutoRunner
+ class Runner < Mini
+ include Test::Unit::RequireFiles
+ end
+
+ attr_accessor :to_run, :options
+
+ def initialize(force_standalone = false, default_dir = nil, argv = ARGV)
+ @runner = Runner.new do |files, options|
+ options[:base_directory] ||= default_dir
+ @to_run = files
+ yield self if block_given?
+ files
+ end
+ @options = @runner.option_parser
+ @argv = argv
+ end
+
+ def process_args(*args)
+ @runner.process_args(*args)
+ end
+
+ def run
+ @runner.run(@argv) || true
+ end
+
+ def self.run(*args)
+ new(*args).run
+ end
+ end
end
end