ruby-changes:17273
From: nobu <ko1@a...>
Date: Thu, 16 Sep 2010 21:40:47 +0900 (JST)
Subject: [ruby-changes:17273] Ruby:r29274 (trunk): * lib/test/unit.rb (Test::Unit::GlobOption): merged RejectOption.
nobu 2010-09-16 21:40:40 +0900 (Thu, 16 Sep 2010) New Revision: 29274 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29274 Log: * lib/test/unit.rb (Test::Unit::GlobOption): merged RejectOption. * test/runner.rb: utilize GlobOption. Modified files: trunk/ChangeLog trunk/lib/test/unit.rb trunk/test/runner.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 29273) +++ ChangeLog (revision 29274) @@ -1,3 +1,9 @@ +Thu Sep 16 21:40:37 2010 Nobuyoshi Nakada <nobu@r...> + + * lib/test/unit.rb (Test::Unit::GlobOption): merged RejectOption. + + * test/runner.rb: utilize GlobOption. + Thu Sep 16 21:31:24 2010 Nobuyoshi Nakada <nobu@r...> * lib/rdoc/ri/driver.rb (RDoc::RI::Driver.setup_options) Index: lib/test/unit.rb =================================================================== --- lib/test/unit.rb (revision 29273) +++ lib/test/unit.rb (revision 29274) @@ -87,25 +87,6 @@ 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 @@ 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 @@ 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 Index: test/runner.rb =================================================================== --- test/runner.rb (revision 29273) +++ test/runner.rb (revision 29274) @@ -6,21 +6,12 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/