From 51267d117721b017f00493085c8e45a7d0efed05 Mon Sep 17 00:00:00 2001 From: ntalbott Date: Fri, 3 Oct 2003 22:35:19 +0000 Subject: [PATCH] * 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 --- ChangeLog | 13 ++++++++ lib/test/unit/collector/objectspace.rb | 11 +++++-- lib/test/unit/testsuite.rb | 5 ++++ test/testunit/collector/test_objectspace.rb | 24 ++++++++------- test/testunit/test_testsuite.rb | 33 ++++++++++++++------- 5 files changed, 63 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 35779411dc..07097775f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Sat Oct 4 07:33:00 2003 Nathaniel Talbott + + * 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 * ext/syck/rubyext.c: default keys handled. diff --git a/lib/test/unit/collector/objectspace.rb b/lib/test/unit/collector/objectspace.rb index ac79980d7f..5a1d29cc1a 100644 --- a/lib/test/unit/collector/objectspace.rb +++ b/lib/test/unit/collector/objectspace.rb @@ -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 diff --git a/lib/test/unit/testsuite.rb b/lib/test/unit/testsuite.rb index 4ece3257ca..b3a704ec63 100644 --- a/lib/test/unit/testsuite.rb +++ b/lib/test/unit/testsuite.rb @@ -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; diff --git a/test/testunit/collector/test_objectspace.rb b/test/testunit/collector/test_objectspace.rb index 37de5a439b..488f2e394c 100644 --- a/test/testunit/collector/test_objectspace.rb +++ b/test/testunit/collector/test_objectspace.rb @@ -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) diff --git a/test/testunit/test_testsuite.rb b/test/testunit/test_testsuite.rb index 97f639da82..5f6631d3eb 100644 --- a/test/testunit/test_testsuite.rb +++ b/test/testunit/test_testsuite.rb @@ -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