Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readline.readline (ext/readline or lib/reline) should works fine without tty #4796

Merged
merged 2 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/reline/general_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def self.set_default_key_bindings(_)
end

@@buf = []
@@input = STDIN

def self.input=(val)
@@input = val
Expand Down
14 changes: 14 additions & 0 deletions test/readline/test_readline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "test/unit"
require "tempfile"
require "timeout"
require "open3"

module BasetestReadline
INPUTRC = "INPUTRC"
Expand Down Expand Up @@ -809,6 +810,19 @@ def test_completion_quote_character_after_completion
Readline.completer_quote_characters = saved_completer_quote_characters if saved_completer_quote_characters
end

def test_without_tty
loader = nil
if defined?(TestReadline) && self.class == TestReadline
loader = "use_ext_readline"
elsif defined?(TestRelineAsReadline) && self.class == TestRelineAsReadline
loader = "use_lib_reline"
end
if loader
res, exit_status = Open3.capture2e("ruby -I#{__dir__} -Ilib -rhelper -e '#{loader}; Readline.readline(%{y or n?})'", stdin_data: "y\n")
assert exit_status.success?, "It should work fine without tty, but it failed.\nError output:\n#{res}"
end
end

private

def replace_stdio(stdin_path, stdout_path)
Expand Down