-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polish the exit! command and its tests (#867)
* Remove IRB.irb_exit! method It's not necessary to introduce a new method just for the exit! command at this moment. * Rename ExitForcedAction to ForceExit * Move force exit tests to a dedicated file * Fix nested history saving with exit! command Because we switched to use `Kernel#exit` instead of `exit!`, the outer session's ensure block in `Irb#run` will be run, which will save the history. This means the separate check to save history when force exiting is no longer necessary. * execute_lines helper should also capture IRB setup's output This prevents setup warnings from being printed to test output while allowing those output to be tested. * Update readme
- Loading branch information
Showing
8 changed files
with
112 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: false | ||
require 'irb' | ||
|
||
require_relative "../helper" | ||
|
||
module TestIRB | ||
class ForceExitTest < IntegrationTestCase | ||
def test_forced_exit_finishes_process_immediately | ||
write_ruby <<~'ruby' | ||
puts "First line" | ||
puts "Second line" | ||
binding.irb | ||
puts "Third line" | ||
binding.irb | ||
puts "Fourth line" | ||
ruby | ||
|
||
output = run_ruby_file do | ||
type "123" | ||
type "456" | ||
type "exit!" | ||
end | ||
|
||
assert_match(/First line\r\n/, output) | ||
assert_match(/Second line\r\n/, output) | ||
assert_match(/irb\(main\):001> 123/, output) | ||
assert_match(/irb\(main\):002> 456/, output) | ||
refute_match(/Third line\r\n/, output) | ||
refute_match(/Fourth line\r\n/, output) | ||
end | ||
|
||
def test_forced_exit_in_nested_sessions | ||
write_ruby <<~'ruby' | ||
def foo | ||
binding.irb | ||
end | ||
binding.irb | ||
binding.irb | ||
ruby | ||
|
||
output = run_ruby_file do | ||
type "123" | ||
type "foo" | ||
type "exit!" | ||
end | ||
|
||
assert_match(/irb\(main\):001> 123/, output) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters