1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Kernel#open may be redefined

This commit is contained in:
Nobuyoshi Nakada 2019-09-27 01:13:10 +09:00
parent 617fa3049a
commit 81191afe8a
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60

View file

@ -2283,14 +2283,25 @@ class TestIO < Test::Unit::TestCase
o = Object.new o = Object.new
def o.to_open(**kw); kw; end def o.to_open(**kw); kw; end
assert_equal({:a=>1}, open(o, a: 1)) assert_equal({:a=>1}, open(o, a: 1))
assert_warn(/The last argument is used as the keyword parameter.*for `to_open'/m) do
w = /The last argument is used as the keyword parameter.*for `(to_)?open'/m
redefined = nil
w.singleton_class.define_method(:===) do |s|
match = super(s)
redefined = !$1
match
end
assert_warn(w) do
assert_equal({:a=>1}, open(o, {a: 1})) assert_equal({:a=>1}, open(o, {a: 1}))
end end
def o.to_open(kw); kw; end def o.to_open(kw); kw; end
assert_equal({:a=>1}, open(o, a: 1)) assert_equal({:a=>1}, open(o, a: 1))
unless redefined
assert_equal({:a=>1}, open(o, {a: 1})) assert_equal({:a=>1}, open(o, {a: 1}))
end end
end
def test_open_pipe def test_open_pipe
open("|" + EnvUtil.rubybin, "r+") do |f| open("|" + EnvUtil.rubybin, "r+") do |f|