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