Skip to content

Commit

Permalink
Prohibit test method redefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Sep 16, 2021
1 parent 8450b6a commit 34d6720
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tool/lib/test/unit/testcase.rb
Expand Up @@ -337,7 +337,7 @@ def self.method_added(name)
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
Expand Down
13 changes: 4 additions & 9 deletions tool/test/testunit/test_redefinition.rb
Expand Up @@ -3,14 +3,9 @@

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

0 comments on commit 34d6720

Please sign in to comment.