[cairo-commit] rcairo/test-unit/test run-test.rb, NONE, 1.1 test_assertions.rb, NONE, 1.1 test_attribute.rb, NONE, 1.1 test_color.rb, NONE, 1.1 test_diff.rb, NONE, 1.1 test_emacs_runner.rb, NONE, 1.1 test_error.rb, NONE, 1.1 test_failure.rb, NONE, 1.1 test_fixture.rb, NONE, 1.1 test_notification.rb, NONE, 1.1 test_omission.rb, NONE, 1.1 test_pending.rb, NONE, 1.1 test_priority.rb, NONE, 1.1 test_testcase.rb, NONE, 1.1 test_testresult.rb, NONE, 1.1 test_testsuite.rb, NONE, 1.1 testunit_test_util.rb, NONE, 1.1

Kouhei Sutou commit at pdx.freedesktop.org
Wed Aug 13 01:21:02 PDT 2008


Committed by: kou

Update of /cvs/cairo/rcairo/test-unit/test
In directory kemper:/tmp/cvs-serv10309/test-unit/test

Added Files:
	run-test.rb test_assertions.rb test_attribute.rb test_color.rb 
	test_diff.rb test_emacs_runner.rb test_error.rb 
	test_failure.rb test_fixture.rb test_notification.rb 
	test_omission.rb test_pending.rb test_priority.rb 
	test_testcase.rb test_testresult.rb test_testsuite.rb 
	testunit_test_util.rb 
Log Message:
* test-unit: imported Test::Unit 2.x.


--- NEW FILE: run-test.rb ---
#!/usr/bin/env ruby

$VERBOSE = true

base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
lib_dir = File.join(base_dir, "lib")
test_dir = File.join(base_dir, "test")

$LOAD_PATH.unshift(lib_dir)

require 'test/unit'

exit Test::Unit::AutoRunner.run(true, test_dir)

--- NEW FILE: test_assertions.rb ---
# Author:: Nathaniel Talbott.
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
# License:: Ruby license.

require 'test/unit'

module Test
  module Unit
    class TC_Assertions < TestCase
      def check(value, message="")
        add_assertion
        raise AssertionFailedError.new(message) unless value
      end

      def check_assertions(expect_fail, expected_message="",
                           return_value_expected=false)
        @actual_assertion_count = 0
        failed = true
        actual_message = nil
        @catch_assertions = true
        return_value = nil
        begin
          return_value = yield
          failed = false
        rescue AssertionFailedError => error
          actual_message = error.message
        end
        @catch_assertions = false

        if expect_fail
          message = "Should have failed, but didn't"
        else
          message = "Should not have failed, but did with message\n" +
            "<#{actual_message}>"
        end
        check(expect_fail == failed, message)

        message = "Should have made one assertion but made\n" +
          "<#{@actual_assertion_count}>"
        check(1 == @actual_assertion_count, message)

        if expect_fail
          case expected_message
          when String
            check(actual_message == expected_message,
                  "Should have the correct message.\n" +
                  "<#{expected_message.inspect}> expected but was\n" +
                  "<#{actual_message.inspect}>")
          when Regexp
            check(actual_message =~ expected_message,
                  "The message should match correctly.\n" +
                  "</#{expected_message.source}/> expected to match\n" +
                  "<#{actual_message.inspect}>")
          else
            check(false,
                  "Incorrect expected message type in assert_nothing_failed")
          end
        else
          if return_value_expected
            check(!return_value.nil?, "Should return a value")
          else
            check(return_value.nil?,
                  "Should not return a value but returned <#{return_value}>")
          end
        end

        return_value
      end

      def check_nothing_fails(return_value_expected=false, &proc)
        check_assertions(false, "", return_value_expected, &proc)
      end

      def check_fails(expected_message="", &proc)
        check_assertions(true, expected_message, &proc)
      end

      def inspect_tag(tag)
        begin
          throw tag
        rescue NameError
          tag.to_s.inspect
        rescue ArgumentError
          tag.inspect
        end
      end

      def test_assert_block
        check_nothing_fails {
          assert_block {true}
        }
        check_nothing_fails {
          assert_block("successful assert_block") {true}
        }
        check_nothing_fails {
          assert_block("successful assert_block") {true}
        }
        check_fails("assert_block failed.") {
          assert_block {false}
        }
        check_fails("failed assert_block") {
          assert_block("failed assert_block") {false}
        }
      end
      
      def test_assert
        check_nothing_fails{assert("a")}
        check_nothing_fails{assert(true)}
        check_nothing_fails{assert(true, "successful assert")}
        check_fails("<nil> is not true."){assert(nil)}
        check_fails("<false> is not true."){assert(false)}
        check_fails("failed assert.\n<false> is not true."){assert(false, "failed assert")}
      end
      
      def test_assert_equal
        check_nothing_fails {
          assert_equal("string1", "string1")
        }
        check_nothing_fails {
          assert_equal( "string1", "string1", "successful assert_equal")
        }
        check_nothing_fails {
          assert_equal("string1", "string1", "successful assert_equal")
        }

        message = <<-EOM.chomp
<"string1"> expected but was
<"string2">.

diff:
- string1
?       ^
+ string2
?       ^
EOM
        check_fails(message) {
          assert_equal("string1", "string2")
        }

        message = <<-EOM.chomp
failed assert_equal.
<"string1"> expected but was
<"string2">.

diff:
- string1
?       ^
+ string2
?       ^
EOM
        check_fails(message) {
          assert_equal("string1", "string2", "failed assert_equal")
        }

        message = <<-EOM.chomp
<"111111"> expected but was
<111111>.

diff:
- "111111"
? -      -
+ 111111
EOM
        check_fails(message) do
          assert_equal("111111", 111111)
        end
      end

      def test_assert_equal_for_too_small_difference
        message = <<-EOM.chomp
<1> expected but was
<2>.
EOM
        check_fails(message) do
          assert_equal(1, 2)
        end
      end

      def test_assert_equal_for_same_inspected_objects
        now = Time.now
        now_without_usec = Time.at(now.to_i)
        message = <<-EOM.chomp
<#{now.inspect}> expected but was
<#{now.inspect}>.
EOM
        check_fails(message) do
          assert_equal(now, now_without_usec)
        end
      end

      def test_assert_equal_with_multi_lines_result
        message = <<-EOM.chomp
<#{"a\nb".inspect}> expected but was
<#{"x".inspect}>.

diff:
+ x
- a
- b
EOM
        check_fails(message) do
          assert_equal("a\nb", "x")
        end
      end

      def test_assert_raise
        return_value = nil
        check_nothing_fails(true) {
          return_value = assert_raise(RuntimeError) {
            raise "Error"
          }
        }
        check(return_value.kind_of?(Exception), "Should have returned the exception from a successful assert_raise")
        check(return_value.message == "Error", "Should have returned the correct exception from a successful assert_raise")
        check_nothing_fails(true) {
          assert_raise(ArgumentError, "successful assert_raise") {
            raise ArgumentError.new("Error")
          }
        }
        check_nothing_fails(true) {
          assert_raise(RuntimeError) {
            raise "Error"
          }
        }
        check_nothing_fails(true) {
          assert_raise(RuntimeError, "successful assert_raise") {
            raise "Error"
          }
        }
        check_fails("<RuntimeError> exception expected but none was thrown.") {
          assert_raise(RuntimeError) {
            1 + 1
          }
        }
        check_fails(%r{\Afailed assert_raise.\n<ArgumentError> exception expected but was\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
          assert_raise(ArgumentError, "failed assert_raise") {
            raise "Error"
          }
        }
        check_fails("Should expect a class of exception, Object.\n<false> is not true.") {
          assert_nothing_raised(Object) {
            1 + 1
          }
        }

        exceptions = [ArgumentError, TypeError]
        modules = [Math, Comparable]
        rescues = exceptions + modules
        exceptions.each do |exc|
          check_nothing_fails(true) {
            return_value = assert_raise(*rescues) {
              raise exc, "Error"
            }
          }
          check(return_value.instance_of?(exc), "Should have returned #{exc} but was #{return_value.class}")
          check(return_value.message == "Error", "Should have returned the correct exception from a successful assert_raise")
        end
        modules.each do |mod|
          check_nothing_fails(true) {
            return_value = assert_raise(*rescues) {
              raise Exception.new("Error").extend(mod)
            }
          }
          check(mod === return_value, "Should have returned #{mod}")
          check(return_value.message == "Error", "Should have returned the correct exception from a successful assert_raise")
        end
        check_fails("<[ArgumentError, TypeError, Math, Comparable]> exception expected but none was thrown.") {
          assert_raise(*rescues) {
            1 + 1
          }
        }
        check_fails(%r{\Afailed assert_raise.
<\[ArgumentError, TypeError\]> exception expected but was
Class: <RuntimeError>
Message: <"Error">
---Backtrace---
.+
---------------\Z}m) {
          assert_raise(ArgumentError, TypeError, "failed assert_raise") {
            raise "Error"
          }
        }
      end
      
      def test_assert_instance_of
        check_nothing_fails {
          assert_instance_of(String, "string")
        }
        check_nothing_fails {
          assert_instance_of(String, "string", "successful assert_instance_of")
        }
        check_nothing_fails {
          assert_instance_of(String, "string", "successful assert_instance_of")
        }
        check_fails(%Q{<"string"> expected to be an instance of\n<Hash> but was\n<String>.}) {
          assert_instance_of(Hash, "string")
        }
        check_fails(%Q{failed assert_instance_of.\n<"string"> expected to be an instance of\n<Hash> but was\n<String>.}) {
          assert_instance_of(Hash, "string", "failed assert_instance_of")
        }
      end
      
      def test_assert_nil
        check_nothing_fails {
          assert_nil(nil)
        }
        check_nothing_fails {
          assert_nil(nil, "successful assert_nil")
        }
        check_nothing_fails {
          assert_nil(nil, "successful assert_nil")
        }
        check_fails(%Q{<"string"> expected to be nil.}) {
          assert_nil("string")
        }
        check_fails(%Q{failed assert_nil.\n<"string"> expected to be nil.}) {
          assert_nil("string", "failed assert_nil")
        }
      end
      
      def test_assert_not_nil
        check_nothing_fails{assert_not_nil(false)}
        check_nothing_fails{assert_not_nil(false, "message")}
        check_fails("<nil> expected to not be nil."){assert_not_nil(nil)}
        check_fails("message.\n<nil> expected to not be nil.") {assert_not_nil(nil, "message")}
      end
        
      def test_assert_kind_of
        check_nothing_fails {
          assert_kind_of(Module, Array)
        }
        check_nothing_fails {
          assert_kind_of(Object, "string", "successful assert_kind_of")
        }
        check_nothing_fails {
          assert_kind_of(Object, "string", "successful assert_kind_of")
        }
        check_nothing_fails {
          assert_kind_of(Comparable, 1)
        }
        check_fails(%Q{<"string">\nexpected to be kind_of?\n<Class> but was\n<String>.}) {
          assert_kind_of(Class, "string")
        }
        check_fails(%Q{failed assert_kind_of.\n<"string">\nexpected to be kind_of?\n<Class> but was\n<String>.}) {
          assert_kind_of(Class, "string", "failed assert_kind_of")
        }
      end
      
      def test_assert_match
        check_nothing_fails {
          assert_match(/strin./, "string")
        }
        check_nothing_fails {
          assert_match("strin", "string")
        }
        check_nothing_fails {
          assert_match(/strin./, "string", "successful assert_match")
        }
        check_nothing_fails {
          assert_match(/strin./, "string", "successful assert_match")
        }
        check_fails(%Q{<"string"> expected to be =~\n</slin./>.}) {
          assert_match(/slin./, "string")
        }
        check_fails(%Q{<"string"> expected to be =~\n</strin\\./>.}) {
          assert_match("strin.", "string")
        }
        check_fails(%Q{failed assert_match.\n<"string"> expected to be =~\n</slin./>.}) {
          assert_match(/slin./, "string", "failed assert_match")
        }
      end
      
      def test_assert_same
        thing = "thing"
        check_nothing_fails {
          assert_same(thing, thing)
        }
        check_nothing_fails {
          assert_same(thing, thing, "successful assert_same")
        }
        check_nothing_fails {
          assert_same(thing, thing, "successful assert_same")
        }
        thing2 = "thing"
        check_fails(%Q{<"thing">\nwith id <#{thing.__id__}> expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
          assert_same(thing, thing2)
        }
        check_fails(%Q{failed assert_same.\n<"thing">\nwith id <#{thing.__id__}> expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
          assert_same(thing, thing2, "failed assert_same")
        }
      end
      
      def test_assert_nothing_raised
        check_nothing_fails {
          assert_nothing_raised {
            1 + 1
          }
        }
        check_nothing_fails {
          assert_nothing_raised("successful assert_nothing_raised") {
            1 + 1
          }
        }
        check_nothing_fails {
          assert_nothing_raised("successful assert_nothing_raised") {
            1 + 1
          }
        }
        check_nothing_fails {
          begin
            assert_nothing_raised(RuntimeError, StandardError, Comparable, "successful assert_nothing_raised") {
              raise ZeroDivisionError.new("ArgumentError")
            }
          rescue ZeroDivisionError
          end
        }
        check_fails("Should expect a class of exception, Object.\n<false> is not true.") {
          assert_nothing_raised(Object) {
            1 + 1
          }
        }
        check_fails(%r{\AException raised:\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
          assert_nothing_raised {
            raise "Error"
          }
        }
        check_fails(%r{\Afailed assert_nothing_raised\.\nException raised:\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
          assert_nothing_raised("failed assert_nothing_raised") {
            raise "Error"
          }
        }
        check_fails(%r{\AException raised:\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
          assert_nothing_raised(StandardError, RuntimeError) {
            raise "Error"
          }
        }
        check_fails("Failure.") do
          assert_nothing_raised do
            flunk("Failure")
          end
        end
      end
      
      def test_flunk
        check_fails("Flunked.") {
          flunk
        }
        check_fails("flunk message.") {
          flunk("flunk message")
        }
      end
      
      def test_assert_not_same
        thing = "thing"
        thing2 = "thing"
        check_nothing_fails {
          assert_not_same(thing, thing2)
        }
        check_nothing_fails {
          assert_not_same(thing, thing2, "message")
        }
        check_fails(%Q{<"thing">\nwith id <#{thing.__id__}> expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
          assert_not_same(thing, thing)
        }
        check_fails(%Q{message.\n<"thing">\nwith id <#{thing.__id__}> expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
          assert_not_same(thing, thing, "message")
        }
      end
      
      def test_assert_not_equal
        check_nothing_fails {
          assert_not_equal("string1", "string2")
        }
        check_nothing_fails {
          assert_not_equal("string1", "string2", "message")
        }
        check_fails(%Q{<"string"> expected to be != to\n<"string">.}) {
          assert_not_equal("string", "string")
        }
        check_fails(%Q{message.\n<"string"> expected to be != to\n<"string">.}) {
          assert_not_equal("string", "string", "message")
        }
      end
      
      def test_assert_no_match
        check_nothing_fails{assert_no_match(/sling/, "string")}
        check_nothing_fails{assert_no_match(/sling/, "string", "message")}
        check_fails(%Q{The first argument to assert_no_match should be a Regexp.\n<"asdf"> expected to be an instance of\n<Regexp> but was\n<String>.}) do
          assert_no_match("asdf", "asdf")
        end
        check_fails(%Q{</string/> expected to not match\n<"string">.}) do
          assert_no_match(/string/, "string")
        end
        check_fails(%Q{message.\n</string/> expected to not match\n<"string">.}) do
          assert_no_match(/string/, "string", "message")
        end
      end
      
      def test_assert_throws
        check_nothing_fails do
          assert_throws(:thing, "message") do
            throw :thing
          end
        end

        tag = :thing2
        check_fails("message.\n" +
                    "<:thing> expected to be thrown but\n" +
                    "<#{inspect_tag(tag)}> was thrown.") do
          assert_throws(:thing, "message") do
            throw :thing2
          end
        end
        check_fails("message.\n" +
                    "<:thing> should have been thrown.") do
          assert_throws(:thing, "message") do
            1 + 1
          end
        end
      end
      
      def test_assert_nothing_thrown
        check_nothing_fails do
          assert_nothing_thrown("message") do
            1 + 1
          end
        end

        tag = :thing
        inspected = inspect_tag(tag)
        check_fails("message.\n" +
                    "<#{inspected}> was thrown when nothing was expected.") do
          assert_nothing_thrown("message") do
            throw tag
          end
        end
      end
      
      def test_assert_operator
        check_nothing_fails {
          assert_operator("thing", :==, "thing", "message")
        }
        check_fails(%Q{<0.15>\ngiven as the operator for #assert_operator must be a Symbol or #respond_to?(:to_str).}) do
          assert_operator("thing", 0.15, "thing")
        end
        check_fails(%Q{message.\n<"thing1"> expected to be\n==\n<"thing2">.}) {
          assert_operator("thing1", :==, "thing2", "message")
        }
      end
      
      def test_assert_respond_to
        check_nothing_fails {
          assert_respond_to("thing", :to_s, "message")
        }
        check_nothing_fails {
          assert_respond_to("thing", "to_s", "message")
        }
        check_fails("<0.15>\ngiven as the method name argument to #assert_respond_to must be a Symbol or #respond_to?(:to_str).") {
          assert_respond_to("thing", 0.15)
        }
        check_fails("message.\n<:symbol>\nof type <Symbol>\nexpected to respond_to?<:non_existent>.") {
          assert_respond_to(:symbol, :non_existent, "message")
        }
      end
      
      def test_assert_in_delta
        check_nothing_fails {
          assert_in_delta(1.4, 1.4, 0)
        }
        check_nothing_fails {
          assert_in_delta(0.5, 0.4, 0.1, "message")
        }
        check_nothing_fails {
          float_thing = Object.new
          def float_thing.to_f
            0.2
          end
          assert_in_delta(0.1, float_thing, 0.1)
        }
        check_fails("message.\n<0.5> and\n<0.4> expected to be within\n<0.05> of each other.") {
          assert_in_delta(0.5, 0.4, 0.05, "message")
        }
        check_fails(%r{The arguments must respond to to_f; the first float did not\.\n<.+>\nof type <Object>\nexpected to respond_to\?<:to_f>.}) {
          assert_in_delta(Object.new, 0.4, 0.1)
        }
        check_fails("The delta should not be negative.\n<-0.1> expected to be\n>=\n<0.0>.") {
          assert_in_delta(0.5, 0.4, -0.1, "message")
        }
      end
      
      def test_assert_send
        object = Object.new
        class << object
          private
          def return_argument(argument, bogus)
            return argument
          end
        end
        check_nothing_fails {
          assert_send([object, :return_argument, true, "bogus"], "message")
        }
        check_fails(%r{\Amessage\.\n<.+> expected to respond to\n<return_argument\(\[false, "bogus"\]\)> with a true value.\Z}) {
          assert_send([object, :return_argument, false, "bogus"], "message")
        }
      end
      
      def test_condition_invariant
        object = Object.new
        def object.inspect
          @changed = true
        end
        def object.==(other)
          @changed ||= false
          return (!@changed)
        end
        check_nothing_fails do
          assert_equal(object, object, "message")
        end
      end

      def test_assert_boolean
        check_nothing_fails do
          assert_boolean(true)
        end
        check_nothing_fails do
          assert_boolean(false)
        end

        check_fails("<true> or <false> expected but was\n<1>") do
          assert_boolean(1)
        end

        check_fails("<true> or <false> expected but was\n<nil>") do
          assert_boolean(nil)
        end

        check_fails("message.\n<true> or <false> expected but was\n<\"XXX\">") do
          assert_boolean("XXX", "message")
        end
      end

      def test_assert_true
        check_nothing_fails do
          assert_true(true)
        end

        check_fails("<true> expected but was\n<false>") do
          assert_true(false)
        end

        check_fails("<true> expected but was\n<1>") do
          assert_true(1)
        end

        check_fails("message.\n<true> expected but was\n<nil>") do
          assert_true(nil, "message")
        end
      end

      def test_assert_false
        check_nothing_fails do
          assert_false(false)
        end

        check_fails("<false> expected but was\n<true>") do
          assert_false(true)
        end

        check_fails("<false> expected but was\n<nil>") do
          assert_false(nil)
        end

        check_fails("message.\n<false> expected but was\n<:false>") do
          assert_false(:false, "message")
        end
      end

      def add_failure(message, location=caller)
        unless @catch_assertions
          super
        end
      end

      def add_assertion
        if @catch_assertions
          @actual_assertion_count += 1
        else
          super
        end
      end
    end
  end
end

--- NEW FILE: test_attribute.rb ---
class TestUnitAttribute < Test::Unit::TestCase
  class TestStack < Test::Unit::TestCase
    class << self
      def suite
        Test::Unit::TestSuite.new(name)
      end
    end

    class Stack
      def initialize
        @data = []
      end

      def push(data)
        @data.push(data)
      end

      def peek
        @data[-2]
      end

      def empty?
        @data.empty?
      end

      def size
        @data.size + 11
      end
    end

    def setup
      @stack = Stack.new
    end

    attribute :category, :accessor
    def test_peek
      @stack.push(1)
      @stack.push(2)
      assert_equal(2, @stack.peek)
    end

    attribute :bug, 1234
    def test_bug_1234
      assert_equal(0, @stack.size)
    end

    def test_no_attributes
      assert(@stack.empty?)
      @stack.push(1)
      assert(!@stack.empty?)
      assert_equal(1, @stack.size)
    end
  end

  def test_set_attributes
    test_for_accessor_category = TestStack.new("test_peek")
    assert_equal({"category" => :accessor},
                 test_for_accessor_category.attributes)

    test_for_bug_1234 = TestStack.new("test_bug_1234")
    assert_equal({"bug" => 1234}, test_for_bug_1234.attributes)

    test_no_attributes = TestStack.new("test_no_attributes")
    assert_equal({}, test_no_attributes.attributes)
  end

  def test_callback
    changed_attributes = []
    observer = Proc.new do |test_case, key, old_value, value, method_name|
      changed_attributes << [test_case, key, old_value, value, method_name]
    end

    test_case = Class.new(TestStack) do
      register_attribute_observer(:bug, &observer)
      attribute("bug", 9876, "test_bug_1234")
      attribute(:description, "Test for peek", "test_peek")
      attribute(:bug, 29, "test_peek")
    end

    assert_equal([
                  [test_case, "bug", 1234, 9876, "test_bug_1234"],
                  [test_case, "bug", nil, 29, "test_peek"],
                 ],
                 changed_attributes)
  end
end

--- NEW FILE: test_color.rb ---
class TestUnitColor < Test::Unit::TestCase
  def test_color_escape_sequence
    assert_escape_sequence(["31"], color("red"))
    assert_escape_sequence(["32", "1"], color("green", :bold => true))
    assert_escape_sequence(["0"], color("reset"))
    assert_escape_sequence(["45"], color("magenta", :foreground => false))
  end

  def test_mix_color_escape_sequence
    assert_escape_sequence(["34", "1"],
                           mix_color([color("blue"),
                                      color("none", :bold => true)]))
    assert_escape_sequence(["34", "1", "4"],
                           mix_color([color("blue"),
                                      color("none", :bold => true)]) +
                           color("none", :underline => true))
    assert_escape_sequence(["34", "1", "4"],
                           color("blue") +
                           color("none", :bold => true) +
                           color("none", :underline => true))
  end

  private
  def color(name, options={})
    Test::Unit::Color.new(name, options)
  end

  def mix_color(colors)
    Test::Unit::MixColor.new(colors)
  end

  def assert_escape_sequence(expected, color)
    assert_equal(expected, color.sequence)
    assert_match(/\e\[(?:\d+;)*\d+m/, color.escape_sequence)
    assert_equal(expected, color.escape_sequence[2..-2].split(";"))
  end
end

--- NEW FILE: test_diff.rb ---
class TestUnitDiff < Test::Unit::TestCase
  def test_to_indexes
    assert_to_indexes({"abc def" => [0, 2], "abc" => [1]},
                      ["abc def", "abc", "abc def"])

    assert_to_indexes({?a => [0, 3], ?b => [1], ?c => [2], ?d => [4]},
                      "abcad")

    assert_to_indexes({
                        ?1 => [0, 35],
                        ?t => [2, 5, 16],
                        ?e => [3, 14, 31, 38],
                        ?s => [4, 6, 12, 13, 20, 32, 44],
                        ?, => [7, 21, 33],
                        ?0 => [9, 23],
                        ?a => [11, 26],
                        ?r => [15, 30],
                        ?i => [17, 27, 41],
                        ?o => [18],
                        ?n => [19, 39, 42],
                        ?f => [25],
                        ?l => [28],
                        ?u => [29],
                        ?p => [37],
                        ?d => [40],
                        ?g => [43],
                      },
                      "1 tests, 0 assertions, 0 failures, 1 pendings") do |x|
      x == " "[0]
    end
  end

  def test_longest_match
    assert_longest_match([0, 1, 3],
                         %w(b c d), %w(a b c d x y z),
                         0, 2, 0, 7)
    assert_longest_match([1, 2, 2],
                         %w(b c d), %w(a b c d x y z),
                         1, 2, 0, 6)
    assert_longest_match([0, 0, 0],
                         %w(a b), %w(c),
                         0, 1, 0, 0)
    assert_longest_match([1, 0, 2],
                         %w(q a b x c d), %w(a b y c d f),
                         0, 5, 0, 5)
    assert_longest_match([4, 3, 2],
                         %w(q a b x c d), %w(a b y c d f),
                         3, 5, 2, 5)

    assert_longest_match([1, 0, 2], "qabxcd", "abycdf", 0, 5, 0, 5)
    assert_longest_match([0, 0, 1], "efg", "eg", 0, 2, 0, 1)
    assert_longest_match([2, 1, 1], "efg", "eg", 1, 2, 1, 1)
  end

  def test_longest_match_with_junk_predicate
    assert_longest_match([0, 4, 5], " abcd", "abcd abcd", 0, 4, 0, 8)
    assert_longest_match([1, 0, 4], " abcd", "abcd abcd", 0, 4, 0, 8) do |x|
      x == ' '[0]
    end
  end

  def test_matches
    assert_matches([[0, 0, 2],
                    [3, 2, 2]],
                   %w(a b x c d), %w(a b c d))
    assert_matches([[1, 0, 2],
                    [4, 3, 2]],
                   %w(q a b x c d), %w(a b y c d f))

    assert_matches([[1, 0, 2],
                    [4, 3, 2]],
                   "qabxcd", "abycdf")
    assert_matches([[0, 0, 1],
                    [2, 1, 1]],
                   "efg", "eg")
  end

  def test_matches_with_junk_predicate
    assert_matches([[0, 0, 23],
                    [24, 24, 11],
                    [36, 36, 9]],
                  "1 tests, 0 assertions, 1 failures, 0 pendings",
                  "1 tests, 0 assertions, 0 failures, 1 pendings")

    assert_matches([[0, 0, 1],
                    [1, 1, 8],
                    [9, 9, 1],
                    [10, 10, 13],
                    [24, 24, 11],
                    [36, 36, 9]],
                  "1 tests, 0 assertions, 1 failures, 0 pendings",
                  "1 tests, 0 assertions, 0 failures, 1 pendings") do |x|
      x == " "[0]
    end
  end

  def test_blocks
    assert_blocks([[0, 0, 2],
                   [3, 2, 2],
                   [5, 4, 0]],
                  %w(a b x c d), %w(a b c d))
    assert_blocks([[1, 0, 2],
                   [4, 3, 2],
                   [6, 6, 0]],
                  %w(q a b x c d), %w(a b y c d f))

    assert_blocks([[1, 0, 2],
                   [4, 3, 2],
                   [6, 6, 0]],
                  "qabxcd", "abycdf")
    assert_blocks([[0, 0, 1],
                   [2, 1, 1],
                   [3, 2, 0]],
                  "efg", "eg")
  end

  def test_blocks_with_junk_predicate
    assert_blocks([[0, 0, 23],
                   [24, 24, 11],
                   [36, 36, 9],
                   [45, 45, 0]],
                  "1 tests, 0 assertions, 1 failures, 0 pendings",
                  "1 tests, 0 assertions, 0 failures, 1 pendings") do |x|
      x == " "[0]
    end
  end

  def test_operations
    assert_operations([], %w(), %w())

    assert_operations([[:delete, 0, 1, 0, 0],
                       [:equal, 1, 3, 0, 2],
                       [:replace, 3, 4, 2, 3],
                       [:equal, 4, 6, 3, 5],
                       [:insert, 6, 6, 5, 6]],
                      %w(q a b x c d), %w(a b y c d f))

    assert_operations([[:delete, 0, 1, 0, 0],
                       [:equal, 1, 3, 0, 2],
                       [:replace, 3, 4, 2, 3],
                       [:equal, 4, 6, 3, 5],
                       [:insert, 6, 6, 5, 6]],
                      "qabxcd", "abycdf")

    assert_operations([[:equal, 0, 23, 0, 23],
                       [:replace, 23, 24, 23, 24],
                       [:equal, 24, 35, 24, 35],
                       [:replace, 35, 36, 35, 36],
                       [:equal, 36, 45, 36, 45]],
                      "1 tests, 0 assertions, 1 failures, 0 pendings",
                      "1 tests, 0 assertions, 0 failures, 1 pendings")

    assert_operations([[:equal, 0, 23, 0, 23],
                       [:replace, 23, 24, 23, 24],
                       [:equal, 24, 35, 24, 35],
                       [:replace, 35, 36, 35, 36],
                       [:equal, 36, 45, 36, 45]],
                      "1 tests, 0 assertions, 1 failures, 0 pendings",
                      "1 tests, 0 assertions, 0 failures, 1 pendings") do |x|
      x == " "[0]
    end
  end

  def test_grouped_operations
    assert_grouped_operations([[[:equal, 0, 0, 0, 0]]],
                              %w(),
                              %w())

    assert_grouped_operations([[[:equal, 0, 3, 0, 3]]],
                              %w(a b c),
                              %w(a b c))

    assert_grouped_operations([[[:equal, 0, 1, 0, 1],
                                [:replace, 1, 2, 1, 2],
                                [:equal, 2, 5, 2, 5]],
                               [[:equal, 8, 11, 8, 11],
                                [:replace, 11, 12, 11, 12],
                                [:equal, 12, 13, 12, 13],
                                [:delete, 13, 16, 13, 13],
                                [:equal, 16, 17, 13, 14],
                                [:replace, 17, 18, 14, 15],
                                [:equal, 18, 20, 15, 17]]],
                              %w(1 2 3 4 5 6 7 8 9 a b c d e f g h i j k),
                              %w(1 i 3 4 5 6 7 8 9 a b cX d h iX j k))
  end

  def test_ratio
    assert_ratio(0.75, "abcd", "bcde")
    assert_ratio(0.80, "efg", "eg")
  end

  def test_same_contents_readable_diff
    assert_readable_diff("  aaa", ["aaa"], ["aaa"])
    assert_readable_diff("  aaa\n" \
                         "  bbb",
                         ["aaa", "bbb"], ["aaa", "bbb"])
  end

  def test_deleted_readable_diff
    assert_readable_diff("  aaa\n" \
                         "- bbb",
                         ["aaa", "bbb"], ["aaa"])
    assert_readable_diff("  aaa\n" \
                         "- bbb\n" \
                         "- ccc\n" \
                         "- ddd",
                         ["aaa", "bbb", "ccc", "ddd"], ["aaa"])
  end

  def test_inserted_readable_diff
    assert_readable_diff("  aaa\n" \
                         "+ bbb\n" \
                         "+ ccc\n" \
                         "+ ddd",
                         ["aaa"], ["aaa", "bbb", "ccc", "ddd"])
  end

  def test_replace_readable_diff
    assert_readable_diff("  aaa\n" \
                         "- bbb\n" \
                         "+ BbB\n" \
                         "  ccc\n" \
                         "- ddd\n" \
                         "- efg\n" \
                         "?  -\n" \
                         "+ eg",
                         ["aaa", "bbb", "ccc", "ddd", "efg"],
                         ["aaa", "BbB", "ccc", "eg"])

    assert_readable_diff("-  abcd xyz abc\n" \
                         "? -\n" \
                         "+ abcd abcd xyz abc\n" \
                         "?      +++++",
                         [" abcd xyz abc"],
                         ["abcd abcd xyz abc"])
  end

  def test_difference_readable_diff
    assert_readable_diff("- 1 tests, 0 assertions, 1 failures, 0 pendings\n" \
                         "?                        ^           ^\n" \
                         "+ 1 tests, 0 assertions, 0 failures, 1 pendings\n" \
                         "?                        ^           ^",
                         ["1 tests, 0 assertions, 1 failures, 0 pendings"],
                         ["1 tests, 0 assertions, 0 failures, 1 pendings"])
  end

  def test_complex_readable_diff
    assert_readable_diff("  aaa\n" \
                         "- bbb\n" \
                         "- ccc\n" \
                         "+ \n" \
                         "+   # \n" \
                         "  ddd",
                         ["aaa", "bbb", "ccc", "ddd"],
                         ["aaa", "", "  # ", "ddd"])

    assert_readable_diff("- one1\n" \
                         "?  ^\n" \
                         "+ ore1\n" \
                         "?  ^\n" \
                         "- two2\n" \
                         "- three3\n" \
                         "?  -   -\n" \
                         "+ tree\n" \
                         "+ emu",
                         ["one1", "two2", "three3"],
                         ["ore1", "tree", "emu"])
  end

  def test_empty_readable_diff
    assert_readable_diff("", [""], [""])
  end

  def test_unified_diff
    assert_unified_diff("",
                        ["one", "two", "three"],
                        ["one", "two", "three"],
                        "content 1",
                        "content 2")

    assert_unified_diff("--- Original Sat Jan 26 23:30:50 1991\n" \
                        "+++ Current Fri Jun 06 10:20:52 2003\n" \
                        "@@ -1,4 +1,4 @@\n" \
                        "+zero\n" \
                        " one\n" \
                        "-two\n" \
                        "-three\n" \
                        "+tree\n" \
                        " four",
                        ["one", "two", "three", "four"],
                        ["zero", "one", "tree", "four"],
                        "Original Sat Jan 26 23:30:50 1991",
                        "Current Fri Jun 06 10:20:52 2003",
                        :show_context => false)

    from = File.read(__FILE__).split(/\n/)
    to = from.dup
    target_line = __LINE__
    to[target_line - 1, 1] = []
    context = "  def test_unified_diff"
    summary = "@@ -#{target_line - 3},7 +#{target_line - 3},6 @@ #{context}"
    assert_unified_diff((["--- revision 10",
                          "+++ revision 11",
                          summary] +
                         from[target_line - 4, 3].collect {|line| " #{line}"} +
                         ["-#{from[target_line - 1]}"] +
                         from[target_line, 3].collect {|line| " #{line}"}
                         ).join("\n"),
                        from, to,
                        "revision 10",
                        "revision 11")
  end

  def test_empty_unified_diff
    assert_unified_diff("", [""], [""], "From", "To")
    assert_unified_diff("", [], [], "From", "To")
  end

  def test_diff_lines
    assert_diff_lines(["- ddd",
                       "- efg",
                       "?  -",
                       "+ eg"],
                      ["aaa", "bbb", "ccc", "ddd", "efg"],
                      ["aaa", "BbB", "ccc", "eg"],
                      3, 5, 3, 4)
  end

  def test_diff_line
    assert_diff_line(["- abcDefghiJkl",
                      "?    ^  ^  ^",
                      "+ abcdefGhijkl",
                      "?    ^  ^  ^"],
                     "abcDefghiJkl",
                     "abcdefGhijkl")

    assert_diff_line(["- bcDefghiJklx",
                      "?   ^  ^  ^  -",
                      "+ abcdefGhijkl",
                      "? +  ^  ^  ^"],
                     "bcDefghiJklx",
                     "abcdefGhijkl")
  end

  def test_empty_diff_line
    assert_diff_line(["- ",
                      "+ "],
                     "", "")
  end

  def test_format_diff_point
    assert_format_diff_point(["- \tabcDefghiJkl",
                              "? \t ^ ^  ^",
                              "+ \t\tabcdefGhijkl",
                              "? \t  ^ ^  ^"],
                             "\tabcDefghiJkl",
                             "\t\tabcdefGhijkl",
                             "  ^ ^  ^      ",
                             "+  ^ ^  ^      ")
    assert_format_diff_point(["- efg",
                              "?  ^",
                              "+ eg"],
                             "efg",
                             "eg",
                             " ^",
                             "")
  end

  def test_interesting_line
    from = ["class X",
            "  def find(x=0)",
            "    body",
            "  end",
            "end"]
    to = ["def xxx",
          "  raise 'not call me'",
          "end"]
    assert_interesting_line("  def find(x=0)",
                            from, to,
                            2, 1)
    assert_interesting_line("def xxx",
                            from, to,
                            2, 0)
    assert_interesting_line("class X",
                            from, to,
                            0, 0)
  end

  private
  def assert_to_indexes(expected, to, &junk_predicate)
    matcher = Test::Unit::Diff::SequenceMatcher.new([""], to, &junk_predicate)
    assert_equal(expected, matcher.instance_variable_get("@to_indexes"))
  end

  def assert_find_best_match_position(expected, from, to,
                                      from_start, from_end,
                                      to_start, to_end, &junk_predicate)
    matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)
    assert_equal(expected, matcher.send(:find_best_match_position,
                                        from_start, from_end,
                                        to_start, to_end))
  end

  def assert_longest_match(expected, from, to,
                           from_start, from_end,
                           to_start, to_end, &junk_predicate)
    matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)
    assert_equal(expected, matcher.longest_match(from_start, from_end,
                                                 to_start, to_end))
  end

  def assert_matches(expected, from, to, &junk_predicate)
    matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)
    assert_equal(expected, matcher.send(:matches))
  end

  def assert_blocks(expected, from, to, &junk_predicate)
    matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)
    assert_equal(expected, matcher.blocks)
  end

  def assert_operations(expected, from, to, &junk_predicate)
    matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)
    assert_equal(expected, matcher.operations)
  end

  def assert_grouped_operations(expected, from, to)
    matcher = Test::Unit::Diff::SequenceMatcher.new(from, to)
    assert_equal(expected, matcher.grouped_operations)
  end

  def assert_ratio(expected, from, to)
    matcher = Test::Unit::Diff::SequenceMatcher.new(from, to)
    assert_in_delta(expected, 0.001, matcher.ratio)
  end

  def assert_readable_diff(expected, from, to)
    assert_equal(expected,
                 Test::Unit::Diff.readable(from.join("\n"), to.join("\n")))
  end

  def assert_unified_diff(expected, from, to, from_label, to_label, options={})
    options = options.merge(:from_label => from_label,
                            :to_label => to_label)
    assert_equal(expected,
                 Test::Unit::Diff.unified(from.join("\n"), to.join("\n"),
                                          options))
  end

  def assert_diff_lines(expected, from, to,
                        from_start, from_end,
                        to_start, to_end)
    differ = Test::Unit::Diff::ReadableDiffer.new(from, to)
    assert_equal(expected, differ.send(:diff_lines,
                                       from_start, from_end,
                                       to_start, to_end))
  end

  def assert_diff_line(expected, from_line, to_line)
    differ = Test::Unit::Diff::ReadableDiffer.new([""], [""])
    assert_equal(expected, differ.send(:diff_line, from_line, to_line))
  end

  def assert_format_diff_point(expected, from_line, to_line, from_tags, to_tags)
    differ = Test::Unit::Diff::ReadableDiffer.new([""], [""])
    assert_equal(expected, differ.send(:format_diff_point,
                                       from_line, to_line,
                                       from_tags, to_tags))
  end

  def assert_interesting_line(expected, from, to, from_start, to_start)
    differ = Test::Unit::Diff::UnifiedDiffer.new(from, to)
    assert_equal(expected, differ.send(:find_interesting_line,
                                       from_start, to_start,
                                       :define_line?))
  end
end

--- NEW FILE: test_emacs_runner.rb ---
require 'test/unit'
require 'test/unit/ui/emacs/testrunner'

class TestUnitEmacsRunner < Test::Unit::TestCase
  def test_format_failure_with_a_location
    runner = create_runner
    test_name = "test_failure"
    file = "/home/user/test_xxx.rb"
    line = "3"
    info = "in `xxx'"
    location = "#{file}:#{line}: #{info}"
    message = "FAIL!!!"
    failure = Test::Unit::Failure.new(test_name, [location], message)
    assert_equal(<<-EOM.chomp, runner.send(:format_fault, failure))
Failure:
#{test_name} [#{file}:#{line}]:
#{message}
EOM
  end

  def test_format_failure_with_locations
    runner = create_runner
    test_name = "test_failure"
    locations = ["/home/user/test_xxx.rb:3: in `xxx'",
                 "/home/user/yyy/test_yyy.rb:999: in `yyy'",
                 "/home/user/xyz/zzz.rb:29: in `zzz'"]
    message = "Many backtrace!!!"
    failure = Test::Unit::Failure.new(test_name, locations, message)
    assert_equal(<<-EOM.chomp, runner.send(:format_fault, failure))
Failure:
#{test_name}
#{locations.join("\n")}:
#{message}
EOM
  end

  def test_format_error
    runner = create_runner
    test_name = "test_error"
    message = "Error Message!!!"
    backtrace = ["/home/user/test_xxx.rb:3: in `xxx'",
                 "/home/user/yyy/test_yyy.rb:999: in `yyy'",
                 "/home/user/xyz/zzz.rb:29: in `zzz'"]
    exception = RuntimeError.new(message)
    exception.set_backtrace(backtrace)
    error = Test::Unit::Error.new(test_name, exception)
    assert_equal(<<-EOM.chomp, runner.send(:format_fault, error))
Error:
#{test_name}:
#{exception.class.name}: #{message}
#{backtrace.join("\n")}
EOM
  end

  private
  def create_runner(suite=nil)
    suite ||= Test::Unit::TestSuite.new
    Test::Unit::UI::Emacs::TestRunner.new(suite)
  end
end

--- NEW FILE: test_error.rb ---
# Author:: Nathaniel Talbott.
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
# License:: Ruby license.

require 'test/unit'

module Test
  module Unit
    class TC_Error < TestCase
      TF_Exception = Struct.new('TF_Exception', :message, :backtrace)
      def test_display
        ex = TF_Exception.new("message1\nmessage2", ['line1', 'line2'])
        e = Error.new("name", ex)
        assert_equal("name: #{TF_Exception.name}: message1", e.short_display)
        assert_equal(<<EOM.strip, e.long_display)
Error:
name:
Struct::TF_Exception: message1
message2
    line1
    line2
EOM
      end
    end
  end
end

--- NEW FILE: test_failure.rb ---
# Author:: Nathaniel Talbott.
# Copyright:: Copyright (c) 2003 Nathaniel Talbott. All rights reserved.
# License:: Ruby license.

require 'test/unit'
require 'test/unit/failure'

module Test::Unit
  class TestFailure < TestCase
    def test_display
      f = Failure.new("name", [%q{location:1 in 'l'}], "message1\nmessage2")
      assert_equal("name: message1", f.short_display)
      assert_equal(<<EOM.strip, f.long_display)
Failure:
name [location:1]:
message1
message2
EOM

      f = Failure.new("name", [%q{location1:2 in 'l1'}, 'location2:1', %q{location3:3 in 'l3'}], "message1\nmessage2")
      assert_equal("name: message1", f.short_display)
      assert_equal(<<EOM.strip, f.long_display)
Failure:
name
    [location1:2 in 'l1'
     location2:1
     location3:3 in 'l3']:
message1
message2
EOM
    end
  end
end

--- NEW FILE: test_fixture.rb ---
class TestUnitFixture < Test::Unit::TestCase
  module EmptyModule
  end

  def test_setup_without_option
    test_case = assert_setup([:setup,
                              :custom_setup_method0,
                              :custom_setup_method1,
                              :custom_setup_method3],
                             [])
    assert_inherited_setup([:setup,
                            :custom_setup_method0,
                            :custom_setup_method1,
                            :custom_setup_method3],
                           test_case)
    assert_inherited_setup([:setup], nil)
  end

  def test_setup_with_before_option
    test_case = assert_setup([:custom_setup_method3,
                              :custom_setup_method0,
                              :custom_setup_method1,
                              :setup],
                             [[{:before => :append}],
                              [{:before => :append}],
                              [{:before => :prepend}],
                              [{:before => :prepend}]])
    assert_inherited_setup([:custom_setup_method3,
                            :custom_setup_method0,
                            :custom_setup_method1,
                            :setup],
                           test_case)
    assert_inherited_setup([:setup], nil)
  end

  def test_setup_with_after_option
    test_case = assert_setup([:setup,
                              :custom_setup_method3,
                              :custom_setup_method0,
                              :custom_setup_method1],
                             [[{:after => :append}],
                              [{:after => :append}],
                              [{:after => :prepend}],
                              [{:after => :prepend}]])
    assert_inherited_setup([:setup,
                            :custom_setup_method3,
                            :custom_setup_method0,
                            :custom_setup_method1],
                           test_case)
    assert_inherited_setup([:setup], nil)
  end

  def test_setup_with_invalid_option
    assert_invalid_setup_option(:unknown => true)
    assert_invalid_setup_option(:before => :unknown)
    assert_invalid_setup_option(:after => :unknown)
  end

  def test_teardown_without_option
    test_case = assert_teardown([:custom_teardown_method3,
                                 :custom_teardown_method1,
                                 :custom_teardown_method0,
                                 :teardown],
                                [])
    assert_inherited_teardown([:custom_teardown_method3,
                               :custom_teardown_method1,
                               :custom_teardown_method0,
                               :teardown],
                              test_case)
    assert_inherited_teardown([:teardown], nil)
  end

  def test_teardown_with_before_option
    test_case = assert_teardown([:custom_teardown_method3,
                                 :custom_teardown_method0,
                                 :custom_teardown_method1,
                                 :teardown],
                                [[{:before => :append}],
                                 [{:before => :append}],
                                 [{:before => :prepend}],
                                 [{:before => :prepend}]])
    assert_inherited_teardown([:custom_teardown_method3,
                               :custom_teardown_method0,
                               :custom_teardown_method1,
                               :teardown],
                              test_case)
    assert_inherited_teardown([:teardown], nil)
  end

  def test_teardown_with_after_option
    test_case = assert_teardown([:teardown,
                                 :custom_teardown_method3,
                                 :custom_teardown_method0,
                                 :custom_teardown_method1],
                                [[{:after => :append}],
                                 [{:after => :append}],
                                 [{:after => :prepend}],
                                 [{:after => :prepend}]])
    assert_inherited_teardown([:teardown,
                               :custom_teardown_method3,
                               :custom_teardown_method0,
                               :custom_teardown_method1],
                              test_case)
    assert_inherited_teardown([:teardown], nil)
  end

  def test_teardown_with_invalid_option
    assert_invalid_teardown_option(:unknown => true)
    assert_invalid_teardown_option(:before => :unknown)
    assert_invalid_teardown_option(:after => :unknown)
  end

  private
  def assert_setup_customizable(expected, parent, options)
    called = []
    test_case = Class.new(parent || Test::Unit::TestCase) do
      yield(self, :before) if block_given?

      @@called = called
      def setup
        @@called << :setup
      end

      setup(*(options[0] || [])) if options
      def custom_setup_method0
        @@called << :custom_setup_method0
      end

      def custom_setup_method1
        @@called << :custom_setup_method1
      end
      setup(*[:custom_setup_method1, *(options[1] || [])]) if options

      setup(*(options[2] || [])) if options
      def custom_setup_method2
        @@called << :custom_setup_method2
      end
      unregister_setup(:custom_setup_method2) if options

      setup(*(options[3] || [])) if options
      def custom_setup_method3
        @@called << :custom_setup_method3
      end

      def test_nothing
      end

      yield(self, :after) if block_given?
    end

    test_case.new("test_nothing").run(Test::Unit::TestResult.new) {}
    assert_equal(expected, called)
    test_case
  end

  def assert_setup(expected, options)
    _test_case = assert_setup_customizable(expected, nil, options)
    assert_setup_customizable(expected, nil, options) do |test_case, tag|
      test_case.send(:include, EmptyModule) if tag == :before
    end
    _test_case
  end

  def assert_inherited_setup(expected, parent)
    _test_case = assert_setup_customizable(expected, parent, nil)
    assert_setup_customizable(expected, parent, nil) do |test_case, tag|
      test_case.send(:include, EmptyModule) if tag == :before
    end
    _test_case
  end

  def assert_teardown_customizable(expected, parent, options)
    called = []
    test_case = Class.new(parent || Test::Unit::TestCase) do
      yield(self, :before) if block_given?

      @@called = called
      def teardown
        @@called << :teardown
      end

      teardown(*(options[0] || [])) if options
      def custom_teardown_method0
        @@called << :custom_teardown_method0
      end

      def custom_teardown_method1
        @@called << :custom_teardown_method1
      end
      teardown(*[:custom_teardown_method1, *(options[1] || [])]) if options

      teardown(*(options[2] || [])) if options
      def custom_teardown_method2
        @@called << :custom_teardown_method2
      end
      unregister_teardown(:custom_teardown_method2) if options

      teardown(*(options[3] || [])) if options
      def custom_teardown_method3
        @@called << :custom_teardown_method3
      end

      def test_nothing
      end

      yield(self, :after) if block_given?
    end

    test_case.new("test_nothing").run(Test::Unit::TestResult.new) {}
    assert_equal(expected, called)
    test_case
  end

  def assert_teardown(expected, options)
    assert_teardown_customizable(expected, nil, options)
    assert_teardown_customizable(expected, nil, options) do |test_case, tag|
      test_case.send(:include, EmptyModule) if tag == :before
    end
  end

  def assert_inherited_teardown(expected, parent)
    assert_teardown_customizable(expected, parent, nil)
    assert_teardown_customizable(expected, parent, nil) do |test_case, tag|
      test_case.send(:include, EmptyModule) if tag == :before
    end
  end

  def assert_invalid_option(fixture_type, option)
    exception = assert_raise(ArgumentError) do
      Class.new(Test::Unit::TestCase) do
        def test_nothing
        end

        send(fixture_type, option)
        def fixture
        end
      end
    end
    assert_equal("must be {:before => :prepend}, {:before => :append}, " +
                 "{:after => :prepend} or {:after => :append}" +
                 ": #{option.inspect}",
                 exception.message)
  end

  def assert_invalid_setup_option(option)
    assert_invalid_option(:setup, option)
  end

  def assert_invalid_teardown_option(option)
    assert_invalid_option(:teardown, option)
  end
end

--- NEW FILE: test_notification.rb ---
require 'test/unit'
require 'testunit_test_util'

class TestNotification < Test::Unit::TestCase
  include TestUnitTestUtil

  class TestCase < Test::Unit::TestCase
    class << self
      def suite
        Test::Unit::TestSuite.new(name)
      end
    end

    def test_notify
      notify("1st notify")
      notify("2nd notify. Reach here.")
    end
  end

  def test_notify
    result = _run_test("test_notify")
    assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \
                 "0 omissions, 2 notifications",
                 result.to_s)
    assert_fault_messages(["1st notify", "2nd notify. Reach here."],
                          result.notifications)
  end

  private
  def _run_test(name)
    super(TestCase, name)
  end
end

--- NEW FILE: test_omission.rb ---
require 'test/unit'
require 'testunit_test_util'

class TestUnitOmission < Test::Unit::TestCase
  include TestUnitTestUtil

  class TestCase < Test::Unit::TestCase
    class << self
      def suite
        Test::Unit::TestSuite.new(name)
      end
    end

    def test_omit
      omit("1st omit")
      omit("2nd omit. Should not be reached here.")
      assert(true, "Should not be reached here too.")
    end

    def test_omit_with_condition
      omit_if(false, "Never omit.")
      omit_unless(true, "Never omit too.")
      omit_if(true, "Should omit.")
      omit("The last omit. Should not be reached here.")
    end

    def test_omit_with_block
      omit("Omit block") do
        flunk("Should not be reached here.")
      end
      assert(true, "Should be reached here.")
    end

    def test_omit_with_block_and_condition
      omit_if(false, "Never omit.") do
        assert(true, "Should be reached here.")
      end
      omit_if(true, "Should omit.") do
        flunk("Never reached here.")
      end
      assert(true, "Should be reached here too.")
    end
  end

  def test_omit
    result = _run_test("test_omit")
    assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \
                 "1 omissions, 0 notifications",
                 result.to_s)
    assert_fault_messages(["1st omit"], result.omissions)
  end

  def test_omit_with_condition
    result = _run_test("test_omit_with_condition")
    assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \
                 "1 omissions, 0 notifications",
                 result.to_s)
    assert_fault_messages(["Should omit."], result.omissions)
  end

  def test_omit_with_block
    result = _run_test("test_omit_with_block")
    assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, " \
                 "1 omissions, 0 notifications",
                 result.to_s)
    assert_fault_messages(["Omit block"], result.omissions)
  end

  def test_omit_with_condition_and_block
    result = _run_test("test_omit_with_block_and_condition")
    assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, " \
                 "1 omissions, 0 notifications",
                 result.to_s)
    assert_fault_messages(["Should omit."], result.omissions)
  end

  private
  def _run_test(name)
    super(TestCase, name)
  end
end

--- NEW FILE: test_pending.rb ---
require 'test/unit'
require 'testunit_test_util'

class TestUnitPending < Test::Unit::TestCase
  include TestUnitTestUtil

  class TestCase < Test::Unit::TestCase
    class << self
      def suite
        Test::Unit::TestSuite.new(name)
      end
    end

    def test_pend
      pend("1st pend")
      pend("2nd pend. Should not be reached here.")
      assert(true, "Should not be reached here too.")
    end

    def test_pend_with_failure_in_block
      pend("Wait a minute") do
        raise "Not implemented yet"
      end
      assert(true, "Reached here.")
    end

    def test_pend_with_no_failure_in_block
      pend("Wait a minute") do
        "Nothing raised"
      end
      assert(true, "Not reached here.")
    end
  end

  def test_pend
    test = nil
    result = _run_test("test_pend") {|t| test = t}
    assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 1 pendings, " \
                 "0 omissions, 0 notifications",
                 result.to_s)
    assert_fault_messages(["1st pend"], result.pendings)
    assert_true(test.interrupted?)
  end

  def test_pend_with_failure_in_block
    test = nil
    result = _run_test("test_pend_with_failure_in_block") {|t| test = t}
    assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 1 pendings, " \
                 "0 omissions, 0 notifications",
                 result.to_s)
    assert_fault_messages(["Wait a minute"], result.pendings)
    assert_false(test.interrupted?)
  end

  def test_pend_with_no_failure_in_block
    test = nil
    result = _run_test("test_pend_with_no_failure_in_block") {|t| test = t}
    assert_equal("1 tests, 1 assertions, 1 failures, 0 errors, 0 pendings, " \
                 "0 omissions, 0 notifications",
                 result.to_s)
    assert_fault_messages(["Pending block should not be passed: Wait a minute."],
                          result.failures)
    assert_true(test.interrupted?)
  end

  private
  def _run_test(name, &block)
    super(TestCase, name, &block)
  end
