2008-10-16 13:55:09 +00:00
|
|
|
# test/unit compatibility layer using minitest.
|
2008-10-10 06:15:29 +00:00
|
|
|
|
2008-10-16 13:55:09 +00:00
|
|
|
require 'minitest/unit'
|
2008-12-11 10:40:24 +00:00
|
|
|
require 'test/unit/assertions'
|
|
|
|
require 'test/unit/testcase'
|
2008-10-10 06:15:29 +00:00
|
|
|
|
2008-10-16 13:55:09 +00:00
|
|
|
module Test
|
2008-10-10 06:15:29 +00:00
|
|
|
module Unit
|
2008-10-16 13:55:09 +00:00
|
|
|
TEST_UNIT_IMPLEMENTATION = 'test/unit compatibility layer using minitest'
|
|
|
|
|
|
|
|
def self.setup_argv(original_argv=ARGV)
|
2008-10-19 15:59:35 +00:00
|
|
|
minitest_argv = []
|
|
|
|
files = []
|
2008-10-16 13:55:09 +00:00
|
|
|
reject = []
|
|
|
|
original_argv = original_argv.dup
|
|
|
|
while arg = original_argv.shift
|
|
|
|
case arg
|
|
|
|
when '-v'
|
2008-10-19 15:59:35 +00:00
|
|
|
minitest_argv << arg
|
2008-11-04 04:09:10 +00:00
|
|
|
when /\A(-n)(.+)?/, /\A(--name)=?\b(.+)?/
|
|
|
|
minitest_argv << $1
|
|
|
|
minitest_argv << ($2 || original_argv.shift)
|
|
|
|
when /\A-x(.+)?/
|
|
|
|
reject << ($1 || original_argv.shift)
|
2008-10-16 13:55:09 +00:00
|
|
|
else
|
2008-10-19 15:59:35 +00:00
|
|
|
files << arg
|
2008-10-16 13:55:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-19 15:59:35 +00:00
|
|
|
if block_given?
|
|
|
|
files = yield files
|
2008-10-16 13:55:09 +00:00
|
|
|
end
|
|
|
|
|
2008-10-19 15:59:35 +00:00
|
|
|
files.map! {|f|
|
2008-12-16 13:43:34 +00:00
|
|
|
f = f.gsub(Regexp.compile(Regexp.quote(File::ALT_SEPARATOR)), File::SEPARATOR) if File::ALT_SEPARATOR
|
2008-10-19 15:59:35 +00:00
|
|
|
if File.directory? f
|
|
|
|
Dir["#{f}/**/test_*.rb"]
|
|
|
|
elsif File.file? f
|
|
|
|
f
|
|
|
|
else
|
|
|
|
raise ArgumentError, "file not found: #{f}"
|
|
|
|
end
|
|
|
|
}
|
|
|
|
files.flatten!
|
|
|
|
|
2008-10-16 13:55:09 +00:00
|
|
|
reject_pat = Regexp.union(reject.map {|r| /#{r}/ })
|
|
|
|
files.reject! {|f| reject_pat =~ f }
|
|
|
|
|
|
|
|
files.each {|f|
|
|
|
|
d = File.dirname(File.expand_path(f))
|
|
|
|
unless $:.include? d
|
|
|
|
$: << d
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
require f
|
|
|
|
rescue LoadError
|
2008-10-18 04:41:17 +00:00
|
|
|
puts "#{f}: #{$!}"
|
2008-10-16 13:55:09 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2008-10-19 15:59:35 +00:00
|
|
|
ARGV.replace minitest_argv
|
2008-10-16 13:55:09 +00:00
|
|
|
end
|
2008-10-10 06:15:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-16 13:55:09 +00:00
|
|
|
MiniTest::Unit.autorun
|