Skip to content

Commit

Permalink
bundled gems migration (#1078)
Browse files Browse the repository at this point in the history
* Pass lib directory of src repository for assert_in_out_err explicitly

* Use git ls-files for bundled gems preparation

* Inject reline gem path into assert_in_out_err

* Keep current file list
  • Loading branch information
hsbt authored Jan 27, 2025
1 parent 1ca7472 commit 095a1f7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion irb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
"exe/irb",
"irb.gemspec",
"man/irb.1",
] + Dir.glob("lib/**/*")
] + Dir.chdir(File.expand_path('..', __FILE__)) { Dir.glob("lib/**/*") }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
Expand Down
4 changes: 3 additions & 1 deletion test/irb/test_option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class OptionTest < TestCase
def test_end_of_option
bug4117 = '[ruby-core:33574]'
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
status = assert_in_out_err(bundle_exec + %w[-W0 -rirb -e IRB.start(__FILE__) -- -f --], "", //, [], bug4117)
libdir = File.expand_path("../../lib", __dir__)
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
20 changes: 15 additions & 5 deletions test/irb/test_raise_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ module TestIRB
class RaiseExceptionTest < TestCase
def test_raise_exception_with_nil_backtrace
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
assert_in_out_err(bundle_exec + %w[-rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, /#<Exception: foo>/, [])
libdir = File.expand_path("../../lib", __dir__)
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[-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 @@ -24,8 +28,10 @@ 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[-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 @@ -36,7 +42,9 @@ def e.inspect; raise; end
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'] : []
assert_in_out_err(bundle_exec + %w[-rirb -W0 -e IRB.start(__FILE__) -- -f --], <<~IRB, /A\\xF3B \(StandardError\)/, [])
libdir = File.expand_path("../../lib", __dir__)
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 @@ -47,6 +55,8 @@ def test_raise_exception_with_different_encoding_containing_invalid_byte_sequenc
ENV["HOME"] = tmpdir

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 @@ -60,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[-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
4 changes: 3 additions & 1 deletion test/irb/test_ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ def test_assignment_expression_with_local_variable
end

def test_initialising_the_old_top_level_ruby_lex
assert_in_out_err(["--disable-gems", "-W:deprecated"], <<~RUBY, [], /warning: constant ::RubyLex is deprecated/)
libdir = File.expand_path("../../lib", __dir__)
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', "-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 095a1f7

Please sign in to comment.