Skip to content

Commit 7ba2227

Browse files
authored
test_dsl: fix test using pipe command (#5160)
**Which issue(s) this PR fixes**: Fixes #5148 **What this PR does / why we need it**: Related to #5159 I overlooked the fact that there were also tests using pipe commands in another file. Since Ruby 4.0, When we give pipe command in `Kernel.open`, it causes an error. ``` $ ruby -w -v -e "Kernel.open('| uname -a'){|out| p out.read }" ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x86_64-linux] -e:1: warning: Calling Kernel#open with a leading '|' is deprecated and will be removed in Ruby 4.0; use IO.popen instead "Linux UM890 6.17.1-0-MANJARO #1 SMP PREEMPT_DYNAMIC Tue, 07 Oct 2025 07:57:35 +0000 x86_64 GNU/Linux\n" $ ruby -w -v -e "Kernel.open('| uname -a'){|out| p out.read }" ruby 4.0.0dev (2025-11-20T00:03:23Z master 167c3dbaa0) +PRISM [x86_64-linux] -e:1:in 'File#initialize': No such file or directory @ rb_sysopen - | uname -a (Errno::ENOENT) from -e:1:in 'Kernel.open' from -e:1:in '<main>' ``` **Docs Changes**: N/A **Release Note**: N/A Signed-off-by: Shizuo Fujita <[email protected]>
1 parent 8ac9690 commit 7ba2227

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

test/config/test_dsl.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require_relative '../helper'
22
require 'fluent/config/element'
33
require "fluent/config/dsl"
4+
require 'tempfile'
45

56
TMP_DIR = File.dirname(__FILE__) + "/tmp/config_dsl#{ENV['TEST_ENV_NUMBER']}"
67
def write_config(path, data)
@@ -358,9 +359,13 @@ def setup
358359
sub_test_case '.parse' do
359360
test 'can get result of Kernel.open() by ruby.open()' do
360361
uname_string = `uname -a`
362+
tmpfile = Tempfile.create('fluentd-test')
363+
tmpfile.write(uname_string)
364+
tmpfile.close
365+
361366
root = Fluent::Config::DSL::Parser.parse(<<DSL)
362367
worker {
363-
uname_str = ruby.open('|uname -a'){|out| out.read}
368+
uname_str = ruby.open("#{tmpfile.path}"){|out| out.read}
364369
source {
365370
uname uname_str
366371
}
@@ -372,6 +377,8 @@ def setup
372377
assert_equal('source', source.name)
373378
assert_equal(1, source.keys.size)
374379
assert_equal(uname_string, source['uname'])
380+
ensure
381+
File.delete(tmpfile.path)
375382
end
376383

377384
test 'accepts ruby keyword with block, which allow to use methods included from ::Kernel' do

0 commit comments

Comments
 (0)