1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/test/unit/collector/objectspace.rb
ntalbott 51267d1177 * lib/test/unit/testsuite.rb: changed #<< to return self, and added
#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
2003-10-03 22:35:19 +00:00

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