ruby-changes:63269
From: aycabta <ko1@a...>
Date: Mon, 5 Oct 2020 04:32:10 +0900 (JST)
Subject: [ruby-changes:63269] 9718ff62c1 (master): Show stdout and stderr when history tests fail
https://git.ruby-lang.org/ruby.git/commit/?id=9718ff62c1 From 9718ff62c12c07ecf7f0e234343dca76ee1aa51d Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Mon, 5 Oct 2020 04:17:15 +0900 Subject: Show stdout and stderr when history tests fail diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb index 3591f88..8942d24 100644 --- a/test/irb/test_history.rb +++ b/test/irb/test_history.rb @@ -15,7 +15,9 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_history.rb#L15 def test_history_save_1 omit "Skip Editline" if /EditLine/n.match(Readline::VERSION) - _result_output, result_history_file = launch_irb_with_irbrc_and_irb_history(<<~IRBRC, <<~IRB_HISTORY) do |stdin| + assert_history_with_irbrc_and_irb_history(<<~EXPECTED_HISTORY, <<~IRBRC, <<~IRB_HISTORY) do |stdin| + exit + EXPECTED_HISTORY IRB.conf[:USE_READLINE] = true IRB.conf[:SAVE_HISTORY] = 1 IRB.conf[:USE_READLINE] = true @@ -27,15 +29,18 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_history.rb#L29 IRB_HISTORY stdin.write("5\nexit\n") end - - assert_equal(<<~HISTORY_FILE, result_history_file) - exit - HISTORY_FILE end def test_history_save_100 omit "Skip Editline" if /EditLine/n.match(Readline::VERSION) - _result_output, result_history_file = launch_irb_with_irbrc_and_irb_history(<<~IRBRC, <<~IRB_HISTORY) do |stdin| + assert_history_with_irbrc_and_irb_history(<<~EXPECTED_HISTORY, <<~IRBRC, <<~IRB_HISTORY) do |stdin| + 1 + 2 + 3 + 4 + 5 + exit + EXPECTED_HISTORY IRB.conf[:USE_READLINE] = true IRB.conf[:SAVE_HISTORY] = 100 IRB.conf[:USE_READLINE] = true @@ -47,20 +52,18 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_history.rb#L52 IRB_HISTORY stdin.write("5\nexit\n") end + end - assert_equal(<<~HISTORY_FILE, result_history_file) + def test_history_save_bignum + omit "Skip Editline" if /EditLine/n.match(Readline::VERSION) + assert_history_with_irbrc_and_irb_history(<<~EXPECTED_HISTORY, <<~IRBRC, <<~IRB_HISTORY) do |stdin| 1 2 3 4 5 exit - HISTORY_FILE - end - - def test_history_save_bignum - omit "Skip Editline" if /EditLine/n.match(Readline::VERSION) - _result_output, result_history_file = launch_irb_with_irbrc_and_irb_history(<<~IRBRC, <<~IRB_HISTORY) do |stdin| + EXPECTED_HISTORY IRB.conf[:USE_READLINE] = true IRB.conf[:SAVE_HISTORY] = 10 ** 19 IRB.conf[:USE_READLINE] = true @@ -72,20 +75,18 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_history.rb#L75 IRB_HISTORY stdin.write("5\nexit\n") end + end - assert_equal(<<~HISTORY_FILE, result_history_file) + def test_history_save_minus_as_infinity + omit "Skip Editline" if /EditLine/n.match(Readline::VERSION) + assert_history_with_irbrc_and_irb_history(<<~EXPECTED_HISTORY, <<~IRBRC, <<~IRB_HISTORY) do |stdin| 1 2 3 4 5 exit - HISTORY_FILE - end - - def test_history_save_minus_as_infinity - omit "Skip Editline" if /EditLine/n.match(Readline::VERSION) - _result_output, result_history_file = launch_irb_with_irbrc_and_irb_history(<<~IRBRC, <<~IRB_HISTORY) do |stdin| + EXPECTED_HISTORY IRB.conf[:USE_READLINE] = true IRB.conf[:SAVE_HISTORY] = -1 # infinity IRB.conf[:USE_READLINE] = true @@ -97,20 +98,11 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_history.rb#L98 IRB_HISTORY stdin.write("5\nexit\n") end - - assert_equal(<<~HISTORY_FILE, result_history_file) - 1 - 2 - 3 - 4 - 5 - exit - HISTORY_FILE end private - def launch_irb_with_irbrc_and_irb_history(irbrc, irb_history) + def assert_history_with_irbrc_and_irb_history(expected_history, irbrc, irb_history) result = nil result_history = nil backup_irbrc = ENV.delete("IRBRC") @@ -128,7 +120,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_history.rb#L120 yield(stdin, stdout) stdin.close stdout.flush - system('ruby', '-Ilib', '-Itest', '-W0', '-rirb', '-e', 'IRB.start(__FILE__)', in: stdin.path, out: stdout.path) + system('ruby', '-Ilib', '-Itest', '-W0', '-rirb', '-e', 'IRB.start(__FILE__)', in: stdin.path, out: stdout.path, err: stdout.path) result = stdout.read stdout.close end @@ -136,7 +128,14 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_history.rb#L128 result_history = f.read end end - [result, result_history] + assert_equal(expected_history, result_history, <<~MESSAGE) + expected: + #{expected_history} + but actual: + #{result_history} + and stdout and stderr ware + #{result} + MESSAGE ensure ENV["HOME"] = backup_home ENV["IRBRC"] = backup_irbrc -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/