mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/test/unit.rb (Test::Unit.setup_argv): call given block for
filtering files. * test/runner.rb: search srcdir/test/arg, srcdir/arg. * bin/testrb: show usage if no files given. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
295c75cb7c
commit
8fe3d0285f
4 changed files with 57 additions and 20 deletions
|
@ -1,3 +1,12 @@
|
|||
Mon Oct 20 00:57:04 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* lib/test/unit.rb (Test::Unit.setup_argv): call given block for
|
||||
filtering files.
|
||||
|
||||
* test/runner.rb: search srcdir/test/arg, srcdir/arg.
|
||||
|
||||
* bin/testrb: show usage if no files given.
|
||||
|
||||
Sun Oct 19 21:19:16 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* common.mk (srcs): removed ID_H_TARGET.
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
#!/usr/bin/env ruby
|
||||
require 'test/unit'
|
||||
Test::Unit.setup_argv
|
||||
Test::Unit.setup_argv {|files|
|
||||
if files.empty?
|
||||
puts "Usage: testrb [options] tests..."
|
||||
exit 1
|
||||
end
|
||||
files
|
||||
}
|
||||
|
|
|
@ -8,35 +8,39 @@ module Test
|
|||
TEST_UNIT_IMPLEMENTATION = 'test/unit compatibility layer using minitest'
|
||||
|
||||
def self.setup_argv(original_argv=ARGV)
|
||||
argv = []
|
||||
files = nil
|
||||
minitest_argv = []
|
||||
files = []
|
||||
reject = []
|
||||
original_argv = original_argv.dup
|
||||
while arg = original_argv.shift
|
||||
case arg
|
||||
when '-v'
|
||||
argv << '-v'
|
||||
minitest_argv << '-v'
|
||||
when '-n', '--name'
|
||||
argv << arg
|
||||
argv << original_argv.shift
|
||||
minitest_argv << arg
|
||||
minitest_argv << original_argv.shift
|
||||
when '-x'
|
||||
reject << original_argv.shift
|
||||
else
|
||||
files ||= []
|
||||
if File.directory? arg
|
||||
files.concat Dir["#{arg}/**/test_*.rb"]
|
||||
elsif File.file? arg
|
||||
files << arg
|
||||
else
|
||||
raise ArgumentError, "file not found: #{arg}"
|
||||
end
|
||||
files << arg
|
||||
end
|
||||
end
|
||||
|
||||
if files == nil
|
||||
files = Dir["test/**/test_*.rb"]
|
||||
if block_given?
|
||||
files = yield files
|
||||
end
|
||||
|
||||
files.map! {|f|
|
||||
if File.directory? f
|
||||
Dir["#{f}/**/test_*.rb"]
|
||||
elsif File.file? f
|
||||
f
|
||||
else
|
||||
raise ArgumentError, "file not found: #{f}"
|
||||
end
|
||||
}
|
||||
files.flatten!
|
||||
|
||||
reject_pat = Regexp.union(reject.map {|r| /#{r}/ })
|
||||
files.reject! {|f| reject_pat =~ f }
|
||||
|
||||
|
@ -52,9 +56,7 @@ module Test
|
|||
end
|
||||
}
|
||||
|
||||
argv.concat files
|
||||
|
||||
ARGV.replace argv
|
||||
ARGV.replace minitest_argv
|
||||
end
|
||||
|
||||
module Assertions
|
||||
|
|
|
@ -2,4 +2,24 @@ require 'rbconfig'
|
|||
exit if CROSS_COMPILING
|
||||
|
||||
require 'test/unit'
|
||||
Test::Unit.setup_argv
|
||||
|
||||
src_testdir = File.dirname(File.expand_path(__FILE__))
|
||||
srcdir = File.dirname(src_testdir)
|
||||
|
||||
Test::Unit.setup_argv {|files|
|
||||
if files.empty?
|
||||
[src_testdir]
|
||||
else
|
||||
files.map {|f|
|
||||
if File.exist? f
|
||||
f
|
||||
elsif File.exist? "#{src_testdir}/#{f}"
|
||||
"#{src_testdir}/#{f}"
|
||||
elsif File.exist? "#{srcdir}/#{f}"
|
||||
"#{srcdir}/#{f}"
|
||||
else
|
||||
raise ArgumentError, "not found: #{f}"
|
||||
end
|
||||
}
|
||||
end
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue