summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSorah Fukumori <her@sorah.jp>2023-02-06 04:38:33 +0900
committergit <svn-admin@ruby-lang.org>2023-02-05 20:31:37 +0000
commit8a29419b7fb723b3faf04b3d9a3cb0740213d946 (patch)
tree46fcb611d49ec47ff01b3dd5f66073b30e58feca
parent8a474b344ea78fcf8a8ea3dac6c6efcf329c2fb9 (diff)
[ruby/reline] test_dumb_terminal: "ruby" command is not always available
Fixes the same issue at https://github.com/ruby/ruby/pull/5417 `ruby` is not always available in certain build environments and configure options (e.g. --program-suffix) This patch tries to choose an appropriate command line for spawning a fresh Ruby process, based on EnvUtil implementation in ruby/ruby's test suite. Plus when this library is directly mirrored into ruby/ruby, prefer EnvUtil available there over the implementation in this library's test suite. https://github.com/ruby/reline/commit/278327d2e9
-rw-r--r--test/reline/helper.rb41
-rw-r--r--test/reline/test_reline.rb2
2 files changed, 42 insertions, 1 deletions
diff --git a/test/reline/helper.rb b/test/reline/helper.rb
index e3ce318c44..c2a47a79d1 100644
--- a/test/reline/helper.rb
+++ b/test/reline/helper.rb
@@ -5,6 +5,19 @@ ENV['TERM'] = 'xterm' # for some CI environments
require 'reline'
require 'test/unit'
+begin
+ require 'rbconfig'
+rescue LoadError
+end
+
+begin
+ # This should exist and available in load path when this file is mirrored to ruby/ruby and running at there
+ if File.exist?(File.expand_path('../../tool/lib/envutil.rb', __dir__))
+ require 'envutil'
+ end
+rescue LoadError
+end
+
module Reline
class <<self
def test_mode(ansi: false)
@@ -25,6 +38,34 @@ module Reline
const_set('IOGate', Reline::GeneralIO)
Reline.instance_variable_set(:@core, nil)
end
+
+ # Return a executable name to spawn Ruby process. In certain build configuration,
+ # "ruby" may not be available.
+ def test_rubybin
+ # When this test suite is running in ruby/ruby, prefer EnvUtil result over original implementation
+ if const_defined?(:EnvUtil)
+ return EnvUtil.rubybin
+ end
+
+ # The following is a simplified port of EnvUtil.rubybin in ruby/ruby
+ if ruby = ENV["RUBY"]
+ return ruby
+ end
+ ruby = "ruby"
+ exeext = RbConfig::CONFIG["EXEEXT"]
+ rubyexe = (ruby + exeext if exeext and !exeext.empty?)
+ if File.exist? ruby and File.executable? ruby and !File.directory? ruby
+ return File.expand_path(ruby)
+ end
+ if rubyexe and File.exist? rubyexe and File.executable? rubyexe
+ return File.expand_path(rubyexe)
+ end
+ if defined?(RbConfig.ruby)
+ RbConfig.ruby
+ else
+ "ruby"
+ end
+ end
end
end
diff --git a/test/reline/test_reline.rb b/test/reline/test_reline.rb
index e58accb3a7..9692605a00 100644
--- a/test/reline/test_reline.rb
+++ b/test/reline/test_reline.rb
@@ -370,7 +370,7 @@ class Reline::Test < Reline::TestCase
def test_dumb_terminal
lib = File.expand_path("../../lib", __dir__)
- out = IO.popen([{"TERM"=>"dumb"}, "ruby", "-I#{lib}", "-rreline", "-e", "p Reline::IOGate"], &:read)
+ out = IO.popen([{"TERM"=>"dumb"}, Reline.test_rubybin, "-I#{lib}", "-rreline", "-e", "p Reline::IOGate"], &:read)
assert_equal("Reline::GeneralIO", out.chomp)
end