2003-09-18 22:48:46 -04:00
|
|
|
# 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
|
2003-10-03 00:04:26 -04:00
|
|
|
@filters = []
|
2003-09-18 22:48:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def collect(name=NAME)
|
|
|
|
suite = TestSuite.new(name)
|
2003-10-03 18:35:19 -04:00
|
|
|
sub_suites = []
|
2003-09-18 22:48:46 -04:00
|
|
|
@source.each_object(Class) do |klass|
|
2003-10-03 18:35:19 -04:00
|
|
|
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
|
2003-09-18 22:48:46 -04:00
|
|
|
end
|
2003-10-03 18:35:19 -04:00
|
|
|
sub_suites.sort_by{|s| s.name}.each{|s| suite << s}
|
2003-09-18 22:48:46 -04:00
|
|
|
suite
|
|
|
|
end
|
|
|
|
|
|
|
|
def include(test)
|
2003-10-03 00:04:26 -04:00
|
|
|
return true if(@filters.empty?)
|
2003-09-18 22:48:46 -04:00
|
|
|
@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
|