From c6cf8a79d025412dbe4bb874aabac0e5c36b3da5 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 24 Jan 2025 12:56:27 +0900 Subject: [PATCH] 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 ++- 3 files changed, 14 insertions(+), 7 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