1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/test/unit.rb (Test::Unit::GlobOption): merged RejectOption.

* test/runner.rb: utilize GlobOption.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-09-16 12:40:40 +00:00
parent 9bc2e3280a
commit 5bfac0d9cf
3 changed files with 31 additions and 40 deletions

View file

@ -1,3 +1,9 @@
Thu Sep 16 21:40:37 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/test/unit.rb (Test::Unit::GlobOption): merged RejectOption.
* test/runner.rb: utilize GlobOption.
Thu Sep 16 21:31:24 2010 Nobuyoshi Nakada <nobu@ruby-lang.org> Thu Sep 16 21:31:24 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/rdoc/ri/driver.rb (RDoc::RI::Driver.setup_options) * lib/rdoc/ri/driver.rb (RDoc::RI::Driver.setup_options)

View file

@ -87,25 +87,6 @@ module Test
module GlobOption module GlobOption
include Options include Options
def non_options(files, options)
files.map! {|f|
f = f.tr(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
if File.directory? f
Dir["#{f}/**/test_*.rb"]
elsif File.file? f
f
else
raise ArgumentError, "file not found: #{f}"
end
}
files.flatten!
super(files, options)
end
end
module RejectOption
include Options
def setup_options(parser, options) def setup_options(parser, options)
super super
parser.on '-x', '--exclude PATTERN' do |pattern| parser.on '-x', '--exclude PATTERN' do |pattern|
@ -114,10 +95,29 @@ module Test
end end
def non_options(files, options) def non_options(files, options)
paths = [options.delete(:base_directory), nil].compact
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}/ })
files.reject! {|f| reject_pat =~ f }
end 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
if !(match = Dir["#{path}/**/test_*.rb"]).empty?
if reject
match.reject! {|n|
n[(prefix.length+1)..-1] if prefix
reject_pat =~ n
}
end
break match
elsif !reject or reject_pat !~ f and File.exist? path
break path
end
end or
raise ArgumentError, "file not found: #{f}"
}
files.flatten!
super(files, options) super(files, options)
end end
end end
@ -133,18 +133,12 @@ module Test
end end
end end
def self.new def self.new(*args, &block)
Mini.new do |files, options| Mini.new(*args, &block)
if block_given?
files = yield files
end
files
end
end end
class Mini < MiniTest::Unit class Mini < MiniTest::Unit
include Test::Unit::GlobOption include Test::Unit::GlobOption
include Test::Unit::RejectOption
include Test::Unit::LoadPathOption include Test::Unit::LoadPathOption
end end
end end

View file

@ -6,21 +6,12 @@ require 'test/unit'
src_testdir = File.dirname(File.expand_path(__FILE__)) src_testdir = File.dirname(File.expand_path(__FILE__))
srcdir = File.dirname(src_testdir) srcdir = File.dirname(src_testdir)
tests = Test::Unit.new {|files| tests = Test::Unit.new {|files, options|
options[:base_directory] = src_testdir
if files.empty? if files.empty?
[src_testdir] [src_testdir]
else else
files.map {|f| files
if File.exist? "#{src_testdir}/#{f}"
"#{src_testdir}/#{f}"
elsif File.exist? "#{srcdir}/#{f}"
"#{srcdir}/#{f}"
elsif File.exist? f
f
else
raise ArgumentError, "not found: #{f}"
end
}
end end
} }
exit tests.run(ARGV) || true exit tests.run(ARGV) || true