2008-10-16 09:55:09 -04:00
|
|
|
# test/unit compatibility layer using minitest.
|
2008-10-10 02:15:29 -04:00
|
|
|
|
2008-10-16 09:55:09 -04:00
|
|
|
require 'minitest/unit'
|
2008-12-11 05:40:24 -05:00
|
|
|
require 'test/unit/assertions'
|
|
|
|
require 'test/unit/testcase'
|
2008-10-10 02:15:29 -04:00
|
|
|
|
2008-10-16 09:55:09 -04:00
|
|
|
module Test
|
2008-10-10 02:15:29 -04:00
|
|
|
module Unit
|
2008-10-16 09:55:09 -04:00
|
|
|
TEST_UNIT_IMPLEMENTATION = 'test/unit compatibility layer using minitest'
|
|
|
|
|
|
|
|
def self.setup_argv(original_argv=ARGV)
|
2008-10-19 11:59:35 -04:00
|
|
|
minitest_argv = []
|
|
|
|
files = []
|
2008-10-16 09:55:09 -04:00
|
|
|
reject = []
|
|
|
|
original_argv = original_argv.dup
|
|
|
|
while arg = original_argv.shift
|
|
|
|
case arg
|
|
|
|
when '-v'
|
2008-10-19 11:59:35 -04:00
|
|
|
minitest_argv << arg
|
2008-11-03 23:09:10 -05: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 09:55:09 -04:00
|
|
|
else
|
2008-10-19 11:59:35 -04:00
|
|
|
files << arg
|
2008-10-16 09:55:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-19 11:59:35 -04:00
|
|
|
if block_given?
|
|
|
|
files = yield files
|
2008-10-16 09:55:09 -04:00
|
|
|
end
|
|
|
|
|
2008-10-19 11:59:35 -04:00
|
|
|
files.map! {|f|
|
2008-12-16 08:43:34 -05:00
|
|
|
f = f.gsub(Regexp.compile(Regexp.quote(File::ALT_SEPARATOR)), File::SEPARATOR) if File::ALT_SEPARATOR
|
2008-10-19 11:59:35 -04: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 09:55:09 -04:00
|
|
|
reject_pat = Regexp.union(reject.map {|r| /#{r}/ })
|
|
|
|
files.reject! {|f| reject_pat =~ f }
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2008-10-16 09:55:09 -04:00
|
|
|
files.each {|f|
|
|
|
|
d = File.dirname(File.expand_path(f))
|
|
|
|
unless $:.include? d
|
|
|
|
$: << d
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
require f
|
|
|
|
rescue LoadError
|
2008-10-18 00:41:17 -04:00
|
|
|
puts "#{f}: #{$!}"
|
2008-10-16 09:55:09 -04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2008-10-19 11:59:35 -04:00
|
|
|
ARGV.replace minitest_argv
|
2008-10-16 09:55:09 -04:00
|
|
|
end
|
2008-10-10 02:15:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-16 09:55:09 -04:00
|
|
|
MiniTest::Unit.autorun
|