ttytest2 0.9.12 → 1.0.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/.bundle/config +0 -0
- data/.github/workflows/test.yml +0 -0
- data/.gitignore +0 -0
- data/Gemfile +0 -0
- data/README.md +38 -5
- data/Rakefile +0 -0
- data/examples/integration_tests.rb +0 -0
- data/lib/ttytest/capture.rb +0 -0
- data/lib/ttytest/constants.rb +2 -0
- data/lib/ttytest/matchers.rb +1 -0
- data/lib/ttytest/terminal.rb +67 -10
- data/lib/ttytest/tmux/driver.rb +8 -0
- data/lib/ttytest/tmux/session.rb +28 -0
- data/lib/ttytest/tmux/tmux.conf +0 -0
- data/lib/ttytest/version.rb +1 -1
- data/lib/ttytest.rb +9 -1
- data/notes.txt +2 -2
- data/ttytest2.gemspec +0 -0
- 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: 4322aa40df769e1ed8a2095f5766199175afae71233c8308b3a6ef30322fedb2
|
4
|
+
data.tar.gz: 3d94b40f20cbea852a6462d23d3922a6a1e7ef95573815320047279f47e8c76d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90580621915fddc1ba3b6390fc58e7787fdfa86336cb576abd3224a68c8cb88fbf665425d960153bd0cf4d170aa02afb63f14f53acc2f1f37711d8bbb0c244a1
|
7
|
+
data.tar.gz: 44047668527313f4bcea17522d2c8ee77bf9e0695ebd89a6c68a01411305cd3389eb5e22e43c1c4861662414b7721b6772fd26d84b1364a8a447d9363af0ab04
|
data/.bundle/config
CHANGED
File without changes
|
data/.github/workflows/test.yml
CHANGED
File without changes
|
data/.gitignore
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ ttytest2 is a fork and a drop-in replacement for [ttytest](https://github.com/jh
|
|
6
6
|
|
7
7
|
It works by running commands inside a tmux session, capturing the pane, and comparing the content to your assertions.
|
8
8
|
|
9
|
-
The assertions will wait a specified amount of time (default 2 seconds) for the expected content to appear.
|
9
|
+
The assertions will wait a specified amount of time (configurable, default 2 seconds) for the expected content to appear.
|
10
10
|
|
11
11
|
[](https://badge.fury.io/rb/ttytest2)
|
12
12
|
|
@@ -77,15 +77,25 @@ Assertions will be retried for up to 2 seconds when called through TTYtest::Term
|
|
77
77
|
Available assertions:
|
78
78
|
|
79
79
|
* `assert_row(row_number, expected_text)`
|
80
|
+
|
80
81
|
* `assert_row_at(row_number, column_start_position, column_end_position, expected_text)`
|
82
|
+
|
81
83
|
* `assert_row_like(row_number, expected_text)`
|
84
|
+
|
82
85
|
* `assert_row_starts_with(row_number, expected_text)`
|
86
|
+
|
83
87
|
* `assert_row_ends_with(row_number, expected_text)`
|
88
|
+
|
84
89
|
* `assert_row_regexp(row_number, regexp_str)`
|
90
|
+
|
85
91
|
* `assert_cursor_position(x: x, y: y)`
|
92
|
+
|
86
93
|
* `assert_cursor_visible`
|
94
|
+
|
87
95
|
* `assert_cursor_hidden`
|
96
|
+
|
88
97
|
* `assert_contents(lines_of_terminal)`
|
98
|
+
|
89
99
|
* `assert_contents_at(row_start, row_end, expected_text)`
|
90
100
|
|
91
101
|
### Output
|
@@ -95,9 +105,19 @@ You can send output to the terminal with the following calls.
|
|
95
105
|
Note: Most of the time send_line has the best ergonomics.
|
96
106
|
|
97
107
|
* `send_line(line)`: simulate typing in a command in the terminal and hitting enter!
|
108
|
+
|
98
109
|
* `send_line_then_sleep(line, sleep_time)`: simulate typing in a command in the terminal and hitting enter, then wait for sleep_time seconds.
|
110
|
+
|
111
|
+
* `send_lines(lines)`: for each line in lines, simulate sending the line and hitting enter.
|
112
|
+
|
113
|
+
* `send_lines_then_sleep(lines, sleep_time)`: for each line in lines, simulate sending the line and hitting enter. After sending all the lines, sleep for sleep_time.
|
114
|
+
|
115
|
+
* `send_line_then_sleep_and_repeat(lines, sleep_time)`: for each line in lines, simulate sending the line and hitting enter, then sleep before sending the next line.
|
116
|
+
|
99
117
|
* `send_keys(output)`: for canonical shells/CLI's (or multi-character keys for noncanonical shells/CLI's).
|
118
|
+
|
100
119
|
* `send_keys_one_at_a_time(output)`: for noncanonical shells/CLI's.
|
120
|
+
|
101
121
|
* `send_keys_exact(output)`: for sending tmux specific keys (any supported send-keys arguments like: DC for delete, Escape for ESC, etc.)
|
102
122
|
|
103
123
|
### Output Helpers
|
@@ -106,22 +126,35 @@ Helper functions to make sending output easier! They use the methods above under
|
|
106
126
|
|
107
127
|
* `send_newline` # simulate hitting enter, equivalent to @tty.send_keys(%(\n))
|
108
128
|
* `send_newlines(number_of_times)` # equivalent to calling send_newline number_of_times
|
129
|
+
* `send_enter` # alias for send_newline
|
130
|
+
* `send_enters(number_of_times)` # alias for send_newlines
|
131
|
+
|
109
132
|
* `send_backspace` # simulate hitting backspace, equivalent to @tty.send_keys(TTYtest::BACKSPACE)
|
110
133
|
* `send_backspaces(number_of_times)` # equivalent to calling send_backspace number_of_times
|
134
|
+
|
111
135
|
* `send_delete` # simulate hitting delete, equivalent to calling send_keys_exact(%(DC))
|
112
136
|
* `send_deletes` # equivalent to calling send_delete number_of_times
|
137
|
+
|
113
138
|
* `send_right_arrow`
|
114
139
|
* `send_right_arrows(number_of_times)`
|
140
|
+
|
115
141
|
* `send_left_arrow`
|
116
142
|
* `send_left_arrows(number_of_times)`
|
143
|
+
|
117
144
|
* `send_up_arrow`
|
118
145
|
* `send_up_arrows(number_of_times)`
|
146
|
+
|
119
147
|
* `send_down_arrow`
|
120
148
|
* `send_down_arrows(number_of_times)`
|
149
|
+
|
121
150
|
* `send_home` # simulate pressing the Home key
|
122
151
|
* `send_end` # simulate pressing the End key
|
152
|
+
|
123
153
|
* `send_clear` # clear the screen by sending clear ascii code
|
124
154
|
|
155
|
+
* `send_escape`
|
156
|
+
* `send_escapes`
|
157
|
+
|
125
158
|
### F keys?
|
126
159
|
|
127
160
|
Send F keys like F1, F2, etc. as shown below:
|
@@ -166,8 +199,6 @@ You can use the method rows to get all rows of the terminal as an array, of use
|
|
166
199
|
# if you want to programatically access the rows, you can do so using @tty.rows
|
167
200
|
p @tty.rows # is equivalent to above statement @tty.print_rows
|
168
201
|
|
169
|
-
|
170
|
-
|
171
202
|
# you can use @tty.capture to access the entire pane.
|
172
203
|
@tty.print # prints out the contents of the terminal:
|
173
204
|
# $ echo "Hello, world"
|
@@ -192,7 +223,9 @@ There are some commonly used keys available as constants to make interacting wit
|
|
192
223
|
TTYtest::BACKSPACE
|
193
224
|
TTYtest::TAB
|
194
225
|
TTYtest::NEWLINE # \n
|
195
|
-
TTYtest::
|
226
|
+
TTYtest::ENTER # \n
|
227
|
+
TTYtest::VERTICAL_TAB # \v
|
228
|
+
TTYtest::SHIFT_ENTER # \v
|
196
229
|
TTYtest::FORM_FEED # \f or New Page NP
|
197
230
|
TTYtest::CTRLL
|
198
231
|
TTYtest::CARRIAGE_RETURN # \r
|
@@ -213,7 +246,7 @@ There are some commonly used keys available as constants to make interacting wit
|
|
213
246
|
TTYtest::CLEAR # clear the screen
|
214
247
|
```
|
215
248
|
|
216
|
-
|
249
|
+
## Tips
|
217
250
|
|
218
251
|
If you are using ttyest2 to test your CLI, using sh is easier than bash because you don't have to worry about user, current working directory, etc. as shown in the examples.
|
219
252
|
|
data/Rakefile
CHANGED
File without changes
|
File without changes
|
data/lib/ttytest/capture.rb
CHANGED
File without changes
|
data/lib/ttytest/constants.rb
CHANGED
data/lib/ttytest/matchers.rb
CHANGED
@@ -46,6 +46,7 @@ module TTYtest
|
|
46
46
|
raise MatchError,
|
47
47
|
"expected row #{row_number} to be like #{expected.inspect} but got #{actual.inspect}\nEntire screen:\n#{self}"
|
48
48
|
end
|
49
|
+
alias assert_row_contains assert_row_like
|
49
50
|
|
50
51
|
# Asserts the contents of a single row starts with expected string
|
51
52
|
# @param [Integer] row_number the row (starting from 0) to test against
|
data/lib/ttytest/terminal.rb
CHANGED
@@ -21,70 +21,127 @@ module TTYtest
|
|
21
21
|
# @!method send_keys(*keys)
|
22
22
|
# Simulate typing keys into the terminal. For canonical cli's/shells which read line by line.
|
23
23
|
# @param [String] keys keys to send to the terminal
|
24
|
+
|
24
25
|
# @!method send_keys_one_at_a_time(keys)
|
25
26
|
# Simulate typing keys into the terminal. For noncanonical cli's/shells which read character by character.
|
26
27
|
# @param [String] keys keys to send to the terminal
|
28
|
+
|
27
29
|
# @!method send_line(line)
|
28
30
|
# Simulate sending a line to the terminal and hitting enter.
|
31
|
+
# Can send multiline input, but if you want to send several commands at once, see send_lines(lines)
|
32
|
+
# @param [String] line the line to send to the terminal
|
33
|
+
|
29
34
|
# @!method send_line_then_sleep(line, sleep_time)
|
30
|
-
# Simulate sending a line to the terminal and hitting enter, then
|
35
|
+
# Simulate sending a line to the terminal and hitting enter, then sleeping for sleep_time.
|
36
|
+
# @param [String] line the line to send to the terminal
|
37
|
+
# @param [Integer] sleep_time the amount of time to sleep after sending the line
|
38
|
+
|
39
|
+
# @!method send_lines(lines)
|
40
|
+
# Simulate sending a multiple lines to the terminal and hitting enter after each line.
|
41
|
+
# @param [String] lines array of lines to send to the terminal
|
42
|
+
|
43
|
+
# @!method send_lines_then_sleep(lines, sleep_time)
|
44
|
+
# Simulate sending multiples lines to the terminal and hitting enter after each line.
|
45
|
+
# After sending all lines, then wait for the sleep_time.
|
46
|
+
# @param [String] line the line to send to the terminal
|
47
|
+
# @param [Integer] sleep_time the amount of time to sleep after sending the line
|
48
|
+
|
49
|
+
# @!method send_line_then_sleep_and_repeat(lines, sleep_time)
|
50
|
+
# Simulate sending a line to the terminal and hitting enter, then sleeping for sleep_time.
|
51
|
+
# before sending the next line.
|
52
|
+
# @param [String] line the line to send to the terminal
|
53
|
+
# @param [Integer] sleep_time the amount of time to sleep after sending the line
|
54
|
+
|
31
55
|
# @!method send_newline
|
32
56
|
# Simulate typing enter by sending newline character to the terminal.
|
33
|
-
|
57
|
+
|
58
|
+
# @!method send_newlines(number_of_times)
|
59
|
+
# Simulates sending newline the specified number of times.
|
60
|
+
# @param [Integer] number_of_times number of times to send newline
|
61
|
+
|
62
|
+
# @!method send_enter
|
63
|
+
# Simulate typing enter by sending newline character to the terminal.
|
64
|
+
|
65
|
+
# @!method send_enters(number_of_times)
|
34
66
|
# Simulates sending newline the specified number of times.
|
35
67
|
# @param [Integer] number of times to send newline
|
68
|
+
|
36
69
|
# @!method send_delete
|
37
70
|
# Simulate typing the delete key in the terminal.
|
38
|
-
|
71
|
+
|
72
|
+
# @!method send_deletes(number_of_times)
|
39
73
|
# Simulates typing delete the specified number of times.
|
40
74
|
# @param [Integer] number of times to send delete
|
75
|
+
|
41
76
|
# @!method send_backspace
|
42
77
|
# Simulate typing the backspace key in the terminal.
|
43
|
-
|
78
|
+
|
79
|
+
# @!method send_backspaces(number_of_times)
|
44
80
|
# Simulates typing backspace the specified number of times.
|
45
81
|
# @param [Integer] number of times to send backspace
|
82
|
+
|
46
83
|
# @!method send_left_arrow
|
47
84
|
# Simulate typing the left arrow key in the terminal.
|
48
|
-
|
85
|
+
|
86
|
+
# @!method send_left_arrows(number_of_times)
|
49
87
|
# Simulates typing left arrow the specified number of times.
|
50
88
|
# @param [Integer] number of times to send left arrow
|
89
|
+
|
51
90
|
# @!method send_right_arrow
|
52
91
|
# Simulate typing the right arrow key in the terminal.
|
53
|
-
|
92
|
+
|
93
|
+
# @!method send_right_arrows(number_of_times)
|
54
94
|
# Simulates typing right arrow the specified number of times.
|
55
95
|
# @param [Integer] number of times to send right arrow
|
96
|
+
|
56
97
|
# @!method send_down_arrow
|
57
98
|
# Simulate typing the down arrow key in the terminal.
|
58
|
-
|
99
|
+
|
100
|
+
# @!method send_down_arrows(number_of_times)
|
59
101
|
# Simulates typing the down arrow the specified number of times.
|
60
102
|
# @param [Integer] number of times to send down arrow
|
103
|
+
|
61
104
|
# @!method send_up_arrow
|
62
105
|
# Simulate typing the up arrow key in the terminal.
|
63
|
-
|
106
|
+
|
107
|
+
# @!method send_up_arrows(number_of_times)
|
64
108
|
# Simulates typing the up arrow the specified number of times.
|
65
109
|
# @param [Integer] number of times to send up arrow
|
66
|
-
|
110
|
+
|
111
|
+
# @!method send_keys_exact(keys)
|
67
112
|
# Send tmux send-keys command to the terminal, such as DC or Enter, to simulate pressing that key in the terminal.
|
113
|
+
# @param [String] keys the line to send to the terminal
|
114
|
+
|
68
115
|
# @!method send_home
|
69
116
|
# Simulates typing in the Home key in the terminal.
|
117
|
+
|
70
118
|
# @!method send_end
|
71
119
|
# Simulates typing in the End key in the terminal.
|
120
|
+
|
72
121
|
# @!method send_clear
|
73
122
|
# Clears the screen in the terminal using ascii clear command.
|
123
|
+
|
74
124
|
# @!method send_escape
|
75
125
|
# Simulates typing in the Escape (ESC) key in the terminal.
|
126
|
+
|
127
|
+
# @!method send_escapes(number_of_times)
|
128
|
+
# Simulates typing in the Escape (ESC) key in the terminal the specified number of times.
|
129
|
+
# @param [Integer] number of times to send escape
|
130
|
+
|
76
131
|
# @!method capture
|
77
132
|
# Capture the current state of the terminal
|
78
133
|
# @return [Capture] instantaneous state of the terminal when called
|
79
134
|
def_delegators :@driver_terminal,
|
80
135
|
:send_keys, :send_keys_one_at_a_time,
|
81
136
|
:send_line, :send_line_then_sleep,
|
137
|
+
:send_lines, :send_lines_then_sleep, :send_line_then_sleep_and_repeat,
|
82
138
|
:send_newline, :send_newlines,
|
139
|
+
:send_enter, :send_enters,
|
83
140
|
:send_delete, :send_deletes,
|
84
141
|
:send_backspace, :send_backspaces,
|
85
142
|
:send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
|
86
143
|
:send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
|
87
|
-
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape,
|
144
|
+
:send_keys_exact, :send_home, :send_end, :send_clear, :send_escape, :send_escapes,
|
88
145
|
:capture
|
89
146
|
|
90
147
|
# @!method print
|
data/lib/ttytest/tmux/driver.rb
CHANGED
@@ -39,6 +39,14 @@ module TTYtest
|
|
39
39
|
Terminal.new(session)
|
40
40
|
end
|
41
41
|
|
42
|
+
def new_default_sh_terminal
|
43
|
+
new_terminal(%(PS1='$ ' /bin/sh), width: 80, height: 24)
|
44
|
+
end
|
45
|
+
|
46
|
+
def new_sh_terminal(width: 80, height: 24)
|
47
|
+
new_terminal(%(PS1='$ ' /bin/sh), width: width, height: height)
|
48
|
+
end
|
49
|
+
|
42
50
|
# @api private
|
43
51
|
def tmux(*args)
|
44
52
|
ensure_available
|
data/lib/ttytest/tmux/session.rb
CHANGED
@@ -67,9 +67,29 @@ module TTYtest
|
|
67
67
|
sleep sleep_time
|
68
68
|
end
|
69
69
|
|
70
|
+
def send_lines(*lines)
|
71
|
+
lines.each do |line|
|
72
|
+
send_line(line)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def send_lines_then_sleep(*lines, sleep_time)
|
77
|
+
lines.each do |line|
|
78
|
+
send_line(line)
|
79
|
+
end
|
80
|
+
sleep sleep_time
|
81
|
+
end
|
82
|
+
|
83
|
+
def send_line_then_sleep_and_repeat(*lines, sleep_time)
|
84
|
+
lines.each do |line|
|
85
|
+
send_line_then_sleep(line, sleep_time)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
70
89
|
def send_newline
|
71
90
|
driver.tmux(*%W[send-keys -t #{name} -l], %(\n))
|
72
91
|
end
|
92
|
+
alias send_enter send_newline
|
73
93
|
|
74
94
|
def send_newlines(number_of_times)
|
75
95
|
while number_of_times.positive?
|
@@ -77,6 +97,7 @@ module TTYtest
|
|
77
97
|
number_of_times -= 1
|
78
98
|
end
|
79
99
|
end
|
100
|
+
alias send_enters send_newlines
|
80
101
|
|
81
102
|
def send_delete
|
82
103
|
send_keys_exact(%(DC))
|
@@ -169,6 +190,13 @@ module TTYtest
|
|
169
190
|
send_keys_exact(%(Escape))
|
170
191
|
end
|
171
192
|
|
193
|
+
def send_escapes(number_of_times)
|
194
|
+
while number_of_times.positive?
|
195
|
+
send_escape
|
196
|
+
number_of_times -= 1
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
172
200
|
private
|
173
201
|
|
174
202
|
attr_reader :driver, :name
|
data/lib/ttytest/tmux/tmux.conf
CHANGED
File without changes
|
data/lib/ttytest/version.rb
CHANGED
data/lib/ttytest.rb
CHANGED
@@ -17,7 +17,15 @@ module TTYtest
|
|
17
17
|
# @param [Integer] width width of the new terminal
|
18
18
|
# @param [Integer] height height of the new terminal
|
19
19
|
# @return [Terminal] a new terminal running the specified command
|
20
|
-
|
20
|
+
|
21
|
+
# @!method new_default_sh_terminal
|
22
|
+
# Create a new terminal using '/bin/sh' with width: 80 and height: 24.
|
23
|
+
# Useful for Unixes.
|
24
|
+
|
25
|
+
# @!method new_sh_terminal(width: 80, height: 24)
|
26
|
+
# Create a new terminal using '/bin/sh' with ability to set width and height.
|
27
|
+
# Useful for Unixes.
|
28
|
+
def_delegators :driver, :new_terminal, :new_default_sh_terminal, :new_sh_terminal
|
21
29
|
end
|
22
30
|
|
23
31
|
class MatchError < StandardError; end
|
data/notes.txt
CHANGED
data/ttytest2.gemspec
CHANGED
File without changes
|
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: 0.
|
4
|
+
version: 1.0.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-
|
11
|
+
date: 2025-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|