summaryrefslogtreecommitdiff
path: root/test/dtrace/helper.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-06-30 18:41:17 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-06-30 20:56:49 +0900
commit3b86ec22515853665c353f2fb14e5bdb10b2e65b (patch)
treea77fa323d6b70aed97f435fac8ad31802c791b9a /test/dtrace/helper.rb
parent126cf11d338d6ca8b78a5a425652167d8aacc222 (diff)
dtrace: check for the command availablity with sudo
Diffstat (limited to 'test/dtrace/helper.rb')
-rw-r--r--test/dtrace/helper.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/test/dtrace/helper.rb b/test/dtrace/helper.rb
index 023d1165b4..7b382e86ca 100644
--- a/test/dtrace/helper.rb
+++ b/test/dtrace/helper.rb
@@ -52,7 +52,17 @@ else
warn "don't know how to check if built with #{impl} support"
cmd = false
end
-ok &= system(*cmd, err: IO::NULL, out: IO::NULL) if cmd
+
+NEEDED_ENVS = [RbConfig::CONFIG["LIBPATHENV"], "RUBY", "RUBYOPT"].compact
+
+if cmd and ok
+ sudocmd = []
+ if sudo
+ sudocmd << sudo
+ NEEDED_ENVS.each {|name| val = ENV[name] and sudocmd << "#{name}=#{val}"}
+ end
+ ok = system(*sudocmd, *cmd, err: IO::NULL, out: IO::NULL)
+end
module DTrace
class TestCase < Test::Unit::TestCase
@@ -136,8 +146,8 @@ module DTrace
cmd = [*DTRACE_CMD, "-q", "-s", d_path, "-c", cmd ]
end
if sudo = @@sudo
- [RbConfig::CONFIG["LIBPATHENV"], "RUBY", "RUBYOPT"].each do |name|
- if name and val = ENV[name]
+ NEEDED_ENVS.each do |name|
+ if val = ENV[name]
cmd.unshift("#{name}=#{val}")
end
end