mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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:
parent
df0e9dbe97
commit
51267d1177
5 changed files with 63 additions and 23 deletions
13
ChangeLog
13
ChangeLog
|
@ -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>
|
Sat Oct 4 04:48:49 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net>
|
||||||
|
|
||||||
* ext/syck/rubyext.c: default keys handled.
|
* ext/syck/rubyext.c: default keys handled.
|
||||||
|
|
|
@ -15,11 +15,16 @@ module Test
|
||||||
|
|
||||||
def collect(name=NAME)
|
def collect(name=NAME)
|
||||||
suite = TestSuite.new(name)
|
suite = TestSuite.new(name)
|
||||||
tests = []
|
sub_suites = []
|
||||||
@source.each_object(Class) do |klass|
|
@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
|
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
|
suite
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,11 @@ module Test
|
||||||
# Adds the test to the suite.
|
# Adds the test to the suite.
|
||||||
def <<(test)
|
def <<(test)
|
||||||
@tests << test
|
@tests << test
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete(test)
|
||||||
|
@tests.delete(test)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Retuns the rolled up number of tests in this suite;
|
# Retuns the rolled up number of tests in this suite;
|
||||||
|
|
|
@ -11,6 +11,9 @@ module Test
|
||||||
class TC_ObjectSpace < TestCase
|
class TC_ObjectSpace < TestCase
|
||||||
def setup
|
def setup
|
||||||
@tc1 = Class.new(TestCase) do
|
@tc1 = Class.new(TestCase) do
|
||||||
|
def self.name
|
||||||
|
"tc_1"
|
||||||
|
end
|
||||||
def test_1
|
def test_1
|
||||||
end
|
end
|
||||||
def test_2
|
def test_2
|
||||||
|
@ -18,6 +21,9 @@ module Test
|
||||||
end
|
end
|
||||||
|
|
||||||
@tc2 = Class.new(TestCase) do
|
@tc2 = Class.new(TestCase) do
|
||||||
|
def self.name
|
||||||
|
"tc_2"
|
||||||
|
end
|
||||||
def test_0
|
def test_0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -35,9 +41,8 @@ module Test
|
||||||
|
|
||||||
def test_basic_collection
|
def test_basic_collection
|
||||||
expected = TestSuite.new("name")
|
expected = TestSuite.new("name")
|
||||||
expected << @tc2.new('test_0')
|
expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1') << @tc1.new('test_2'))
|
||||||
expected << @tc1.new('test_1')
|
expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
|
||||||
expected << @tc1.new('test_2')
|
|
||||||
assert_equal(expected, ObjectSpace.new(@object_space).collect("name"))
|
assert_equal(expected, ObjectSpace.new(@object_space).collect("name"))
|
||||||
|
|
||||||
c = ObjectSpace.new(@object_space)
|
c = ObjectSpace.new(@object_space)
|
||||||
|
@ -52,23 +57,22 @@ module Test
|
||||||
assert_equal(expected, collector.collect)
|
assert_equal(expected, collector.collect)
|
||||||
|
|
||||||
expected = TestSuite.new(ObjectSpace::NAME)
|
expected = TestSuite.new(ObjectSpace::NAME)
|
||||||
expected << @tc2.new('test_0')
|
expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1') << @tc1.new('test_2'))
|
||||||
expected << @tc1.new('test_1')
|
expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
|
||||||
expected << @tc1.new('test_2')
|
|
||||||
collector = ObjectSpace.new(@object_space)
|
collector = ObjectSpace.new(@object_space)
|
||||||
collector.filter = proc{|test| true}
|
collector.filter = proc{|test| true}
|
||||||
assert_equal(expected, collector.collect)
|
assert_equal(expected, collector.collect)
|
||||||
|
|
||||||
expected = TestSuite.new(ObjectSpace::NAME)
|
expected = TestSuite.new(ObjectSpace::NAME)
|
||||||
expected << @tc2.new('test_0')
|
expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1'))
|
||||||
expected << @tc1.new('test_1')
|
expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
|
||||||
collector = ObjectSpace.new(@object_space)
|
collector = ObjectSpace.new(@object_space)
|
||||||
collector.filter = proc{|test| ['test_1', 'test_0'].include?(test.method_name)}
|
collector.filter = proc{|test| ['test_1', 'test_0'].include?(test.method_name)}
|
||||||
assert_equal(expected, collector.collect)
|
assert_equal(expected, collector.collect)
|
||||||
|
|
||||||
expected = TestSuite.new(ObjectSpace::NAME)
|
expected = TestSuite.new(ObjectSpace::NAME)
|
||||||
expected << @tc2.new('test_0')
|
expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1'))
|
||||||
expected << @tc1.new('test_1')
|
expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
|
||||||
collector = ObjectSpace.new(@object_space)
|
collector = ObjectSpace.new(@object_space)
|
||||||
collector.filter = [proc{|test| test.method_name == 'test_1'}, proc{|test| test.method_name == 'test_0'}]
|
collector.filter = [proc{|test| test.method_name == 'test_1'}, proc{|test| test.method_name == 'test_0'}]
|
||||||
assert_equal(expected, collector.collect)
|
assert_equal(expected, collector.collect)
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
|
# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
|
||||||
# License:: Ruby license.
|
# License:: Ruby license.
|
||||||
|
|
||||||
require 'test/unit/testcase'
|
require 'test/unit'
|
||||||
require 'test/unit/testsuite'
|
|
||||||
|
|
||||||
module Test
|
module Test
|
||||||
module Unit
|
module Unit
|
||||||
|
@ -28,15 +27,29 @@ module Test
|
||||||
end
|
end
|
||||||
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
|
def test_size
|
||||||
assert_block("The count should be correct") do
|
suite = TestSuite.new
|
||||||
suite = TestSuite.new
|
suite2 = TestSuite.new
|
||||||
suite2 = TestSuite.new
|
suite2 << self.class.new("test_size")
|
||||||
suite2 << self.class.new("test_size")
|
suite << suite2
|
||||||
suite << suite2
|
suite << self.class.new("test_size")
|
||||||
suite << self.class.new("test_size")
|
assert_equal(2, suite.size, "The count should be correct")
|
||||||
suite.size == 2
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_run
|
def test_run
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue