From 7773a911f5bd0b171ae0bc6c62dbf6ca58360776 Mon Sep 17 00:00:00 2001 From: sorah Date: Sat, 21 Jul 2012 05:12:32 +0000 Subject: [PATCH] * lib/test/unit.rb: warn when test_* method is redefined. Patch by mame (Yusuke Endoh). [Feature #2643] [ruby-core:27790] * test/testunit/test_redefinition.rb: Test for above. * test/testunit/test4test_redefinition.rb: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36484 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ lib/test/unit/testcase.rb | 11 +++++++++++ test/testunit/test4test_redefinition.rb | 11 +++++++++++ test/testunit/test_redefinition.rb | 13 +++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 test/testunit/test4test_redefinition.rb create mode 100644 test/testunit/test_redefinition.rb diff --git a/ChangeLog b/ChangeLog index f9fc87042b..87e44fe083 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Sat Jul 21 14:06:41 2012 Shota Fukumori + + * lib/test/unit.rb: warn when test_* method is redefined. + Patch by mame (Yusuke Endoh). [Feature #2643] [ruby-core:27790] + + * test/testunit/test_redefinition.rb: Test for above. + + * test/testunit/test4test_redefinition.rb: Ditto. + Sat Jul 21 08:41:14 2012 Eric Hodel * lib/logger.rb: Updated example in Logger comment to match other diff --git a/lib/test/unit/testcase.rb b/lib/test/unit/testcase.rb index 02f0f97987..11f34b6f51 100644 --- a/lib/test/unit/testcase.rb +++ b/lib/test/unit/testcase.rb @@ -20,6 +20,17 @@ module Test def self.test_order :sorted end + + Methods = {} + + def self.method_added(name) + return unless name.to_s[/\Atest_/] + Methods[self] ||= {} + if Methods[self][name] + warn("test/unit warning: method #{ self }##{ name } is redefined") + end + Methods[self][name] = true + end end end end diff --git a/test/testunit/test4test_redefinition.rb b/test/testunit/test4test_redefinition.rb new file mode 100644 index 0000000000..72c4cb225a --- /dev/null +++ b/test/testunit/test4test_redefinition.rb @@ -0,0 +1,11 @@ +require 'test/unit' + +class TestForTestRedefinition < Test::Unit::TestCase + def test_redefinition + skip "do nothing (1)" + end + + def test_redefinition + skip "do nothing (2)" + end +end diff --git a/test/testunit/test_redefinition.rb b/test/testunit/test_redefinition.rb new file mode 100644 index 0000000000..612661ee65 --- /dev/null +++ b/test/testunit/test_redefinition.rb @@ -0,0 +1,13 @@ +require 'test/unit' + +class TestHideSkip < Test::Unit::TestCase + def test_hideskip + test_out, o = IO.pipe + spawn(*@options[:ruby], "#{File.dirname(__FILE__)}/test4test_redefinition.rb", out: File::NULL, err: o) + o.close + + assert_match /^test\/unit warning: method TestForTestRedefinition#test_redefinition is redefined$/, + test_out.read + test_out.close + end +end