Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions test/try_selector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,28 @@ def test_valid_rename_sets_selected
assert_equal "brand-new", selected[:new]
end
end

# -------------------------------------------------------------------
# setup_terminal — SIGWINCH guard (cross-platform)
# -------------------------------------------------------------------
class SetupTerminalWinchGuardTest < TrySelectorTestCase
# On platforms without SIGWINCH (e.g. Windows Ruby, RUBY_PLATFORM
# x64-mingw-ucrt), Signal.list has no "WINCH" key and Signal.trap('WINCH')
# raises ArgumentError: unsupported signal. setup_terminal must not crash
# there. Simulate that platform by stubbing Signal.list to omit WINCH.
def test_no_raise_when_winch_unsupported
sel = build_selector
without_winch = Signal.list.reject { |name, _| name == "WINCH" }
original_list = Signal.method(:list)
Signal.define_singleton_method(:list) { without_winch }
begin
sel.send(:setup_terminal) # must not raise
ensure
Signal.define_singleton_method(:list, original_list)
sel&.send(:restore_terminal)
end
# Guard skipped the trap, so no handler was captured.
assert_nil sel.instance_variable_get(:@old_winch_handler)
end
end

2 changes: 1 addition & 1 deletion try.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def setup_terminal
STDERR.print("#{Tui::ANSI::ALT_SCREEN_ON}#{Tui::ANSI.set_title("try")}#{Tui::ANSI::CURSOR_BLINK}")
end

@old_winch_handler = Signal.trap('WINCH') { @needs_redraw = true }
@old_winch_handler = Signal.trap('WINCH') { @needs_redraw = true } if Signal.list.key?('WINCH')
end

def restore_terminal
Expand Down