aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--io.c16
-rw-r--r--test/ruby/test_io.rb5
2 files changed, 8 insertions, 13 deletions
diff --git a/io.c b/io.c
index a8ed4f0433..24f721e8fd 100644
--- a/io.c
+++ b/io.c
@@ -7088,17 +7088,11 @@ rb_io_open_generic(VALUE klass, VALUE filename, int oflags, int fmode,
const convconfig_t *convconfig, mode_t perm)
{
VALUE cmd;
- if (!NIL_P(cmd = check_pipe_command(filename))) {
- if (klass != rb_cIO) {
- ID func = rb_frame_this_func();
- VALUE fname = rb_id2str(func);
- static const char MSG[] = "IO.%"PRIsVALUE" called on %"PRIsVALUE" to invoke external command";
- if (klass == rb_cFile) {
- rb_warn(MSG, fname, klass);
- }
- else {
- rb_raise(rb_eArgError, MSG, fname, klass);
- }
+ const int warn = klass == rb_cFile;
+ if ((warn || klass == rb_cIO) && !NIL_P(cmd = check_pipe_command(filename))) {
+ if (warn) {
+ rb_warn("IO.%"PRIsVALUE" called on File to invoke external command",
+ rb_id2str(rb_frame_this_func()));
}
return pipe_open_s(cmd, rb_io_oflags_modestr(oflags), fmode, convconfig);
}
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 4f6027d8c9..bb16953e99 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -2185,16 +2185,17 @@ class TestIO < Test::Unit::TestCase
end
def test_read_command
+ assert_equal("foo\n", IO.read("|echo foo"))
assert_warn(/invoke external command/) do
File.read("|#{EnvUtil.rubybin} -e puts")
end
assert_warn(/invoke external command/) do
File.binread("|#{EnvUtil.rubybin} -e puts")
end
- assert_raise_with_message(ArgumentError, /invoke external command/) do
+ assert_raise(Errno::ENOENT) do
Class.new(IO).read("|#{EnvUtil.rubybin} -e puts")
end
- assert_raise_with_message(ArgumentError, /invoke external command/) do
+ assert_raise(Errno::ENOENT) do
Class.new(IO).binread("|#{EnvUtil.rubybin} -e puts")
end
end