diff options
author | Hiroshi SHIBATA <[email protected]> | 2023-02-22 09:44:53 +0900 |
---|---|---|
committer | git <[email protected]> | 2023-02-22 01:18:25 +0000 |
commit | 1ddda4c0d7d2b83658ab149e36e088961ca0b2dc (patch) | |
tree | aaffd7da9f5c87e5186f7023e5f0faed13f49149 /test/lib/find_executable.rb | |
parent | ae9e1aee59b0db1e61aa0473556165f9fd719cde (diff) |
[ruby/readline-ext] Import EnvUtils and related test libraries
https://github.com/ruby/readline-ext/commit/f034697a48
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 |