ttytest2 1.3.0 → 1.4.0
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 +4 -4
- data/README.md +34 -16
- data/lib/ttytest/assertions/column_assertions.rb +31 -0
- data/lib/ttytest/assertions/row_assertions.rb +2 -3
- data/lib/ttytest/tmux/session.rb +23 -4
- data/lib/ttytest/version.rb +1 -1
- data/lib/ttytest.rb +2 -4
- data/notes.txt +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 360be4f6d7358f00c2462a247939072ab8e93e1b64f9465112c62b6f9a22a484
|
4
|
+
data.tar.gz: 7ede22ea96c9ce32546111761d730c008da042b997914e59b6d63bf1e4b06d69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 739fde4fb24d1a2a2a6179c5433be0191587f6e6f4aad92c495880991140569ad82821e8e3285bca1cd908f067adb3d404fd70c696b8cb1d973ee4d3fbb8349a
|
7
|
+
data.tar.gz: 7c4472bb3d2cebfbbcf29edb62cbee8f16c8ae84bcd59e8263c108f71e0db89da1ab7fdd1c9c8dfa06f2047b9bae8d7e9e0016718a9ddcfb2ac89d91407efe10
|
data/README.md
CHANGED
@@ -4,13 +4,13 @@
|
|
4
4
|
<img src="images/ttytest2.png" alt="ttytest2 logo" style="width:70%; height:auto;">
|
5
5
|
</a>
|
6
6
|
|
7
|
-
ttytest2 is a
|
7
|
+
ttytest2 is a integration test framework for CLI, TUI, & shell applications.
|
8
8
|
|
9
9
|
ttytest2 is a fork and a drop-in replacement for [ttytest](https://github.com/jhawthorn/ttytest).
|
10
10
|
|
11
11
|
It works by creating a tmux session behind the scenes, running the specified commands, capturing the pane, and then comparing the actual content to the expected content based on the assertions made.
|
12
12
|
|
13
|
-
The assertions will wait a
|
13
|
+
The assertions will wait a configuable amount of time (default 2 seconds) for the expected content to appear before failing.
|
14
14
|
|
15
15
|
[](https://badge.fury.io/rb/ttytest2)
|
16
16
|
|
@@ -38,6 +38,8 @@ The assertions will wait a specified amount of time (configurable, default 2 sec
|
|
38
38
|
* Download the [gem](https://rubygems.org/gems/ttytest2) here.
|
39
39
|
* More documentation available at [ttytest2 docs](https://www.rubydoc.info/gems/ttytest2).
|
40
40
|
* There are more examples in the examples folder.
|
41
|
+
* Synchronous example: [ncsh synchronous tests](https://github.com/a-eski/ncsh/blob/main/acceptance_tests/tests/acceptance_tests.rb)
|
42
|
+
* Concurrent & generated example: [ncsh concurrent tests](https://github.com/a-eski/ncsh/blob/main/acceptance_tests/minitest/tests.rb)
|
41
43
|
|
42
44
|
### Simple Example
|
43
45
|
|
@@ -77,11 +79,11 @@ TTY
|
|
77
79
|
|
78
80
|
Call one of these methods to initialize an instance of ttytest2.
|
79
81
|
|
80
|
-
* `new_terminal(cmd, width, height)`: initialize new tmux terminal instance and run cmd.
|
82
|
+
* `new_terminal(cmd, width, height, max_wait_time, use_return_for_newline)`: initialize new tmux terminal instance and run cmd.
|
81
83
|
|
82
84
|
* `new_default_sh_terminal()`: intialize new tmux terminal instance using sh, width of 80, height of 24.
|
83
85
|
|
84
|
-
* `new_sh_terminal(width, height)`: intialize new tmux terminal instance using sh
|
86
|
+
* `new_sh_terminal(width, height, max_wait_time, use_return_for_newline)`: intialize new tmux terminal instance using sh.
|
85
87
|
|
86
88
|
``` ruby
|
87
89
|
require 'ttytest'
|
@@ -96,6 +98,8 @@ require 'ttytest'
|
|
96
98
|
# you can also use other shells, like bash
|
97
99
|
@tty = TTYtest.new_terminal('/bin/bash')
|
98
100
|
@tty = TTYtest.new_terminal('/bin/bash', width: 80, height: 24)
|
101
|
+
|
102
|
+
# you can specify further options, see section Configurables.
|
99
103
|
```
|
100
104
|
|
101
105
|
## Assertions
|
@@ -128,6 +132,12 @@ If you are reading this on github, the ruby docs accessible from [RubyDoc.Info](
|
|
128
132
|
|
129
133
|
* `assert_rows_each_match_regexp(row_start, row_end, regexp_str)`
|
130
134
|
|
135
|
+
* `assert_column(col_number, expected_text)`
|
136
|
+
|
137
|
+
* `assert_column_is_empty(col_number)`
|
138
|
+
|
139
|
+
* `assert_column_at(col_number, row_start, row_end, expected_str)`
|
140
|
+
|
131
141
|
* `assert_cursor_position(x: x, y: y)`
|
132
142
|
|
133
143
|
* `assert_cursor_visible`
|
@@ -162,17 +172,17 @@ Note: Most of the time send_line has the best ergonomics.
|
|
162
172
|
|
163
173
|
### Base Functions
|
164
174
|
|
165
|
-
These functions form the basis of interacting with the tmux pane.
|
175
|
+
These functions form the basis of interacting with the tmux pane. Internally they power the other functions, but you can also use them directly.
|
166
176
|
|
167
|
-
* `send_keys(output)`: for canonical
|
177
|
+
* `send_keys(output)`: for canonical apps (or multi-character keys for noncanonical apps).
|
168
178
|
|
169
|
-
* `send_keys_one_at_a_time(output)`: for noncanonical
|
179
|
+
* `send_keys_one_at_a_time(output)`: for noncanonical apps.
|
170
180
|
|
171
|
-
* `send_keys_exact(output)`: sends keys as is, exactly. Also useful for sending tmux specific keys (any
|
181
|
+
* `send_keys_exact(output)`: sends keys as is, exactly. Also useful for sending tmux specific keys (any tmux send-keys arguments like: DC (delete), Escape (ESC), etc.)
|
172
182
|
|
173
183
|
### Ergonomic Functions
|
174
184
|
|
175
|
-
The base functions work great, but these functions build upon the base functions to provide more
|
185
|
+
The base functions work great, but these functions build upon the base functions to provide more functionalities and better ergonomics.
|
176
186
|
|
177
187
|
For example, `send_line(line)` makes sure that the enter key (newline character) is sent after the `line` so you don't have to worry about adding it to `line` or calling send_newline after.
|
178
188
|
|
@@ -188,8 +198,14 @@ For example, `send_line(line)` makes sure that the enter key (newline character)
|
|
188
198
|
|
189
199
|
* `send_line_exact`: send line exactly as is to tmux. Certain special characters may not work with send_line. You can also include tmux send-keys arguments like DC for delete, etc.
|
190
200
|
|
201
|
+
* `send_line_exact_then_sleep(line, sleep_time)`: simulate typing in a command in the terminal and hitting enter using send_line_exact semantics, then wait for sleep_time seconds.
|
202
|
+
|
191
203
|
* `send_lines_exact`: send lines exactly are they are to tmux. Similar semantics to send_line_exact.
|
192
204
|
|
205
|
+
* `send_lines_exact_then_sleep(lines, sleep_time)`: for each line in lines, simulate sending the line and hitting enter using send_line_exact semantics. After sending all the lines, sleep for sleep_time.
|
206
|
+
|
207
|
+
* `send_line_exact_then_sleep_and_repeat(lines, sleep_time)`: for each line in lines, simulate sending the line and hitting enter using send_line_exact, then sleep before sending the next line.
|
208
|
+
|
193
209
|
### Output Helpers
|
194
210
|
|
195
211
|
Helper functions to make sending output easier! They use the methods above under 'Sending Output' section under the hood.
|
@@ -200,7 +216,6 @@ Helper functions to make sending output easier! They use the methods above under
|
|
200
216
|
* `send_return` # simulate hitting enter, equivalent to @tty.send_keys(%(\r))
|
201
217
|
* `send_returns(number_of_times)` # equivalent to calling send_return number_of_times
|
202
218
|
|
203
|
-
|
204
219
|
* `send_backspace` # simulate hitting backspace, equivalent to @tty.send_keys(TTYtest::BACKSPACE)
|
205
220
|
* `send_backspaces(number_of_times)` # equivalent to calling send_backspace number_of_times
|
206
221
|
|
@@ -246,9 +261,12 @@ Send F keys like F1, F2, etc. as shown below:
|
|
246
261
|
|
247
262
|
### Constants
|
248
263
|
|
249
|
-
|
264
|
+
Commonly used keys are available as constants to simplify use.
|
250
265
|
|
251
266
|
``` ruby
|
267
|
+
# can use like:
|
268
|
+
send_keys_exact(TTYtest::CTRLA)
|
269
|
+
|
252
270
|
TTYtest::CTRLA
|
253
271
|
TTYtest::CTRLB
|
254
272
|
TTYtest::CTRLC
|
@@ -287,7 +305,7 @@ There are 2 main configurations for ttytest2: max_wait_time, and use_return_for_
|
|
287
305
|
|
288
306
|
### Max wait time
|
289
307
|
|
290
|
-
Max wait time represents the amount of time in seconds that ttytest2 will keep retrying an assertion before failing.
|
308
|
+
Max wait time represents the amount of time in seconds that ttytest2 will keep retrying an assertion before failing that assertion.
|
291
309
|
|
292
310
|
You can configure max wait time as shown below.
|
293
311
|
|
@@ -301,7 +319,7 @@ You can configure max wait time as shown below.
|
|
301
319
|
|
302
320
|
### Use return for newline
|
303
321
|
|
304
|
-
Use return for newline tells ttytest2 to use return ('
|
322
|
+
Use return for newline tells ttytest2 to use return ('/r') instead of newline ('/n') for methods like send_line, send_line_exact, etc.
|
305
323
|
|
306
324
|
Some line readers may interpreter return and newline differently, so this can be useful in those cases.
|
307
325
|
|
@@ -346,11 +364,11 @@ p "\n#{@tty.capture}" # this is equivalent to above statement @tty.print
|
|
346
364
|
|
347
365
|
## Tips
|
348
366
|
|
349
|
-
If you are using ttyest2 to test your CLI, using sh
|
367
|
+
If you are using ttyest2 to test your CLI, using sh can be easier than bash because you don't have to worry about user, current working directory, etc. as shown in the examples.
|
350
368
|
|
351
|
-
|
369
|
+
The assertions like `assert_row_like`, `assert_row_starts_with`, and `assert_row_ends_with` are usually extremely helpful, especially if trying to test your application in different environments or using a docker container with a shell that is not sh.
|
352
370
|
|
353
|
-
Most line readers use '\n' for newline, but some may interpret
|
371
|
+
Most line readers use '\n' for newline, but some may interpret newline and return differently or expect '\r' for the enter key.
|
354
372
|
|
355
373
|
## Docker
|
356
374
|
|
@@ -37,5 +37,36 @@ module TTYtest
|
|
37
37
|
"expected column #{col_number} to be empty\nEntire screen:\n#{self}"
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
# Asserts the contents of a column contain the expected string at the specified position
|
42
|
+
# @param [Integer] col_number the column (starting from 0) to test against
|
43
|
+
# @param [Integer] row_start the row position to start comparing expected against
|
44
|
+
# @param [Integer] row_end the row position to end comparing expected against (inclusive)
|
45
|
+
# @param [String] expected the expected value that the row starts with. Any trailing whitespace is ignored
|
46
|
+
# @raise [MatchError] if the column doesn't match
|
47
|
+
def assert_column_at(col_number, row_start, row_end, expected)
|
48
|
+
validate(col_number)
|
49
|
+
expected = expected.rstrip
|
50
|
+
actual = []
|
51
|
+
|
52
|
+
rows.each_with_index do |row, i|
|
53
|
+
next if i < row_start
|
54
|
+
break if i > row_end || row.nil? || row == ''
|
55
|
+
|
56
|
+
actual[i - row_start] = row[col_number]
|
57
|
+
next if row[col_number] == expected[i - row_start]
|
58
|
+
|
59
|
+
raise MatchError,
|
60
|
+
"expected column #{col_number} to be #{expected.inspect}\n
|
61
|
+
Entire screen:\n#{self}"
|
62
|
+
end
|
63
|
+
|
64
|
+
return if !actual.nil? && actual.join.eql?(expected)
|
65
|
+
|
66
|
+
inspection = get_inspection(actual.join)
|
67
|
+
|
68
|
+
raise MatchError,
|
69
|
+
"expected column #{col_number} to contain #{expected} at #{row_start}-#{row_end} and got #{inspection}\nEntire screen:\n#{self}"
|
70
|
+
end
|
40
71
|
end
|
41
72
|
end
|
@@ -34,7 +34,7 @@ module TTYtest
|
|
34
34
|
end
|
35
35
|
alias assert_line_is_empty assert_row_is_empty
|
36
36
|
|
37
|
-
# Asserts the contents of a
|
37
|
+
# Asserts the contents of a row contain the expected string at the specified position
|
38
38
|
# @param [Integer] row_number the row (starting from 0) to test against
|
39
39
|
# @param [Integer] column_start the column position to start comparing expected against
|
40
40
|
# @param [Integer] columns_end the column position to end comparing expected against
|
@@ -51,8 +51,7 @@ module TTYtest
|
|
51
51
|
inspection = get_inspection_bounded(actual, column_start, column_end)
|
52
52
|
|
53
53
|
raise MatchError,
|
54
|
-
"expected row #{row_number} to contain #{expected
|
55
|
-
column_end]} at #{column_start}-#{column_end} and got #{inspection}\nEntire screen:\n#{self}"
|
54
|
+
"expected row #{row_number} to contain #{expected} at #{column_start}-#{column_end} and got #{inspection}\nEntire screen:\n#{self}"
|
56
55
|
end
|
57
56
|
alias assert_line_at assert_row_at
|
58
57
|
|
data/lib/ttytest/tmux/session.rb
CHANGED
@@ -78,6 +78,19 @@ module TTYtest
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
def send_lines_then_sleep(*lines, sleep_time)
|
82
|
+
lines.each do |line|
|
83
|
+
send_line(line)
|
84
|
+
end
|
85
|
+
sleep sleep_time
|
86
|
+
end
|
87
|
+
|
88
|
+
def send_line_then_sleep_and_repeat(*lines, sleep_time)
|
89
|
+
lines.each do |line|
|
90
|
+
send_line_then_sleep(line, sleep_time)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
81
94
|
def send_line_exact(line)
|
82
95
|
send_keys_exact(line)
|
83
96
|
if @use_return_for_newline
|
@@ -87,22 +100,28 @@ module TTYtest
|
|
87
100
|
send_newline unless line[-1] == '\n'
|
88
101
|
end
|
89
102
|
|
103
|
+
# Send line then sleep for sleep_time
|
104
|
+
def send_line_exact_then_sleep(line, sleep_time)
|
105
|
+
send_line_exact(line)
|
106
|
+
sleep sleep_time
|
107
|
+
end
|
108
|
+
|
90
109
|
def send_lines_exact(*lines)
|
91
110
|
lines.each do |line|
|
92
111
|
send_line_exact(line)
|
93
112
|
end
|
94
113
|
end
|
95
114
|
|
96
|
-
def
|
115
|
+
def send_lines_exact_then_sleep(*lines, sleep_time)
|
97
116
|
lines.each do |line|
|
98
|
-
|
117
|
+
send_line_exact(line)
|
99
118
|
end
|
100
119
|
sleep sleep_time
|
101
120
|
end
|
102
121
|
|
103
|
-
def
|
122
|
+
def send_line_exact_then_sleep_and_repeat(*lines, sleep_time)
|
104
123
|
lines.each do |line|
|
105
|
-
|
124
|
+
send_line_exact_then_sleep(line, sleep_time)
|
106
125
|
end
|
107
126
|
end
|
108
127
|
|
data/lib/ttytest/version.rb
CHANGED
data/lib/ttytest.rb
CHANGED
@@ -22,12 +22,12 @@ module TTYtest
|
|
22
22
|
|
23
23
|
# @!method new_default_sh_terminal
|
24
24
|
# Create a new terminal using '/bin/sh' with width: 80 and height: 24.
|
25
|
-
# Useful for
|
25
|
+
# Useful for applications like shells which may show user or the cwd.
|
26
26
|
# @return [Terminal] a new sh terminal
|
27
27
|
|
28
28
|
# @!method new_sh_terminal(width: 80, height: 24)
|
29
29
|
# Create a new terminal using '/bin/sh' with ability to set width and height.
|
30
|
-
# Useful for
|
30
|
+
# Useful for applications like shells which may show user or the cwd.
|
31
31
|
# @param [Integer] max_wait_time max time to wait for screen to update before an assertion fails
|
32
32
|
# @param [bool] use_return_for_newline use return instead of newline for functions like send_line
|
33
33
|
# @return [Terminal] a new sh terminal with specified width and height
|
@@ -35,8 +35,6 @@ module TTYtest
|
|
35
35
|
def_delegators :driver
|
36
36
|
|
37
37
|
def new_terminal(cmd, width: 80, height: 24, max_wait_time: 2, use_return_for_newline: false)
|
38
|
-
# @max_wait_time = max_wait_time
|
39
|
-
# @use_return_for_newline = use_return_for_newline
|
40
38
|
driver.new_terminal(cmd, width: width, height: height, max_wait_time: max_wait_time,
|
41
39
|
use_return_for_newline: use_return_for_newline)
|
42
40
|
end
|
data/notes.txt
CHANGED
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.
|
4
|
+
version: 1.4.0
|
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-09-
|
11
|
+
date: 2025-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|