Skip to content

Commit 8ac9690

Browse files
authored
test_configdsl: fix test using pipe command (#5159)
**Which issue(s) this PR fixes**: Fixes #5148 **What this PR does / why we need it**: 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>' ``` This path will save the command's result in temporary files and use them instead due to avoid the error. **Docs Changes**: N/A **Release Note**: N/A Signed-off-by: Shizuo Fujita <[email protected]>
1 parent 08f8c24 commit 8ac9690

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

test/test_configdsl.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/dsl'
33
require 'fluent/test'
4+
require 'tempfile'
45

56
class ConfigDSLTest < Test::Unit::TestCase
67
# TEST_CONFIG1 = %[
@@ -107,8 +108,12 @@ def test_config_error
107108

108109
def test_with_ruby_keyword
109110
uname_string = `uname -a`
111+
tmpfile = Tempfile.create('fluentd-test')
112+
tmpfile.write(uname_string)
113+
tmpfile.close
114+
110115
root1 = Fluent::Config::DSL::Parser.parse(<<DSL)
111-
uname_str = ruby.open('|uname -a'){|out| out.read}
116+
uname_str = ruby.open("#{tmpfile.path}"){|out| out.read}
112117
source {
113118
uname uname_str
114119
}
@@ -144,5 +149,7 @@ def test_with_ruby_keyword
144149
}
145150
DSL
146151
assert_raise (NoMethodError) { Fluent::Config::DSL::Parser.parse(conf3) }
152+
ensure
153+
File.delete(tmpfile.path)
147154
end
148155
end

0 commit comments

Comments
 (0)