diff options
author | Nobuyoshi Nakada <[email protected]> | 2023-04-29 00:48:24 +0900 |
---|---|---|
committer | git <[email protected]> | 2023-04-28 16:09:20 +0000 |
commit | 966f0d91e2a86fa1347cdafbe1af47e7350aa4ca (patch) | |
tree | 956cd10c444c1833979c253c1896e370785f109d /test/lib/find_executable.rb | |
parent | 74028c210c23a13b3168886efcf837b4bf930468 (diff) |
[ruby/rdoc] Update test libraries from ruby/ruby 2023-04-29
From https://github.com/ruby/ruby/commit/74028c210c23a13b3168886efcf837b4bf930468
https://github.com/ruby/rdoc/commit/badc518c57
Diffstat (limited to 'test/lib/find_executable.rb')
-rw-r--r-- | test/lib/find_executable.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/lib/find_executable.rb b/test/lib/find_executable.rb new file mode 100644 index 0000000000..89c6fb8f3b --- /dev/null +++ b/test/lib/find_executable.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true +require "rbconfig" + +module EnvUtil + def find_executable(cmd, *args) + exts = RbConfig::CONFIG["EXECUTABLE_EXTS"].split | [RbConfig::CONFIG["EXEEXT"]] + ENV["PATH"].split(File::PATH_SEPARATOR).each do |path| + next if path.empty? + path = File.join(path, cmd) + exts.each do |ext| + cmdline = [path + ext, *args] + begin + return cmdline if yield(IO.popen(cmdline, "r", err: [:child, :out], &:read)) + rescue + next + end + end + end + nil + end + module_function :find_executable +end |