mirror of
https://github.com/ruby/ruby.git
synced 2025-08-26 22:45:03 +02:00
[Bug #20510] Do not count optional hash argument for IO.new
Since `IO.new` accepts one or two positional arguments except for the optional hash argument, exclude the optional hash argument from the check for delegation to `IO.new`.
This commit is contained in:
parent
4d0c5486a2
commit
0bae2f0002
3 changed files with 64 additions and 34 deletions
|
@ -460,6 +460,39 @@ class TestFile < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
Dir.mktmpdir(__method__.to_s) do |tmpdir|
|
||||
path = File.join(tmpdir, "foo")
|
||||
|
||||
assert_raise(Errno::ENOENT) {File.new(path)}
|
||||
f = File.new(path, "w")
|
||||
f.write("FOO\n")
|
||||
f.close
|
||||
f = File.new(path)
|
||||
data = f.read
|
||||
f.close
|
||||
assert_equal("FOO\n", data)
|
||||
|
||||
f = File.new(path, File::WRONLY)
|
||||
f.write("BAR\n")
|
||||
f.close
|
||||
f = File.new(path, File::RDONLY)
|
||||
data = f.read
|
||||
f.close
|
||||
assert_equal("BAR\n", data)
|
||||
|
||||
data = File.open(path) {|file|
|
||||
File.new(file.fileno, mode: File::RDONLY, autoclose: false).read
|
||||
}
|
||||
assert_equal("BAR\n", data)
|
||||
|
||||
data = File.open(path) {|file|
|
||||
File.new(file.fileno, File::RDONLY, autoclose: false).read
|
||||
}
|
||||
assert_equal("BAR\n", data)
|
||||
end
|
||||
end
|
||||
|
||||
def test_file_open_newline_option
|
||||
Dir.mktmpdir(__method__.to_s) do |tmpdir|
|
||||
path = File.join(tmpdir, "foo")
|
||||
|
|
|
@ -2929,6 +2929,15 @@ class TestIO < Test::Unit::TestCase
|
|||
f.close
|
||||
|
||||
assert_equal("FOO\n", File.read(t.path))
|
||||
|
||||
fd = IO.sysopen(t.path)
|
||||
%w[w r+ w+ a+].each do |mode|
|
||||
assert_raise(Errno::EINVAL, "#{mode} [ruby-dev:38571]") {IO.new(fd, mode)}
|
||||
end
|
||||
f = IO.new(fd, "r")
|
||||
data = f.read
|
||||
f.close
|
||||
assert_equal("FOO\n", data)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue