diff --git a/ChangeLog b/ChangeLog index 12b7adbe4a..aa633a258d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Sep 16 21:40:37 2010 Nobuyoshi Nakada + + * lib/test/unit.rb (Test::Unit::GlobOption): merged RejectOption. + + * test/runner.rb: utilize GlobOption. + Thu Sep 16 21:31:24 2010 Nobuyoshi Nakada * lib/rdoc/ri/driver.rb (RDoc::RI::Driver.setup_options) diff --git a/lib/test/unit.rb b/lib/test/unit.rb index 68fd808102..74ac201c4b 100644 --- a/lib/test/unit.rb +++ b/lib/test/unit.rb @@ -87,25 +87,6 @@ module Test module GlobOption 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) super parser.on '-x', '--exclude PATTERN' do |pattern| @@ -114,10 +95,29 @@ module Test end def non_options(files, options) + paths = [options.delete(:base_directory), nil].compact if reject = options.delete(:reject) reject_pat = Regexp.union(reject.map {|r| /#{r}/ }) - files.reject! {|f| reject_pat =~ f } 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) end end @@ -133,18 +133,12 @@ module Test end end - def self.new - Mini.new do |files, options| - if block_given? - files = yield files - end - files - end + def self.new(*args, &block) + Mini.new(*args, &block) end class Mini < MiniTest::Unit include Test::Unit::GlobOption - include Test::Unit::RejectOption include Test::Unit::LoadPathOption end end diff --git a/test/runner.rb b/test/runner.rb index 6fd02a80ae..c92cb2670f 100644 --- a/test/runner.rb +++ b/test/runner.rb @@ -6,21 +6,12 @@ require 'test/unit' src_testdir = File.dirname(File.expand_path(__FILE__)) srcdir = File.dirname(src_testdir) -tests = Test::Unit.new {|files| +tests = Test::Unit.new {|files, options| + options[:base_directory] = src_testdir if files.empty? [src_testdir] else - files.map {|f| - 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 - } + files end } exit tests.run(ARGV) || true