mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
f34ce620a7
and SystemExitError) while loading a testcase. smell of bug. * test/testunit/collector/test_dir.rb: add new test of the LoadError. * test/drb/{test_drbssl.rb,test_drbunix.rb}: do not define testcase if openssl is not installed. * test/testunit/collector/test_dir.rb: assert_raises -> assert_raise. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
85 lines
2.5 KiB
Ruby
85 lines
2.5 KiB
Ruby
require 'test/unit/testsuite'
|
|
require 'test/unit/collector'
|
|
|
|
module Test
|
|
module Unit
|
|
module Collector
|
|
class Dir
|
|
include Collector
|
|
|
|
attr_writer :pattern
|
|
|
|
def initialize(dir=::Dir, file=::File, object_space=::ObjectSpace, req=nil)
|
|
super()
|
|
@dir = dir
|
|
@file = file
|
|
@object_space = object_space
|
|
@req = req
|
|
@pattern = /\Atest_.*\.rb\Z/m
|
|
end
|
|
|
|
def collect(*from)
|
|
if(from.empty?)
|
|
recursive_collect('.', find_test_cases)
|
|
elsif(from.size == 1)
|
|
recursive_collect(from.first, find_test_cases)
|
|
else
|
|
suites = []
|
|
from.each do |f|
|
|
suite = recursive_collect(f, find_test_cases)
|
|
suites << suite unless(suite.tests.empty?)
|
|
end
|
|
suite = TestSuite.new("[#{from.join(', ')}]")
|
|
sort(suites).each{|s| suite << s}
|
|
suite
|
|
end
|
|
end
|
|
|
|
def find_test_cases(ignore=[])
|
|
cases = []
|
|
@object_space.each_object(Class) do |c|
|
|
cases << c if(c < TestCase && !ignore.include?(c))
|
|
end
|
|
ignore.concat(cases)
|
|
cases
|
|
end
|
|
|
|
def recursive_collect(name, already_gathered)
|
|
sub_suites = []
|
|
if(@file.directory?(name))
|
|
@dir.entries(name).each do |e|
|
|
next if(e == '.' || e == '..')
|
|
e_name = @file.join(name, e)
|
|
if(@file.directory?(e_name))
|
|
sub_suite = recursive_collect(e_name, already_gathered)
|
|
sub_suites << sub_suite unless(sub_suite.empty?)
|
|
else
|
|
(next unless(@pattern =~ e)) if(@pattern)
|
|
collect_file(e_name, sub_suites, already_gathered)
|
|
end
|
|
end
|
|
else
|
|
collect_file(name, sub_suites, already_gathered)
|
|
end
|
|
suite = TestSuite.new(@file.basename(name))
|
|
sort(sub_suites).each{|s| suite << s}
|
|
suite
|
|
end
|
|
|
|
def collect_file(name, suites, already_gathered)
|
|
loadpath = $:.dup
|
|
dir = File.dirname(File.expand_path(name))
|
|
$:.unshift(dir) unless $:.first == dir
|
|
if(@req)
|
|
@req.require(name)
|
|
else
|
|
require(name)
|
|
end
|
|
find_test_cases(already_gathered).each{|t| add_suite(suites, t.suite)}
|
|
ensure
|
|
$:.replace(loadpath)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|