ruby-changes:67081
From: Samuel <ko1@a...>
Date: Mon, 9 Aug 2021 08:41:13 +0900 (JST)
Subject: [ruby-changes:67081] 48c43f7783 (master): Rework the readline test to be more robust.
https://git.ruby-lang.org/ruby.git/commit/?id=48c43f7783 From 48c43f7783bdb9aa92af61970ed85cf91342b942 Mon Sep 17 00:00:00 2001 From: Samuel Williams <samuel.williams@o...> Date: Mon, 9 Aug 2021 09:40:13 +1200 Subject: Rework the readline test to be more robust. - Capture that the child is started by initial log line. - More robust handling of child status reaping. - Direct exit without sucess mesage if `#readline` receives input. --- test/readline/test_readline.rb | 89 ++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/test/readline/test_readline.rb b/test/readline/test_readline.rb index a8eb136..3678f5b 100644 --- a/test/readline/test_readline.rb +++ b/test/readline/test_readline.rb @@ -8,6 +8,8 @@ module BasetestReadline https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L8 INPUTRC = "INPUTRC" SAVED_ENV = %w[COLUMNS LINES] + TIMEOUT = 8 + def setup @saved_env = ENV.values_at(*SAVED_ENV) @inputrc, ENV[INPUTRC] = ENV[INPUTRC], IO::NULL @@ -449,7 +451,7 @@ module BasetestReadline https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L451 w << "\cr\u3042\u3093" w.reopen(IO::NULL) assert_equal("\u3046\u3093", Readline.readline("", true), bug6602) - Timeout.timeout(2) do + Timeout.timeout(TIMEOUT) do assert_equal("\u3042\u3093", Readline.readline("", true), bug6602) end assert_equal(nil, Readline.readline("", true), bug6602) @@ -482,6 +484,7 @@ module BasetestReadline https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L484 code = <<-"end;" require 'readline' require 'helper' + puts "Readline::VERSION is \#{Readline::VERSION}." #{ if defined?(TestReadline) && self.class == TestReadline "use_ext_readline" @@ -496,6 +499,7 @@ module BasetestReadline https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L499 p :INT } Readline.readline('input> ') + exit!(0) # Cause the process to exit immediately. }.value rescue Interrupt puts 'FAILED' @@ -503,59 +507,52 @@ module BasetestReadline https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L507 end puts 'SUCCEEDED' end; - f = Tempfile.new("interrupt_in_other_thread") - path = f.path - f.write code - f.close - f.open - asserted = false - current_dir = File.expand_path("..", __FILE__) - log, status = EnvUtil.invoke_ruby(["-I#{current_dir}", path], "", true, :merge_to_stdout) do |_in, _out, _, pid| - begin - Timeout.timeout(4) do - log = String.new("Readline::VERSION is #{Readline::VERSION}.\n") - while c = _out.read(1) - log << c if c - break if log.include?('input>') - end - Process.kill(:INT, pid) - sleep 0.1 - while c = _out.read(1) - log << c if c - break if log.include?('INT') - end - begin - _in.write "\n" - rescue Errno::EPIPE - # The "write" will fail if Reline crashed by SIGINT. + + script = Tempfile.new("interrupt_in_other_thread") + script.write code + script.close + + log = String.new + + EnvUtil.invoke_ruby(["-I#{__dir__}", script.path], "", true, :merge_to_stdout) do |_in, _out, _, pid| + Timeout.timeout(TIMEOUT) do + while c = _out.read(1) + log << c if c + break if log.include?('input>') + end + Process.kill(:INT, pid) + sleep 0.1 + while c = _out.read(1) + log << c if c + break if log.include?('INT') + end + begin + _in.write "\n" + rescue Errno::EPIPE + # The "write" will fail if Reline crashed by SIGINT. + end + while c = _out.read(1) + log << c if c + if log.include?('FAILED') + assert false, "Should handle SIGINT correctly but raised interrupt.\nLog: #{log}\n----" end - while c = _out.read(1) - log << c if c - if log.include?('FAILED') - assert false, "Should handle SIGINT correctly but failed." - asserted = true - end - if log.include?('SUCCEEDED') - assert true, "Should handle SIGINT correctly but failed." - asserted = true - end + if log.include?('SUCCEEDED') + assert false, "Should handle SIGINT correctly but exited successfully.\nLog: #{log}\n----" end end - rescue Timeout::Error => e - assert false, "Timed out to handle SIGINT.\nLog: #{log}\nBacktrace:\n#{e.full_message(highlight: false)}\n----" - asserted = true + rescue Timeout::Error + assert false, "Timed out to handle SIGINT!\nLog: #{log}\n----" end - [log, Process.wait2(pid)[1]] - end - unless asserted - assert false, "Unknown failure with exit status #{status}\nLog: #{log}\n----" + ensure + status = Process.wait2(pid).last + assert status.success?, "Unknown failure with exit status #{status}\nLog: #{log}\n----" end + + assert log.include?('INT'), "Interrupt was handled correctly." ensure - f.close! if f + script&.close! end - - def test_setting_quoting_detection_proc return unless Readline.respond_to?(:quoting_detection_proc=) -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/