Skip to content

Commit

Permalink
Add a test for Readline.readline without tty
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Sep 1, 2021
1 parent ba0464e commit 67eaa22
Showing 1 changed file with 14 additions and 0 deletions.
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

0 comments on commit 67eaa22

Please sign in to comment.