mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Prohibit test method redefinition
This commit is contained in:
parent
8450b6a91d
commit
34d6720fee
Notes:
git
2021-09-17 09:43:47 +09:00
2 changed files with 5 additions and 10 deletions
|
@ -337,7 +337,7 @@ module Test
|
|||
return unless name.to_s.start_with?("test_")
|
||||
@test_methods ||= {}
|
||||
if @test_methods[name]
|
||||
warn "test/unit warning: method #{ self }##{ name } is redefined"
|
||||
raise AssertionFailedError, "test/unit: method #{ self }##{ name } is redefined"
|
||||
end
|
||||
@test_methods[name] = true
|
||||
end
|
||||
|
|
|
@ -3,14 +3,9 @@ require 'test/unit'
|
|||
|
||||
class TestRedefinition < Test::Unit::TestCase
|
||||
def test_redefinition
|
||||
assert_match(/^test\/unit warning: method TestForTestRedefinition#test_redefinition is redefined$/,
|
||||
redefinition)
|
||||
end
|
||||
|
||||
def redefinition(*args)
|
||||
IO.popen([*@options[:ruby], "#{File.dirname(__FILE__)}/test4test_redefinition.rb", *args],
|
||||
err: [:child, :out]) {|f|
|
||||
f.read
|
||||
}
|
||||
message = %r[test/unit: method TestForTestRedefinition#test_redefinition is redefined$]
|
||||
assert_raise_with_message(Test::Unit::AssertionFailedError, message) do
|
||||
require_relative("test4test_redefinition.rb")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue