diff options
author | aycabta <aycabta@gmail.com> | 2020-10-05 04:17:15 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2020-10-05 04:17:26 +0900 |
commit | 9718ff62c12c07ecf7f0e234343dca76ee1aa51d (patch) | |
tree | c5c22bd9087cf6f6bb2930d356b89caf36c83971 /test | |
parent | f8c50109d7d1a067bae80b56e7b0b1923951c068 (diff) | |
download | ruby-9718ff62c12c07ecf7f0e234343dca76ee1aa51d.tar.gz |
Show stdout and stderr when history tests fail
Diffstat (limited to 'test')
-rw-r--r-- | test/irb/test_history.rb | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb index 3591f88f59..8942d24c12 100644 --- a/test/irb/test_history.rb +++ b/test/irb/test_history.rb @@ -15,7 +15,9 @@ module TestIRB 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 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 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 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 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 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 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 |