From eae449adc7b23f341e5c77182dab210fcd9610ac Mon Sep 17 00:00:00 2001 From: Alex Eski Date: Sun, 12 Oct 2025 09:22:24 -0700 Subject: [PATCH 1/4] improve test coverage 1 --- test/ttytest/assertions/column_assertions_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/ttytest/assertions/column_assertions_test.rb b/test/ttytest/assertions/column_assertions_test.rb index 4190bae..4e6897f 100644 --- a/test/ttytest/assertions/column_assertions_test.rb +++ b/test/ttytest/assertions/column_assertions_test.rb @@ -25,6 +25,14 @@ def test_assert_column_failure assert_includes ex.message, 'expected column 0 to be' end + def test_assert_column_nil_failure + @capture = Capture.new(nil) + ex = assert_raises TTYtest::MatchError do + @capture.assert_column(0, 'foo') + end + assert_includes ex.message, 'expected column 0 to be "foo"' + end + def test_assert_column_wrong_column_failure @capture = Capture.new("$\n$\n$\n$\n$\n$\n") From 5af27fe92d5e2055796670345c5e3861a36518a3 Mon Sep 17 00:00:00 2001 From: Alex Eski Date: Sat, 25 Oct 2025 06:50:49 -0700 Subject: [PATCH 2/4] improve test coverage 2 --- .../assertions/screen_assertions_test.rb | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/ttytest/assertions/screen_assertions_test.rb b/test/ttytest/assertions/screen_assertions_test.rb index bfc6c10..c97a0b1 100644 --- a/test/ttytest/assertions/screen_assertions_test.rb +++ b/test/ttytest/assertions/screen_assertions_test.rb @@ -21,6 +21,13 @@ def test_assert_contents_success $ echo "Hello, world Hello, world TERM + + @capture.assert_contents <<~TERM + $ echo "Hello, world + Hello, world + + + TERM end def test_assert_contents_failure @@ -83,6 +90,14 @@ def test_assert_contents_at_success $ echo "Hello, world" Hello, world TERM + + @capture.assert_contents_at 0, 0, <<~TERM + $ echo "Hello, world" + TERM + + @capture.assert_contents_at 1, 1, <<~TERM + Hello, world + TERM end def test_assert_contents_at_success_multiple_lines @@ -121,6 +136,17 @@ def test_assert_contents_at_success_multiple_lines $ echo "Hello, world" Hello, world TERM + + @capture.assert_contents_at 1, 3, <<~TERM + Hello, world + $ echo "Hello, world" + Hello, world + TERM + + @capture.assert_contents_at 2, 3, <<~TERM + $ echo "Hello, world" + Hello, world + TERM end def test_assert_contents_at_failure @@ -160,6 +186,8 @@ def test_assert_contents_at_trailing_whitespace def test_assert_contents_include_true @capture = Capture.new(FOO_BAR_BAZ_THEN_EMPTY) + @capture.assert_contents_include('foo') + @capture.assert_contents_include('bar') @capture.assert_contents_include('baz') end From e97d02b2d48bf5f7202c0a472dc557904c2a907b Mon Sep 17 00:00:00 2001 From: Alex Eski Date: Sat, 25 Oct 2025 10:47:45 -0700 Subject: [PATCH 3/4] improve test coverage 3 --- .../assertions/column_assertions_test.rb | 24 ++++++++++++++++- .../ttytest/assertions/row_assertions_test.rb | 2 ++ .../assertions/screen_assertions_test.rb | 26 ++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/test/ttytest/assertions/column_assertions_test.rb b/test/ttytest/assertions/column_assertions_test.rb index 4e6897f..19477e8 100644 --- a/test/ttytest/assertions/column_assertions_test.rb +++ b/test/ttytest/assertions/column_assertions_test.rb @@ -5,14 +5,19 @@ module TTYtest class ColumnAssertionsTest < Minitest::Test def test_assert_column_success - @capture = Capture.new("$\n$\n$\n$\n$\n$\n") + @capture = Capture.new("$@za\n$@za\n$@za\n$@za\n$@za\n$@za\n") @capture.assert_column(0, '$$$$$$') + @capture.assert_column(1, '@@@@@@') + @capture.assert_column(2, 'zzzzzz') + @capture.assert_column(3, 'aaaaaa') end def test_assert_column_right_success @capture = Capture.new(" $\n $\n $\n $\n $\n $\n") + @capture.assert_column_is_empty(0) + @capture.assert_column_is_empty(1) @capture.assert_column(2, '$$$$$$') end @@ -123,13 +128,30 @@ def test_assert_column_at_right_success @capture = Capture.new(" $\n $\n $\n $\n $\n $\n") @capture.assert_column_at(2, 0, 5, '$$$$$$') + @capture.assert_column_at(2, 0, 4, '$$$$$') + @capture.assert_column_at(2, 0, 3, '$$$$') + @capture.assert_column_at(2, 0, 2, '$$$') + @capture.assert_column_at(2, 0, 1, '$$') + @capture.assert_column_at(2, 0, 0, '$') + @capture.assert_column_at(2, 1, 5, '$$$$$') @capture.assert_column_at(2, 1, 4, '$$$$') + @capture.assert_column_at(2, 1, 3, '$$$') + @capture.assert_column_at(2, 1, 2, '$$') + @capture.assert_column_at(2, 1, 1, '$') + @capture.assert_column_at(2, 2, 5, '$$$$') @capture.assert_column_at(2, 2, 4, '$$$') + @capture.assert_column_at(2, 2, 3, '$$') + @capture.assert_column_at(2, 2, 2, '$') + @capture.assert_column_at(2, 3, 5, '$$$') @capture.assert_column_at(2, 3, 4, '$$') + @capture.assert_column_at(2, 3, 3, '$') + + @capture.assert_column_at(2, 4, 5, '$$') @capture.assert_column_at(2, 4, 4, '$') + @capture.assert_column_at(2, 5, 5, '$') end diff --git a/test/ttytest/assertions/row_assertions_test.rb b/test/ttytest/assertions/row_assertions_test.rb index 7fec4b2..23a8b04 100644 --- a/test/ttytest/assertions/row_assertions_test.rb +++ b/test/ttytest/assertions/row_assertions_test.rb @@ -320,6 +320,8 @@ def test_assert_rows_each_match_regexp_success @capture.assert_rows_each_match_regexp(0, 2, 'foo') @capture.assert_rows_each_match_regexp(0, 2, '[o]') @capture.assert_rows_each_match_regexp(0, 2, '[f]') + @capture.assert_rows_each_match_regexp(0, 2, '[fo]') + @capture.assert_rows_each_match_regexp(0, 2, '[fo]') end def test_assert_rows_each_match_regexp_failure diff --git a/test/ttytest/assertions/screen_assertions_test.rb b/test/ttytest/assertions/screen_assertions_test.rb index c97a0b1..8cc18b0 100644 --- a/test/ttytest/assertions/screen_assertions_test.rb +++ b/test/ttytest/assertions/screen_assertions_test.rb @@ -86,11 +86,21 @@ def test_assert_contents_at_success @capture.assert_contents_at(0, 0, '$ echo "Hello, world"') @capture.assert_contents_at(1, 1, 'Hello, world') + @capture.assert_contents_at 0, 0, <<~TERM + $ echo "Hello, world" + TERM + @capture.assert_contents_at 0, 1, <<~TERM $ echo "Hello, world" Hello, world TERM + @capture.assert_contents_at 0, 2, <<~TERM + $ echo "Hello, world" + Hello, world + + TERM + @capture.assert_contents_at 0, 0, <<~TERM $ echo "Hello, world" TERM @@ -125,7 +135,8 @@ def test_assert_contents_at_success_multiple_lines Hello, world TERM - @capture.assert_contents_at 1, 2, <<~TERM + @capture.assert_contents_at 0, 2, <<~TERM + $ echo "Hello, world" Hello, world $ echo "Hello, world" TERM @@ -137,6 +148,15 @@ def test_assert_contents_at_success_multiple_lines Hello, world TERM + @capture.assert_contents_at 1, 1, <<~TERM + Hello, world + TERM + + @capture.assert_contents_at 1, 2, <<~TERM + Hello, world + $ echo "Hello, world" + TERM + @capture.assert_contents_at 1, 3, <<~TERM Hello, world $ echo "Hello, world" @@ -147,6 +167,10 @@ def test_assert_contents_at_success_multiple_lines $ echo "Hello, world" Hello, world TERM + + @capture.assert_contents_at 3, 3, <<~TERM + Hello, world + TERM end def test_assert_contents_at_failure From 76515bbbca700ea6ecf140096221232a19667820 Mon Sep 17 00:00:00 2001 From: Alex Eski Date: Sat, 25 Oct 2025 10:56:14 -0700 Subject: [PATCH 4/4] improve test coverage 4 --- test/ttytest/terminal_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/ttytest/terminal_test.rb b/test/ttytest/terminal_test.rb index a59694a..e55982a 100644 --- a/test/ttytest/terminal_test.rb +++ b/test/ttytest/terminal_test.rb @@ -50,6 +50,12 @@ def test_new_default_sh_terminal_hello_world hello_world_test end + def test_new_default_sh_terminal_hello_world_return + @tty = TTYtest.new_default_sh_terminal + @tty.use_return_for_newline = true + hello_world_test + end + def test_command_exiting @tty = TTYtest.new_terminal(%(printf "foo\nbar\n")) @tty.assert_row(0, 'foo') @@ -70,6 +76,9 @@ def empty_command_test_helper(input) tty = TTYtest.new_terminal(input) tty.assert_cursor_position(0, 0) tty.assert_contents '' + tty.assert_contents_empty + tty.assert_row_is_empty(0) + tty.assert_column_is_empty(0) end def test_empty_commands @@ -304,6 +313,11 @@ def test_typical_example @tty.assert_cursor_position(2, 2) @tty.assert_contents_at(0, 0, '$ echo "Hello, world"') + @tty.assert_contents_at 0, 2, <<~TTY + $ echo "Hello, world" + Hello, world + $ + TTY @tty.assert_row_starts_with(0, '$ echo') @tty.assert_row_ends_with(0, '"Hello, world"') @@ -322,6 +336,7 @@ def test_typical_example_return @tty = TTYtest.new_terminal(%(PS1='$ ' /bin/sh), width: 80, height: 7, use_return_for_newline: true) @tty.assert_row(0, '$') @tty.assert_cursor_position(2, 0) + @tty.assert_cursor_visible @tty.send_line('echo "Hello, world"')