diff options
Diffstat (limited to 'test/reline')
-rw-r--r-- | test/reline/helper.rb | 41 | ||||
-rw-r--r-- | test/reline/test_reline.rb | 2 |
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 |