mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
51267d1177
#delete. * test/testunit/test_testsuite.rb: ditto. Also slightly refactored #test_size. * lib/test/unit/collector/objectspace.rb: collector now preserves the hierarchy of suites. * test/testunit/collector/test_objectspace.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4668 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
50 lines
1.3 KiB
Ruby
50 lines
1.3 KiB
Ruby
# Author:: Nathaniel Talbott.
|
|
# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
|
|
# License:: Ruby license.
|
|
|
|
module Test
|
|
module Unit
|
|
module Collector
|
|
class ObjectSpace
|
|
NAME = 'collected from the ObjectSpace'
|
|
|
|
def initialize(source=::ObjectSpace)
|
|
@source = source
|
|
@filters = []
|
|
end
|
|
|
|
def collect(name=NAME)
|
|
suite = TestSuite.new(name)
|
|
sub_suites = []
|
|
@source.each_object(Class) do |klass|
|
|
if(Test::Unit::TestCase > klass)
|
|
sub_suite = klass.suite
|
|
to_delete = sub_suite.tests.find_all{|t| !include(t)}
|
|
to_delete.each{|t| sub_suite.delete(t)}
|
|
sub_suites << sub_suite unless(sub_suite.size == 0)
|
|
end
|
|
end
|
|
sub_suites.sort_by{|s| s.name}.each{|s| suite << s}
|
|
suite
|
|
end
|
|
|
|
def include(test)
|
|
return true if(@filters.empty?)
|
|
@filters.each do |filter|
|
|
return true if(filter.call(test))
|
|
end
|
|
false
|
|
end
|
|
|
|
def filter=(filters)
|
|
@filters = case(filters)
|
|
when Proc
|
|
[filters]
|
|
when Array
|
|
filters
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|