From 051164ffe806807ff52caad9c3c08647da64d117 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 24 Jan 2025 12:56:27 +0900 Subject: [PATCH 1/4] Pass lib directory of src repository for assert_in_out_err explicitly --- test/irb/test_option.rb | 3 ++- test/irb/test_raise_exception.rb | 15 ++++++++++----- test/irb/test_ruby_lex.rb | 3 ++- test/irb/test_workspace.rb | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/test/irb/test_option.rb b/test/irb/test_option.rb index fec31f384..e8622fc7b 100644 --- a/test/irb/test_option.rb +++ b/test/irb/test_option.rb @@ -6,7 +6,8 @@ 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__) + status = assert_in_out_err(bundle_exec + %W[-W0 -I#{libdir} -rirb -e IRB.start(__FILE__) -- -f --], "", //, [], bug4117) assert(status.success?, bug4117) end end diff --git a/test/irb/test_raise_exception.rb b/test/irb/test_raise_exception.rb index 44a5ae87e..2c8136ba9 100644 --- a/test/irb/test_raise_exception.rb +++ b/test/irb/test_raise_exception.rb @@ -7,15 +7,17 @@ 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, /#/, []) + libdir = File.expand_path("../../lib", __dir__) + assert_in_out_err(bundle_exec + %W[-I#{libdir} -rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, /#/, []) 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__) expected = /#\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} -rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, expected, []) e = Exception.new("foo") def e.message; raise 'bar'; end raise e @@ -24,8 +26,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__) 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} -rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, expected, []) e = Exception.new("foo") def e.message; raise; end def e.inspect; raise; end @@ -36,7 +39,8 @@ 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__) + assert_in_out_err(bundle_exec + %W[-I#{libdir} -rirb -W0 -e IRB.start(__FILE__) -- -f --], <<~IRB, /A\\xF3B \(StandardError\)/, []) raise StandardError, "A\\xf3B" IRB end @@ -47,6 +51,7 @@ 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__) File.open("#{tmpdir}/euc.rb", 'w') do |f| f.write(<<~EOF) # encoding: euc-jp @@ -60,7 +65,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} -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' diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb index 4e406a8ce..8911a6cd4 100644 --- a/test/irb/test_ruby_lex.rb +++ b/test/irb/test_ruby_lex.rb @@ -200,7 +200,8 @@ 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__) + assert_in_out_err(["-I#{libdir}", "--disable-gems", "-W:deprecated"], <<~RUBY, [], /warning: constant ::RubyLex is deprecated/) require "irb" ::RubyLex.new(nil) RUBY diff --git a/test/irb/test_workspace.rb b/test/irb/test_workspace.rb index ad515f91d..62166abfd 100644 --- a/test/irb/test_workspace.rb +++ b/test/irb/test_workspace.rb @@ -89,7 +89,7 @@ def test_toplevel_binding_local_variables 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", "-C#{top_srcdir}", '-e', <<~RUBY, '--', '-f', '--'], 'binding.local_variables', /\[:_\]/, [], bug17623) version = 'xyz' # typical rubygems loading file load('#{irb_path}') RUBY From 1ef78ae667c70d1815b20d84642a65672ca82955 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 24 Jan 2025 12:59:54 +0900 Subject: [PATCH 2/4] Use git ls-files for bundled gems preparation --- irb.gemspec | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/irb.gemspec b/irb.gemspec index 9a93382b7..c30b9fb7c 100644 --- a/irb.gemspec +++ b/irb.gemspec @@ -21,19 +21,9 @@ Gem::Specification.new do |spec| spec.metadata["documentation_uri"] = "https://ruby.github.io/irb/" spec.metadata["changelog_uri"] = "#{spec.homepage}/releases" - spec.files = [ - "Gemfile", - "LICENSE.txt", - "README.md", - "Rakefile", - "bin/console", - "bin/setup", - "doc/irb/irb-tools.rd.ja", - "doc/irb/irb.rd.ja", - "exe/irb", - "irb.gemspec", - "man/irb.1", - ] + Dir.glob("lib/**/*") + spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do + `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + end spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] From cf5e61e393845ae0bc0363ac8cc83799a28a48ce Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 24 Jan 2025 14:11:22 +0900 Subject: [PATCH 3/4] Inject reline gem path into assert_in_out_err --- test/irb/test_option.rb | 3 ++- test/irb/test_raise_exception.rb | 15 ++++++++++----- test/irb/test_ruby_lex.rb | 3 ++- test/irb/test_workspace.rb | 3 ++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/test/irb/test_option.rb b/test/irb/test_option.rb index e8622fc7b..a3a40c0b9 100644 --- a/test/irb/test_option.rb +++ b/test/irb/test_option.rb @@ -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 diff --git a/test/irb/test_raise_exception.rb b/test/irb/test_raise_exception.rb index 2c8136ba9..133f073f5 100644 --- a/test/irb/test_raise_exception.rb +++ b/test/irb/test_raise_exception.rb @@ -8,7 +8,8 @@ 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, /#/, []) + 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, /#/, []) raise Exception.new("foo").tap {|e| def e.backtrace; nil; end } IRB end @@ -16,8 +17,9 @@ def test_raise_exception_with_nil_backtrace 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 = /#\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 @@ -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 @@ -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 @@ -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 @@ -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' diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb index 8911a6cd4..9392b49fa 100644 --- a/test/irb/test_ruby_lex.rb +++ b/test/irb/test_ruby_lex.rb @@ -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 diff --git a/test/irb/test_workspace.rb b/test/irb/test_workspace.rb index 62166abfd..99ade80f6 100644 --- a/test/irb/test_workspace.rb +++ b/test/irb/test_workspace.rb @@ -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 From 0ae3d265aa5e5db8a23f1038975b4693cc6f5e68 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 27 Jan 2025 19:06:46 +0900 Subject: [PATCH 4/4] Keep current file list --- irb.gemspec | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/irb.gemspec b/irb.gemspec index c30b9fb7c..cce77e68f 100644 --- a/irb.gemspec +++ b/irb.gemspec @@ -21,9 +21,19 @@ Gem::Specification.new do |spec| spec.metadata["documentation_uri"] = "https://ruby.github.io/irb/" spec.metadata["changelog_uri"] = "#{spec.homepage}/releases" - spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do - `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } - end + spec.files = [ + "Gemfile", + "LICENSE.txt", + "README.md", + "Rakefile", + "bin/console", + "bin/setup", + "doc/irb/irb-tools.rd.ja", + "doc/irb/irb.rd.ja", + "exe/irb", + "irb.gemspec", + "man/irb.1", + ] + 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"]