From kou ¡÷ clear-code.com Sun Jun 12 00:29:24 2011 From: kou ¡÷ clear-code.com (Kouhei Sutou) Date: Sun, 12 Jun 2011 04:29:24 +0000 Subject: [test-unit-commit:00050] test-unit/test-unit [master] fix implicit method name overide by declarative style test definition. Message-ID: <20110612043017.CD65E2C410E@taiyaki.ru> Kouhei Sutou 2011-06-12 04:29:24 +0000 (Sun, 12 Jun 2011) New Revision: d235a90d7bff4f81630ed5fa2a5cc591ddb8fa29 Log: fix implicit method name overide by declarative style test definition. fixes #3 Reported by Jeremy Stephens. Thanks!!! Modified files: README.txt lib/test/unit/testcase.rb test/test-testcase.rb Modified: README.txt (+1 -0) =================================================================== --- README.txt 2011-05-13 00:41:43 +0000 (4492546) +++ README.txt 2011-06-12 04:29:24 +0000 (d8f29c6) @@ -75,3 +75,4 @@ Ruby license and PSF license. * Champak Ch: A bug report. * Florian Frank: A bug report. * grafi-tt: A bug fix. +* Jeremy Stephens: A bug report. Modified: lib/test/unit/testcase.rb (+1 -1) =================================================================== --- lib/test/unit/testcase.rb 2011-05-13 00:41:43 +0000 (911648b) +++ lib/test/unit/testcase.rb 2011-06-12 04:29:24 +0000 (51e8b78) @@ -257,7 +257,7 @@ module Test message = "wrong number of arguments (#{n_arguments} for 1)" raise ArgumentError, message end - method_name = test_description + method_name = "test: #{test_description}" define_method(method_name, &block) description(test_description, method_name) attribute(:test, true, {}, method_name) Modified: test/test-testcase.rb (+3 -3) =================================================================== --- test/test-testcase.rb 2011-05-13 00:41:43 +0000 (025d19d) +++ test/test-testcase.rb 2011-06-12 04:29:24 +0000 (e7c3385) @@ -506,9 +506,9 @@ module Test test_case.test_order = :defined - assert_equal(["declarative style test definition", - "include parenthesis", - "1 + 2 = 3"], + assert_equal(["test: declarative style test definition", + "test: include parenthesis", + "test: 1 + 2 = 3"], test_case.suite.tests.collect {|test| test.method_name}) assert_equal(["declarative style test definition", From kou ¡÷ clear-code.com Mon Jun 13 01:59:47 2011 From: kou ¡÷ clear-code.com (Kouhei Sutou) Date: Mon, 13 Jun 2011 05:59:47 +0000 Subject: [test-unit-commit:00051] test-unit/test-unit [master] support recursive references. Message-ID: <20110613060040.D6DA02C415B@taiyaki.ru> Kouhei Sutou 2011-06-13 05:59:47 +0000 (Mon, 13 Jun 2011) New Revision: 453a45df7fda06d1a2170bb79299daab3716b922 Log: support recursive references. Modified files: lib/test/unit/assertions.rb test/test-assertions.rb Modified: lib/test/unit/assertions.rb (+4 -0) =================================================================== --- lib/test/unit/assertions.rb 2011-06-12 04:29:24 +0000 (aedf418) +++ lib/test/unit/assertions.rb 2011-06-13 05:59:47 +0000 (b7a4f89) @@ -1543,6 +1543,10 @@ EOM @inspect_target.pretty_print_cycle(q) end + def object_id + @object.object_id + end + private def inspect_target if HashInspector.target?(@object) Modified: test/test-assertions.rb (+20 -0) =================================================================== --- test/test-assertions.rb 2011-06-12 04:29:24 +0000 (2fed77c) +++ test/test-assertions.rb 2011-06-13 05:59:47 +0000 (9f8ad7c) @@ -356,6 +356,26 @@ EOM end end + def test_assert_equal_with_recursive_hash + alice = {"name" => "Alice"} + bob = {"name" => "Bob"} + alice["followers"] = [bob] + bob["followers"] = [alice] + message = <<-EOM.chomp +<{"followers"=>[{"followers"=>[{...}], "name"=>"Bob"}], "name"=>"Alice"}> expected but was +<{"followers"=>[{"followers"=>[{...}], "name"=>"Alice"}], "name"=>"Bob"}>. + +diff: +- {"followers"=>[{"followers"=>[{...}], "name"=>"Bob"}], "name"=>"Alice"} +? ----------------- ++ {"followers"=>[{"followers"=>[{...}], "name"=>"Alice"}], "name"=>"Bob"} +? +++++++++++++++++ +EOM + check_fails(message) do + assert_equal(alice, bob) + end + end + def test_assert_raise_success return_value = nil check_nothing_fails(true) do From kou ¡÷ clear-code.com Mon Jun 13 03:28:52 2011 From: kou ¡÷ clear-code.com (Kouhei Sutou) Date: Mon, 13 Jun 2011 07:28:52 +0000 Subject: [test-unit-commit:00052] test-unit/test-unit [master] don't override object_id. Message-ID: <20110613072945.4B8A52C415B@taiyaki.ru> Kouhei Sutou 2011-06-13 07:28:52 +0000 (Mon, 13 Jun 2011) New Revision: 33449f562455bb671bc13124926ae9f9a1896d4f Log: don't override object_id. Modified files: lib/test/unit/assertions.rb Modified: lib/test/unit/assertions.rb (+37 -15) =================================================================== --- lib/test/unit/assertions.rb 2011-06-13 05:59:47 +0000 (b7a4f89) +++ lib/test/unit/assertions.rb 2011-06-13 07:28:52 +0000 (bb2f371) @@ -1525,8 +1525,20 @@ EOM end class Inspector - def initialize(object) + include Comparable + + class << self + def cached_new(object, inspected_objects) + inspected_objects[object.object_id] ||= + new(object, inspected_objects) + end + end + + attr_reader :object + def initialize(object, inspected_objects={}) + @inspected_objects = inspected_objects @object = object + @inspected_objects[@object.object_id] = self @inspect_target = inspect_target end @@ -1543,16 +1555,20 @@ EOM @inspect_target.pretty_print_cycle(q) end - def object_id - @object.object_id + def <=>(other) + if other.is_a?(self.class) + @object <=> other.object + else + @object <=> other + end end private def inspect_target if HashInspector.target?(@object) - HashInspector.new(@object) + HashInspector.new(@object, @inspected_objects) elsif ArrayInspector.target?(@object) - ArrayInspector.new(@object) + ArrayInspector.new(@object, @inspected_objects) else @object end @@ -1566,8 +1582,14 @@ EOM end end - def initialize(hash) - @hash = hash + def initialize(hash, inspected_objects) + @inspected_objects = inspected_objects + @hash = {} + hash.each do |key, value| + key = Inspector.cached_new(key, @inspected_objects) + value = Inspector.cached_new(value, @inspected_objects) + @hash[key] = value + end end def inspect @@ -1600,8 +1622,7 @@ EOM rescue ArgumentError end keys.each do |key| - yield(Inspector.new(key), - Inspector.new(@hash[key])) + yield(key, @hash[key]) end end end @@ -1613,8 +1634,11 @@ EOM end end - def initialize(array) - @array = array + def initialize(array, inspected_objects) + @inspected_objects = inspected_objects + @array = array.collect do |element| + Inspector.cached_new(element, @inspected_objects) + end end def inspect @@ -1633,10 +1657,8 @@ EOM @array.pretty_print_cycle(q) end - def each - @array.each do |element| - yield(Inspector.new(element)) - end + def each(&block) + @array.each(&block) end end