end

--- NEW FILE: test_priority.rb ---
require 'test/unit'

class TestUnitPriority < Test::Unit::TestCase
  class TestCase < Test::Unit::TestCase
    class << self
      def suite
        Test::Unit::TestSuite.new(name)
      end
    end

    priority :must
    def test_must
      assert(true)
    end

    def test_must_inherited
      assert(true)
    end

    priority :important
    def test_important
      assert(true)
    end

    def test_important_inherited
      assert(true)
    end

    priority :high
    def test_high
      assert(true)
    end

    def test_high_inherited
      assert(true)
    end

    priority :normal
    def test_normal
      assert(true)
    end

    def test_normal_inherited
      assert(true)
    end

    priority :low
    def test_low
      assert(true)
    end

    def test_low_inherited
      assert(true)
    end

    priority :never
    def test_never
      assert(true)
    end

    def test_never_inherited
      assert(true)
    end
  end

  def test_priority
    assert_priority("must", 1.0, 0.0001)
    assert_priority("important", 0.9, 0.09)
    assert_priority("high", 0.70, 0.1)
    assert_priority("normal", 0.5, 0.1)
    assert_priority("low", 0.25, 0.1)
    assert_priority("never", 0.0, 0.0001)
  end

  def assert_priority(priority, expected, delta)
    assert_need_to_run("test_#{priority}", expected, delta)
    assert_need_to_run("test_#{priority}_inherited", expected, delta)
  end

  def assert_need_to_run(test_name, expected, delta)
    test = TestCase.new(test_name)
    n = 1000
    n_need_to_run = 0
    n.times do |i|
      n_need_to_run +=1 if Test::Unit::Priority::Checker.need_to_run?(test)
    end
    assert_in_delta(expected, n_need_to_run.to_f / n, delta)
  end
end

--- NEW FILE: test_testcase.rb ---
# Author:: Nathaniel Talbott.
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
# License:: Ruby license.

require 'test/unit'

module Test
  module Unit
    class TC_TestCase < TestCase
      def test_creation
        tc = Class.new(TestCase) do
          def test_with_arguments(arg1, arg2)
          end
        end
      
        caught = true
        catch(:invalid_test) do
          tc.new(:test_with_arguments)
          caught = false
        end
        check("Should have caught an invalid test when there are arguments", caught)
        
        caught = true
        catch(:invalid_test) do
          tc.new(:non_existent_test)
          caught = false
        end
        check("Should have caught an invalid test when the method does not exist", caught)
      end
      
      def setup
        @tc_failure_error = Class.new(TestCase) do
          def test_failure
            assert_block("failure") { false }
          end
          def test_error
            1 / 0
          end
          def test_nested_failure
            nested
          end
          def nested
            assert_block("nested"){false}
          end
          def return_passed?
            return passed?
          end
        end

        def @tc_failure_error.name
          "TC_FailureError"
        end
      end
 
      def test_add_failed_assertion
        test_case = @tc_failure_error.new(:test_failure)
        check("passed? should start out true", test_case.return_passed?)
        result = TestResult.new
        called = false
        result.add_listener(TestResult::FAULT) {
          | fault |
          check("Should have a Failure", fault.instance_of?(Failure))
          check("The Failure should have the correct message", "failure" == fault.message)
          check("The Failure should have the correct test_name (was <#{fault.test_name}>)", fault.test_name == "test_failure(TC_FailureError)")
          r = /\A.*#{Regexp.escape(File.basename(__FILE__))}:\d+:in `test_failure'\Z/

          location = fault.location
          check("The location should be an array", location.kind_of?(Array))
          check("The location should have two lines (was: <#{location.inspect}>)", location.size == 2)
          check("The Failure should have the correct location (was <#{location[0].inspect}>, expected <#{r.inspect}>)", r =~ location[0])
          called = true
        }
        progress = []
        test_case.run(result) { |*arguments| progress << arguments }
        check("The failure should have triggered the listener", called)
        check("The failure should have set passed?", !test_case.return_passed?)
        check("The progress block should have been updated correctly", [[TestCase::STARTED, test_case.name], [TestCase::FINISHED, test_case.name]] == progress)
      end

      def test_add_failure_nested
        test_case = @tc_failure_error.new(:test_nested_failure)
        check("passed? should start out true", test_case.return_passed?)

        result = TestResult.new
        called = false
        result.add_listener(TestResult::FAULT) {
          | fault |
          check("Should have a Failure", fault.instance_of?(Failure))
          check("The Failure should have the correct message", "nested" == fault.message)
          check("The Failure should have the correct test_name (was <#{fault.test_name}>)", fault.test_name == "test_nested_failure(TC_FailureError)")
          r = 

          location = fault.location
          check("The location should be an array", location.kind_of?(Array))
          check("The location should have the correct number of lines (was: <#{location.inspect}>)", location.size == 3)
          check("The Failure should have the correct location (was <#{location[0].inspect}>)", /\A.*#{Regexp.escape(File.basename(__FILE__))}:\d+:in `nested'\Z/ =~ location[0])
          check("The Failure should have the correct location (was <#{location[1].inspect}>)", /\A.*#{Regexp.escape(File.basename(__FILE__))}:\d+:in `test_nested_failure'\Z/ =~ location[1])
          called = true
        }
        test_case.run(result){}
        check("The failure should have triggered the listener", called)
      end
      
      def test_add_error
        test_case = @tc_failure_error.new(:test_error)
        check("passed? should start out true", test_case.return_passed?)
        result = TestResult.new
        called = false
        result.add_listener(TestResult::FAULT) {
          | fault |
          check("Should have a TestError", fault.instance_of?(Error))
          check("The Error should have the correct message", "ZeroDivisionError: divided by 0" == fault.message)
          check("The Error should have the correct test_name", "test_error(TC_FailureError)" == fault.test_name)
          check("The Error should have the correct exception", fault.exception.instance_of?(ZeroDivisionError))
          called = true
        }
        test_case.run(result) {}
        check("The error should have triggered the listener", called)
        check("The error should have set passed?", !test_case.return_passed?)
      end

      def test_no_tests      
        suite = TestCase.suite
        check("Should have a test suite", suite.instance_of?(TestSuite))
        check("Should have one test", suite.size == 1)
        check("Should have the default test", suite.tests.first.name == "default_test(Test::Unit::TestCase)")
        
        result = TestResult.new
        suite.run(result) {}
        check("Should have had one test run", result.run_count == 1)
        check("Should have had one test failure", result.failure_count == 1)
        check("Should have had no errors", result.error_count == 0)
      end

      def test_suite
        tc = Class.new(TestCase) do
          def test_succeed
            assert_block {true}
          end
          def test_fail
            assert_block {false}
          end
          def test_error
            1/0
          end
          def dont_run
            assert_block {true}
          end
          def test_dont_run(argument)
            assert_block {true}
          end
          def test
            assert_block {true}
          end
        end
      
        suite = tc.suite
        check("Should have a test suite", suite.instance_of?(TestSuite))
        check("Should have three tests", suite.size == 3)
  
        result = TestResult.new
        suite.run(result) {}
        check("Should have had three test runs", result.run_count == 3)
        check("Should have had one test failure", result.failure_count == 1)
        check("Should have had one test error", result.error_count == 1)
      end
      
     
      def test_setup_teardown
        tc = Class.new(TestCase) do
          attr_reader(:setup_called, :teardown_called)
          def initialize(test)
            super(test)
            @setup_called = false
            @teardown_called = false
          end
          def setup
            @setup_called = true
          end
          def teardown
            @teardown_called = true
          end
          def test_succeed
            assert_block {true}
          end
          def test_fail
            assert_block {false}
          end
          def test_error
            raise "Error!"
          end
        end
        result = TestResult.new
  
        test = tc.new(:test_succeed)
        test.run(result) {}
        check("Should have called setup the correct number of times", test.setup_called)
        check("Should have called teardown the correct number of times", test.teardown_called)
  
        test = tc.new(:test_fail)
        test.run(result) {}
        check("Should have called setup the correct number of times", test.setup_called)
        check("Should have called teardown the correct number of times", test.teardown_called)
  
        test = tc.new(:test_error)
        test.run(result) {}
        check("Should have called setup the correct number of times", test.setup_called)
        check("Should have called teardown the correct number of times", test.teardown_called)
  
        check("Should have had two test runs", result.run_count == 3)
        check("Should have had a test failure", result.failure_count == 1)
        check("Should have had a test error", result.error_count == 1)
      end
      
      def test_assertion_failed_not_called
        tc = Class.new(TestCase) do
          def test_thing
            raise AssertionFailedError.new
          end
        end
        
        suite = tc.suite
        check("Should have one test", suite.size == 1)
        result = TestResult.new
        suite.run(result) {}
        check("Should have had one test run", result.run_count == 1)
        check("Should have had one assertion failure", result.failure_count == 1)
        check("Should not have any assertion errors but had #{result.error_count}", result.error_count == 0)
      end
      
      def test_equality
        tc1 = Class.new(TestCase) do
          def test_1
          end
          def test_2
          end
        end
        
        tc2 = Class.new(TestCase) do
          def test_1
          end
        end
      
        test1 = tc1.new('test_1')
        test2 = tc1.new('test_1')
        check("Should be equal", test1 == test2)
        check("Should be equal", test2 == test1)
        
        test1 = tc1.new('test_2')
        check("Should not be equal", test1 != test2)
        check("Should not be equal", test2 != test1)
        
        test2 = tc1.new('test_2')
        check("Should be equal", test1 == test2)
        check("Should be equal", test2 == test1)
        
        test1 = tc1.new('test_1')
        test2 = tc2.new('test_1')
        check("Should not be equal", test1 != test2)
        check("Should not be equal", test2 != test1)

        
        check("Should not be equal", test1 != Object.new)
        check("Should not be equal", Object.new != test1)
      end

      def test_re_raise_exception
        test_case = Class.new(TestCase) do
          def test_raise_interrupt
            raise Interrupt
          end
        end

        test = test_case.new("test_raise_interrupt")
        begin
          test.run(TestResult.new) {}
          check("Should not be reached", false)
        rescue Exception
          check("Interrupt exception should be re-raised", $!.class == Interrupt)
        end
      end

      def test_startup_shutdown
        called = []
        test_case = Class.new(TestCase) do
          @@called = called
          class << self
            def startup
              @@called << :startup
            end

            def shutdown
              @@called << :shutdown
            end
          end

          def setup
            @@called << :setup
          end

          def teardown
            @@called << :teardown
          end

          def test1
          end

          def test2
          end
        end

        test_suite = test_case.suite
        test_suite.run(TestResult.new) {}
        check("startup/shutdown should be called once per test case" +
              ": #{called.inspect}",
              called == [:startup,
                         :setup, :teardown,
                         :setup, :teardown,
                         :shutdown])
      end

      def test_error_on_startup
        test_case = Class.new(TestCase) do
          class << self
            def startup
              raise "from startup"
            end
          end

          def test_nothing
          end
        end

        test_suite = test_case.suite
        result = TestResult.new
        test_suite.run(result) {}
        check("Should record an error on startup: #{result}",
              result.error_count == 1)
      end

      def test_pass_through_error_on_startup
        test_case = Class.new(TestCase) do
          class << self
            def startup
              raise Interrupt
            end
          end

          def test_nothing
          end
        end

        test_suite = test_case.suite
        begin
          test_suite.run(TestResult.new) {}
          check("Should not be reached", false)
        rescue Exception
          check("Interrupt should be passed through: #{$!}",
                Interrupt === $!)
        end
      end

      def test_error_on_shutdown
        test_case = Class.new(TestCase) do
          class << self
            def shutdown
              raise "from shutdown"
            end
          end

          def test_nothing
          end
        end

        test_suite = test_case.suite
        result = TestResult.new
        test_suite.run(result) {}
        check("Should record an error on shutdown: #{result}",
              result.error_count == 1)
      end

      def test_pass_through_error_on_shutdown
        test_case = Class.new(TestCase) do
          class << self
            def shutdown
              raise Interrupt
            end
          end

          def test_nothing
          end
        end

        test_suite = test_case.suite
        begin
          test_suite.run(TestResult.new) {}
          check("Should not be reached", false)
        rescue Exception
          check("Interrupt should be passed through: #{$!}",
                Interrupt === $!)
        end
      end

      def test_interrupted
        test_case = Class.new(TestCase) do
          def test_fail
            flunk
          end

          def test_nothing
          end
        end

        failed_test = test_case.new(:test_fail)
        failed_test.run(TestResult.new) {}
        check("Should be interrupted", failed_test.interrupted?)

        success_test = test_case.new(:test_nothing)
        success_test.run(TestResult.new) {}
        check("Should not be interrupted", !success_test.interrupted?)
      end

      private
      def check(message, passed)
        add_assertion
        raise AssertionFailedError.new(message) unless passed
      end
    end
  end
end

--- NEW FILE: test_testresult.rb ---
# Author:: Nathaniel Talbott.
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
# License:: Ruby license.

require 'test/unit/testcase'
require 'test/unit/testresult'

module Test
  module Unit
    class TC_TestResult < TestCase
      def setup
        @my_result = TestResult.new
        @my_result.add_assertion()
        @failure = "failure"
        @my_result.add_failure(@failure)
        @error = "error"
        @my_result.add_error(@error)
      end

      def test_result_changed_notification
        called1 = false
        @my_result.add_listener(TestResult::CHANGED) do |result|
          assert_equal(@my_result, result)
          called1 = true
        end
        @my_result.add_assertion
        assert_true(called1)

        called1, called2 = false, false
        @my_result.add_listener(TestResult::CHANGED) do |result|
          assert_equal(@my_result, result)
          called2 = true
        end
        @my_result.add_assertion
        assert_equal([true, true], [called1, called2])

        called1, called2 = false, false
        @my_result.add_failure("")
        assert_equal([true, true], [called1, called2])

        called1, called2 = false, false
        @my_result.add_error("")
        assert_equal([true, true], [called1, called2])

        called1, called2 = false, false
        @my_result.add_run
        assert_equal([true, true], [called1, called2])
      end

      def test_fault_notification
        called1 = false
        fault = "fault"
        @my_result.add_listener(TestResult::FAULT) do |passed_fault|
          assert_equal(fault, passed_fault)
          called1 = true
        end

        @my_result.add_assertion
        assert_false(called1)

        @my_result.add_failure(fault)
        assert_true(called1)

        called1, called2 = false, false
        @my_result.add_listener(TestResult::FAULT) do |passed_fault|
          assert_equal(fault, passed_fault)
          called2 = true
        end

        @my_result.add_assertion
        assert_equal([false, false], [called1, called2])

        called1, called2 = false, false
        @my_result.add_failure(fault)
        assert_equal([true, true], [called1, called2])

        called1, called2 = false, false
        @my_result.add_error(fault)
        assert_equal([true, true], [called1, called2])

        called1, called2 = false, false
        @my_result.add_run
        assert_equal([false, false], [called1, called2])
      end

      def test_passed?
        result = TestResult.new
        assert_true(result.passed?)

        result.add_assertion
        assert_true(result.passed?)

        result.add_run
        assert_true(result.passed?)

        result.add_failure("")
        assert_false(result.passed?)

        result = TestResult.new
        result.add_error("")
        assert_false(result.passed?)
      end

      def test_faults
        assert_equal([@failure, @error], @my_result.faults)

        notification = "notification"
        @my_result.add_notification(notification)
        assert_equal([@failure, @error, notification], @my_result.faults)
      end
    end
  end
end

--- NEW FILE: test_testsuite.rb ---
# Author:: Nathaniel Talbott.
# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
# License:: Ruby license.

require 'test/unit'

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_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
        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
        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

--- NEW FILE: testunit_test_util.rb ---
module TestUnitTestUtil
  private
  def assert_fault_messages(expected, faults)
    assert_equal(expected, faults.collect {|fault| fault.message})
  end

  def _run_test(test_case, name)
    result = Test::Unit::TestResult.new
    test = test_case.new(name)
    yield(test) if block_given?
    test.run(result) {}
    result
  end
end



More information about the cairo-commit mailing list