ttytest2 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4322aa40df769e1ed8a2095f5766199175afae71233c8308b3a6ef30322fedb2
4
- data.tar.gz: 3d94b40f20cbea852a6462d23d3922a6a1e7ef95573815320047279f47e8c76d
3
+ metadata.gz: 9b9538d393117d0cc417fd097ce965cc0c84612e9c8c244a7462072568ae1f42
4
+ data.tar.gz: c88ea611163de40b6047faea181a573e767e6e68a3644143a0e4e00dc3401448
5
5
  SHA512:
6
- metadata.gz: 90580621915fddc1ba3b6390fc58e7787fdfa86336cb576abd3224a68c8cb88fbf665425d960153bd0cf4d170aa02afb63f14f53acc2f1f37711d8bbb0c244a1
7
- data.tar.gz: 44047668527313f4bcea17522d2c8ee77bf9e0695ebd89a6c68a01411305cd3389eb5e22e43c1c4861662414b7721b6772fd26d84b1364a8a447d9363af0ab04
6
+ metadata.gz: 86fa0a0862a158102d08c9d05df218927dee91bf49c73176d1f7979136c626b10496e02af55085f30e336492d1aad3884da8690d908868ed3bfb8b92f179172e
7
+ data.tar.gz: f2a16dcae9a58b970659e7a5181ba4dfad50b106bdf5efb057cc1ff3ccccc3712c7d7ded8edb49ed10102279244e7059ebd4c02b5d66940fa888fde4bc279fb6
data/README.md CHANGED
@@ -39,6 +39,7 @@ The assertions will wait a specified amount of time (configurable, default 2 sec
39
39
 
40
40
  ``` ruby
41
41
  require 'ttytest'
42
+
42
43
  @tty = TTYtest.new_terminal(%(PS1='$ ' /bin/sh), width: 80, height: 7)
43
44
  @tty.assert_row(0, '$')
44
45
  @tty.assert_cursor_position(2, 0)
@@ -68,6 +69,31 @@ TTY
68
69
  # $
69
70
  ```
70
71
 
72
+ ### Initializing
73
+
74
+ Call one of these methods to initialize an instance of ttytest2.
75
+
76
+ * `new_terminal(cmd, width, height)`: initialize new tmux terminal instance and run cmd.
77
+
78
+ * `new_default_sh_terminal()`: intialize new tmux terminal instance using sh, width of 80, height of 24.
79
+
80
+ * `new_sh_terminal(width, height)`: intialize new tmux terminal instance using sh and width and height parameters.
81
+
82
+ ``` ruby
83
+ require 'ttytest'
84
+
85
+ # these are all equivalent
86
+ @tty = TTYtest.new_terminal(%(PS1='$ ' /bin/sh))
87
+ @tty = TTYtest.new_terminal(%(PS1='$ ' /bin/sh), width: 80, height: 24)
88
+ @tty = TTYtest.new_default_sh_terminal
89
+ @tty = TTYtest.new_sh_terminal
90
+ @tty = TTYtest.new_sh_terminal(width: 80, height: 24)
91
+
92
+ # you can also use other shells, like bash
93
+ @tty = TTYtest.new_terminal('/bin/bash')
94
+ @tty = TTYtest.new_terminal('/bin/bash', width: 80, height: 24)
95
+ ```
96
+
71
97
  ### Assertions
72
98
 
73
99
  The main way to use TTYtest is through assertions.
@@ -78,6 +104,8 @@ Available assertions:
78
104
 
79
105
  * `assert_row(row_number, expected_text)`
80
106
 
107
+ * `assert_row_is_empty(row_number)`
108
+
81
109
  * `assert_row_at(row_number, column_start_position, column_end_position, expected_text)`
82
110
 
83
111
  * `assert_row_like(row_number, expected_text)`
@@ -755,7 +755,7 @@ def stdout_and_stderr_redirection_tests(row)
755
755
  end
756
756
 
757
757
  row = 0
758
- @tty = TTYtest.new_terminal(%(PS1='$ ' ./bin/ncsh), width: 120, height: 120)
758
+ @tty = TTYtest.new_terminal(%(./bin/ncsh), width: 120, height: 120)
759
759
 
760
760
  row = startup_tests(row, true)
761
761
  row = basic_tests row
@@ -776,7 +776,7 @@ tab_autocompletion_tests row
776
776
  @tty.send_newline
777
777
 
778
778
  row = 0
779
- @tty = TTYtest.new_terminal(%(PS1='$ ' ./bin/ncsh), width: 180, height: 150)
779
+ @tty = TTYtest.new_terminal(%(./bin/ncsh), width: 180, height: 150)
780
780
  row = startup_tests(row, false)
781
781
  row = syntax_error_tests row
782
782
  row = stderr_redirection_tests row
@@ -10,12 +10,27 @@ module TTYtest
10
10
  def assert_row(row_number, expected)
11
11
  expected = expected.rstrip
12
12
  actual = row(row_number)
13
+
13
14
  return if actual == expected
14
15
 
15
16
  raise MatchError,
16
17
  "expected row #{row_number} to be #{expected.inspect} but got #{actual.inspect}\nEntire screen:\n#{self}"
17
18
  end
18
19
 
20
+ def assert_last_row(expected)
21
+ end
22
+
23
+ # Asserts the specified row is empty
24
+ # @param [Integer] row_number the row (starting from 0) to test against
25
+ # @raise [MatchError] if the row isn't empty
26
+ def assert_row_is_empty(row_number)
27
+ actual = row(row_number)
28
+
29
+ return if actual == ''
30
+
31
+ raise MatchError, "expected row #{row_number} to be empty but got #{actual.inspect}\nEntire screen:\n#{self}"
32
+ end
33
+
19
34
  # Asserts the contents of a single row contains the expected string at a specific position
20
35
  # @param [Integer] row_number the row (starting from 0) to test against
21
36
  # @param [Integer] column_start the column position to start comparing expected against
@@ -26,6 +41,7 @@ module TTYtest
26
41
  expected = expected.rstrip
27
42
  actual = row(row_number)
28
43
  column_end += 1
44
+
29
45
  return if actual[column_start, column_end].eql?(expected)
30
46
 
31
47
  raise MatchError,
@@ -41,6 +57,7 @@ module TTYtest
41
57
  def assert_row_like(row_number, expected)
42
58
  expected = expected.rstrip
43
59
  actual = row(row_number)
60
+
44
61
  return if actual.include?(expected)
45
62
 
46
63
  raise MatchError,
@@ -55,6 +72,7 @@ module TTYtest
55
72
  def assert_row_starts_with(row_number, expected)
56
73
  expected = expected.rstrip
57
74
  actual = row(row_number)
75
+
58
76
  return if actual.start_with?(expected)
59
77
 
60
78
  raise MatchError,
@@ -68,6 +86,7 @@ module TTYtest
68
86
  def assert_row_ends_with(row_number, expected)
69
87
  expected = expected.rstrip
70
88
  actual = row(row_number)
89
+
71
90
  return if actual.end_with?(expected)
72
91
 
73
92
  raise MatchError,
@@ -88,6 +107,23 @@ module TTYtest
88
107
  "expected row #{row_number} to match regexp #{regexp_str} but it did not. Row value #{actual.inspect}\nEntire screen:\n#{self}"
89
108
  end
90
109
 
110
+ # Asserts the contents of a multiple rows each match against the passed in regular expression
111
+ # @param [Integer] row_start the row (starting from 0) to test against
112
+ # @param [Integer] row_end the last row to test against
113
+ # @param [String] regexp_str the regular expression as a string that will be used to match with.
114
+ # @raise [MatchError] if the row doesn't match against the regular expression
115
+ def assert_rows_each_match_regexp(row_start, row_end, regexp_str)
116
+ regexp = Regexp.new(regexp_str)
117
+ row_end += 1 if row_end.zero?
118
+
119
+ rows.slice(row_start, row_end).each_with_index do |actual_row, index|
120
+ next if actual_row.match?(regexp)
121
+
122
+ raise MatchError,
123
+ "expected row #{index} to match regexp #{regexp_str} but it did not. Row value #{actual_row.inspect}\nEntire screen:\n#{self}"
124
+ end
125
+ end
126
+
91
127
  # Asserts that the cursor is in the expected position
92
128
  # @param [Integer] x cursor x (row) position, starting from 0
93
129
  # @param [Integer] y cursor y (column) position, starting from 0
@@ -95,6 +131,7 @@ module TTYtest
95
131
  def assert_cursor_position(x, y)
96
132
  expected = [x, y]
97
133
  actual = [cursor_x, cursor_y]
134
+
98
135
  return if actual == expected
99
136
 
100
137
  raise MatchError,
@@ -115,14 +152,11 @@ module TTYtest
115
152
  raise MatchError, "expected cursor to be hidden was visible\nEntire screen:\n#{self}"
116
153
  end
117
154
 
118
- # Asserts the full contents of the terminal
119
- # @param [String] expected the full expected contents of the terminal. Trailing whitespace on each line is ignored
120
- # @raise [MatchError] if the terminal doesn't match the expected content
121
- def assert_contents(expected)
155
+ def matched(expected, actual)
122
156
  expected_rows = expected.split("\n")
123
157
  diff = []
124
158
  matched = true
125
- rows.each_with_index do |actual_row, index|
159
+ actual.each_with_index do |actual_row, index|
126
160
  expected_row = (expected_rows[index] || '').rstrip
127
161
  if actual_row != expected_row
128
162
  diff << "-#{expected_row}"
@@ -133,32 +167,30 @@ module TTYtest
133
167
  end
134
168
  end
135
169
 
170
+ [matched, diff]
171
+ end
172
+
173
+ # Asserts the full contents of the terminal
174
+ # @param [String] expected the full expected contents of the terminal. Trailing whitespace on each line is ignored
175
+ # @raise [MatchError] if the terminal doesn't match the expected content
176
+ def assert_contents(expected)
177
+ matched, diff = matched(expected, rows)
178
+
136
179
  return if matched
137
180
 
138
181
  raise MatchError,
139
182
  "screen did not match expected content:\n--- expected\n+++ actual\n#{diff.join("\n")}"
140
183
  end
141
184
  alias assert_matches assert_contents
185
+ alias assert_screen assert_contents
142
186
 
143
187
  # Asserts the contents of the terminal at specified rows
144
188
  # @param [String] expected the expected contents of the terminal at specified rows. Trailing whitespace on each line is ignored
145
189
  # @raise [MatchError] if the terminal doesn't match the expected content
146
190
  def assert_contents_at(row_start, row_end, expected)
147
- expected_rows = expected.split("\n")
148
- diff = []
149
- matched = true
150
191
  row_end += 1 if row_end.zero?
151
192
 
152
- rows.slice(row_start, row_end).each_with_index do |actual_row, index|
153
- expected_row = (expected_rows[index] || '').rstrip
154
- if actual_row != expected_row
155
- diff << "-#{expected_row}"
156
- diff << "+#{actual_row}"
157
- matched = false
158
- else
159
- diff << " #{actual_row}".rstrip
160
- end
161
- end
193
+ matched, diff = matched(expected, rows.slice(row_start, row_end))
162
194
 
163
195
  return if matched
164
196
 
@@ -166,6 +198,7 @@ module TTYtest
166
198
  "screen did not match expected content:\n--- expected\n+++ actual\n#{diff.join("\n")}"
167
199
  end
168
200
  alias assert_matches_at assert_contents_at
201
+ alias assert_rows assert_contents_at
169
202
 
170
203
  METHODS = public_instance_methods
171
204
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TTYtest
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.2'
5
5
  end
data/notes.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  to push new version to github
2
- git tag v1.0.0
2
+ git tag v1.0.2
3
3
  git push origin --tags
4
4
 
5
5
  to push new version to rubygems.org
6
6
  gem build ttytest2.gemspec
7
- gem push ttytest2-1.0.0.gem
7
+ gem push ttytest2-1.0.2.gem
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ttytest2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Eski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-28 00:00:00.000000000 Z
11
+ date: 2025-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler