Skip to content

Commit

Permalink
Inject reline gem path into assert_in_out_err
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Jan 24, 2025
1 parent 1ef78ae commit cf5e61e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion test/irb/test_option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def test_end_of_option
bug4117 = '[ruby-core:33574]'
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
libdir = File.expand_path("../../lib", __dir__)
status = assert_in_out_err(bundle_exec + %W[-W0 -I#{libdir} -rirb -e IRB.start(__FILE__) -- -f --], "", //, [], bug4117)
reline_libdir = Gem.loaded_specs["reline"].full_gem_path + "/lib"
status = assert_in_out_err(bundle_exec + %W[-W0 -I#{libdir} -I#{reline_libdir} -rirb -e IRB.start(__FILE__) -- -f --], "", //, [], bug4117)
assert(status.success?, bug4117)
end
end
Expand Down
15 changes: 10 additions & 5 deletions test/irb/test_raise_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ class RaiseExceptionTest < TestCase
def test_raise_exception_with_nil_backtrace
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
libdir = File.expand_path("../../lib", __dir__)
assert_in_out_err(bundle_exec + %W[-I#{libdir} -rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, /#<Exception: foo>/, [])
reline_libdir = Gem.loaded_specs["reline"].full_gem_path + "/lib"
assert_in_out_err(bundle_exec + %W[-I#{libdir} -I#{reline_libdir} -rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, /#<Exception: foo>/, [])
raise Exception.new("foo").tap {|e| def e.backtrace; nil; end }
IRB
end

def test_raise_exception_with_message_exception
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
libdir = File.expand_path("../../lib", __dir__)
reline_libdir = Gem.loaded_specs["reline"].full_gem_path + "/lib"
expected = /#<Exception: foo>\nbacktraces are hidden because bar was raised when processing them/
assert_in_out_err(bundle_exec + %W[-I#{libdir} -rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, expected, [])
assert_in_out_err(bundle_exec + %W[-I#{libdir} -I#{reline_libdir} -rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, expected, [])
e = Exception.new("foo")
def e.message; raise 'bar'; end
raise e
Expand All @@ -27,8 +29,9 @@ def e.message; raise 'bar'; end
def test_raise_exception_with_message_inspect_exception
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
libdir = File.expand_path("../../lib", __dir__)
reline_libdir = Gem.loaded_specs["reline"].full_gem_path + "/lib"
expected = /Uninspectable exception occurred/
assert_in_out_err(bundle_exec + %W[-I#{libdir} -rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, expected, [])
assert_in_out_err(bundle_exec + %W[-I#{libdir} -I#{reline_libdir} -rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, expected, [])
e = Exception.new("foo")
def e.message; raise; end
def e.inspect; raise; end
Expand All @@ -40,7 +43,8 @@ def test_raise_exception_with_invalid_byte_sequence
pend if RUBY_ENGINE == 'truffleruby' || /mswin|mingw/ =~ RUBY_PLATFORM
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
libdir = File.expand_path("../../lib", __dir__)
assert_in_out_err(bundle_exec + %W[-I#{libdir} -rirb -W0 -e IRB.start(__FILE__) -- -f --], <<~IRB, /A\\xF3B \(StandardError\)/, [])
reline_libdir = Gem.loaded_specs["reline"].full_gem_path + "/lib"
assert_in_out_err(bundle_exec + %W[-I#{libdir} -I#{reline_libdir} -rirb -W0 -e IRB.start(__FILE__) -- -f --], <<~IRB, /A\\xF3B \(StandardError\)/, [])
raise StandardError, "A\\xf3B"
IRB
end
Expand All @@ -52,6 +56,7 @@ def test_raise_exception_with_different_encoding_containing_invalid_byte_sequenc

bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
libdir = File.expand_path("../../lib", __dir__)
reline_libdir = Gem.loaded_specs["reline"].full_gem_path + "/lib"
File.open("#{tmpdir}/euc.rb", 'w') do |f|
f.write(<<~EOF)
# encoding: euc-jp
Expand All @@ -65,7 +70,7 @@ def raise_euc_with_invalid_byte_sequence
%w(LC_MESSAGES LC_ALL LC_CTYPE LANG).each {|n| env[n] = "ja_JP.UTF-8" }
# TruffleRuby warns when the locale does not exist
env['TRUFFLERUBYOPT'] = "#{ENV['TRUFFLERUBYOPT']} --log.level=SEVERE" if RUBY_ENGINE == 'truffleruby'
args = [env] + bundle_exec + %W[-I#{libdir} -rirb -C #{tmpdir} -W0 -e IRB.start(__FILE__) -- -f --]
args = [env] + bundle_exec + %W[-I#{libdir} -I#{reline_libdir} -rirb -C #{tmpdir} -W0 -e IRB.start(__FILE__) -- -f --]
error = /raise_euc_with_invalid_byte_sequence': あ\\xFF \(RuntimeError\)/
assert_in_out_err(args, <<~IRB, error, [], encoding: "UTF-8")
require_relative 'euc'
Expand Down
3 changes: 2 additions & 1 deletion test/irb/test_ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def test_assignment_expression_with_local_variable

def test_initialising_the_old_top_level_ruby_lex
libdir = File.expand_path("../../lib", __dir__)
assert_in_out_err(["-I#{libdir}", "--disable-gems", "-W:deprecated"], <<~RUBY, [], /warning: constant ::RubyLex is deprecated/)
reline_libdir = Gem.loaded_specs["reline"].full_gem_path + "/lib"
assert_in_out_err(["-I#{libdir}", "-I#{reline_libdir}", "--disable-gems", "-W:deprecated"], <<~RUBY, [], /warning: constant ::RubyLex is deprecated/)
require "irb"
::RubyLex.new(nil)
RUBY
Expand Down
3 changes: 2 additions & 1 deletion test/irb/test_workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ def test_toplevel_binding_local_variables
bug17623 = '[ruby-core:102468]'
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
top_srcdir = "#{__dir__}/../.."
reline_libdir = Gem.loaded_specs["reline"].full_gem_path + "/lib"
irb_path = nil
%w[exe libexec].find do |dir|
irb_path = "#{top_srcdir}/#{dir}/irb"
File.exist?(irb_path)
end or omit 'irb command not found'
assert_in_out_err(bundle_exec + ['-W0', "-I#{top_srcdir}/lib", "-C#{top_srcdir}", '-e', <<~RUBY, '--', '-f', '--'], 'binding.local_variables', /\[:_\]/, [], bug17623)
assert_in_out_err(bundle_exec + ['-W0', "-I#{top_srcdir}/lib", "-I#{reline_libdir}", "-C#{top_srcdir}", '-e', <<~RUBY, '--', '-f', '--'], 'binding.local_variables', /\[:_\]/, [], bug17623)
version = 'xyz' # typical rubygems loading file
load('#{irb_path}')
RUBY
Expand Down

0 comments on commit cf5e61e

Please sign in to comment.