diff options
author | ntalbott <ntalbott@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-09-19 02:48:46 +0000 |
---|---|---|
committer | ntalbott <ntalbott@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-09-19 02:48:46 +0000 |
commit | 65fe176ea49b3094c8d5aa031cd8016de1c9d134 (patch) | |
tree | 715b07f7eccd87ad19acb59d51494d85b759fb66 /test/testunit/test_testsuite.rb | |
parent | 50cd24f1cf4c859b8a602f1cf44baf636b775326 (diff) |
* test/testunit/*: Added.
* lib/test/unit.rb: Documentation update.
* lib/test/unit/ui/console/testrunner.rb (TestRunner#initialize):
Ditto.
* lib/test/unit.rb: Factored out an ObjectSpace collector.
* lib/test/unit/collector/objectspace.rb: Ditto.
* sample/testunit/*: Added.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/testunit/test_testsuite.rb')
-rw-r--r-- | test/testunit/test_testsuite.rb | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/test/testunit/test_testsuite.rb b/test/testunit/test_testsuite.rb new file mode 100644 index 0000000000..97f639da82 --- /dev/null +++ b/test/testunit/test_testsuite.rb @@ -0,0 +1,116 @@ +# Author:: Nathaniel Talbott. +# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. +# License:: Ruby license. + +require 'test/unit/testcase' +require 'test/unit/testsuite' + +module Test + module Unit + class TC_TestSuite < TestCase + def setup + @testcase1 = Class.new(TestCase) do + def test_succeed1 + assert_block { true } + end + def test_fail + assert_block { false } + end + end + + @testcase2 = Class.new(TestCase) do + def test_succeed2 + assert_block { true } + end + def test_error + raise + end + end + 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 + end + + def test_run + progress = [] + suite = @testcase1.suite + result = TestResult.new + suite.run(result) { |*values| progress << values } + + assert_equal(2, result.run_count, "Should have had four test runs") + assert_equal(1, result.failure_count, "Should have had one test failure") + assert_equal(0, result.error_count, "Should have had one test error") + assert_equal([[TestSuite::STARTED, suite.name], + [TestCase::STARTED, "test_fail(#{suite.name})"], + [TestCase::FINISHED, "test_fail(#{suite.name})"], + [TestCase::STARTED, "test_succeed1(#{suite.name})"], + [TestCase::FINISHED, "test_succeed1(#{suite.name})"], + [TestSuite::FINISHED, suite.name]], + progress, "Should have had the correct progress") + + suite = TestSuite.new + suite << @testcase1.suite + suite << @testcase2.suite + result = TestResult.new + progress = [] + suite.run(result) { |*values| progress << values } + + assert_equal(4, result.run_count, "Should have had four test runs") + assert_equal(1, result.failure_count, "Should have had one test failure") + assert_equal(1, result.error_count, "Should have had one test error") + assert_equal(14, progress.size, "Should have had the correct number of progress calls") + end + + def test_empty? + assert(TestSuite.new.empty?, "A new test suite should be empty?") + assert(!@testcase2.suite.empty?, "A test suite with tests should not be empty") + end + + def test_equality + suite1 = TestSuite.new + suite2 = TestSuite.new + assert_equal(suite1, suite2) + assert_equal(suite2, suite1) + + suite1 = TestSuite.new('name') + assert_not_equal(suite1, suite2) + assert_not_equal(suite2, suite1) + + suite2 = TestSuite.new('name') + assert_equal(suite1, suite2) + assert_equal(suite2, suite1) + + suite1 << 'test' + assert_not_equal(suite1, suite2) + assert_not_equal(suite2, suite1) + + suite2 << 'test' + assert_equal(suite1, suite2) + assert_equal(suite2, suite1) + + suite2 = Object.new + class << suite2 + def name + 'name' + end + def tests + ['test'] + end + end + assert_not_equal(suite1, suite2) + assert_not_equal(suite2, suite1) + + assert_not_equal(suite1, Object.new) + assert_not_equal(Object.new, suite1) + end + end + end +end |