* 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
This commit is contained in:
ntalbott 2003-10-03 22:35:19 +00:00
Родитель df0e9dbe97
Коммит 51267d1177
5 изменённых файлов: 63 добавлений и 23 удалений

Просмотреть файл

@ -1,3 +1,16 @@
Sat Oct 4 07:33:00 2003 Nathaniel Talbott <ntalbott@ruby-lang.org>
* 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.
Sat Oct 4 04:48:49 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net>
* ext/syck/rubyext.c: default keys handled.

Просмотреть файл

@ -15,11 +15,16 @@ module Test
def collect(name=NAME)
suite = TestSuite.new(name)
tests = []
sub_suites = []
@source.each_object(Class) do |klass|
tests.concat(klass.suite.tests) if(Test::Unit::TestCase > 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
tests.sort_by{|t| t.name}.each{|test| suite << test if(include(test))}
sub_suites.sort_by{|s| s.name}.each{|s| suite << s}
suite
end

Просмотреть файл

@ -39,6 +39,11 @@ module Test
# Adds the test to the suite.
def <<(test)
@tests << test
self
end
def delete(test)
@tests.delete(test)
end
# Retuns the rolled up number of tests in this suite;

Просмотреть файл

@ -11,6 +11,9 @@ module Test
class TC_ObjectSpace < TestCase
def setup
@tc1 = Class.new(TestCase) do
def self.name
"tc_1"
end
def test_1
end
def test_2
@ -18,6 +21,9 @@ module Test
end
@tc2 = Class.new(TestCase) do
def self.name
"tc_2"
end
def test_0
end
end
@ -35,9 +41,8 @@ module Test
def test_basic_collection
expected = TestSuite.new("name")
expected << @tc2.new('test_0')
expected << @tc1.new('test_1')
expected << @tc1.new('test_2')
expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1') << @tc1.new('test_2'))
expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
assert_equal(expected, ObjectSpace.new(@object_space).collect("name"))
c = ObjectSpace.new(@object_space)
@ -52,23 +57,22 @@ module Test
assert_equal(expected, collector.collect)
expected = TestSuite.new(ObjectSpace::NAME)
expected << @tc2.new('test_0')
expected << @tc1.new('test_1')
expected << @tc1.new('test_2')
expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1') << @tc1.new('test_2'))
expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
collector = ObjectSpace.new(@object_space)
collector.filter = proc{|test| true}
assert_equal(expected, collector.collect)
expected = TestSuite.new(ObjectSpace::NAME)
expected << @tc2.new('test_0')
expected << @tc1.new('test_1')
expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1'))
expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
collector = ObjectSpace.new(@object_space)
collector.filter = proc{|test| ['test_1', 'test_0'].include?(test.method_name)}
assert_equal(expected, collector.collect)
expected = TestSuite.new(ObjectSpace::NAME)
expected << @tc2.new('test_0')
expected << @tc1.new('test_1')
expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1'))
expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
collector = ObjectSpace.new(@object_space)
collector.filter = [proc{|test| test.method_name == 'test_1'}, proc{|test| test.method_name == 'test_0'}]
assert_equal(expected, collector.collect)

Просмотреть файл

@ -2,8 +2,7 @@
# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
# License:: Ruby license.
require 'test/unit/testcase'
require 'test/unit/testsuite'
require 'test/unit'
module Test
module Unit
@ -28,15 +27,29 @@ module Test
end
end
def test_add
s = TestSuite.new
assert_equal(s, s << self.class.new("test_add"))
end
def test_delete
s = TestSuite.new
t1 = self.class.new("test_delete")
s << t1
t2 = self.class.new("test_add")
s << t2
assert_equal(t1, s.delete(t1))
assert_nil(s.delete(t1))
assert_equal(TestSuite.new << t2, s)
end
def test_size
assert_block("The count should be correct") do
suite = TestSuite.new
suite2 = TestSuite.new
suite2 << self.class.new("test_size")
suite << suite2
suite << self.class.new("test_size")
suite.size == 2
end
suite = TestSuite.new
suite2 = TestSuite.new
suite2 << self.class.new("test_size")
suite << suite2
suite << self.class.new("test_size")
assert_equal(2, suite.size, "The count should be correct")
end
def test_run