1
0
Fork 0
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:
Nobuyoshi Nakada 2021-09-17 08:54:18 +09:00
parent 8450b6a91d
commit 34d6720fee
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
Notes: git 2021-09-17 09:43:47 +09:00
2 changed files with 5 additions and 10 deletions

View file

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

View file

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