ttytest2 0.9.12 → 0.9.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -3
- 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/session.rb +28 -0
- data/lib/ttytest/version.rb +1 -1
- 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: fd614376f0369112c875543a1d8cc498b0de69dd436e6158fd6d8f06bd4ee87f
|
4
|
+
data.tar.gz: 59373cd7e5699a8e6c96a3c0071efc4164d09ddfb71365291cf4a5d086b69bd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77eb7d0d56818eaa11b3f0ac84230f5100a50bfc0ccf45c67c34a0389005b55317b5a85d23ed68f5b65c923fe8a51efe620304dcc345c7cd4cf902ff80b8e8d4
|
7
|
+
data.tar.gz: 2a3d270669408488cd1e636231b336cd62e3606d1cd20dfd267858ca3e0a544ded977ecc657df82f2833a2a2a77c9f8d422428b84715377314e6c7faf57b81e7
|
data/README.md
CHANGED
@@ -95,9 +95,19 @@ You can send output to the terminal with the following calls.
|
|
95
95
|
Note: Most of the time send_line has the best ergonomics.
|
96
96
|
|
97
97
|
* `send_line(line)`: simulate typing in a command in the terminal and hitting enter!
|
98
|
+
|
98
99
|
* `send_line_then_sleep(line, sleep_time)`: simulate typing in a command in the terminal and hitting enter, then wait for sleep_time seconds.
|
100
|
+
|
101
|
+
* `send_lines(lines)`: for each line in lines, simulate sending the line and hitting enter.
|
102
|
+
|
103
|
+
* `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.
|
104
|
+
|
105
|
+
* `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.
|
106
|
+
|
99
107
|
* `send_keys(output)`: for canonical shells/CLI's (or multi-character keys for noncanonical shells/CLI's).
|
108
|
+
|
100
109
|
* `send_keys_one_at_a_time(output)`: for noncanonical shells/CLI's.
|
110
|
+
|
101
111
|
* `send_keys_exact(output)`: for sending tmux specific keys (any supported send-keys arguments like: DC for delete, Escape for ESC, etc.)
|
102
112
|
|
103
113
|
### Output Helpers
|
@@ -106,6 +116,8 @@ Helper functions to make sending output easier! They use the methods above under
|
|
106
116
|
|
107
117
|
* `send_newline` # simulate hitting enter, equivalent to @tty.send_keys(%(\n))
|
108
118
|
* `send_newlines(number_of_times)` # equivalent to calling send_newline number_of_times
|
119
|
+
* `send_enter` # alias for send_newline
|
120
|
+
* `send_enters(number_of_times)` # alias for send_newlines
|
109
121
|
* `send_backspace` # simulate hitting backspace, equivalent to @tty.send_keys(TTYtest::BACKSPACE)
|
110
122
|
* `send_backspaces(number_of_times)` # equivalent to calling send_backspace number_of_times
|
111
123
|
* `send_delete` # simulate hitting delete, equivalent to calling send_keys_exact(%(DC))
|
@@ -121,6 +133,8 @@ Helper functions to make sending output easier! They use the methods above under
|
|
121
133
|
* `send_home` # simulate pressing the Home key
|
122
134
|
* `send_end` # simulate pressing the End key
|
123
135
|
* `send_clear` # clear the screen by sending clear ascii code
|
136
|
+
* `send_escape`
|
137
|
+
* `send_escapes`
|
124
138
|
|
125
139
|
### F keys?
|
126
140
|
|
@@ -166,8 +180,6 @@ You can use the method rows to get all rows of the terminal as an array, of use
|
|
166
180
|
# if you want to programatically access the rows, you can do so using @tty.rows
|
167
181
|
p @tty.rows # is equivalent to above statement @tty.print_rows
|
168
182
|
|
169
|
-
|
170
|
-
|
171
183
|
# you can use @tty.capture to access the entire pane.
|
172
184
|
@tty.print # prints out the contents of the terminal:
|
173
185
|
# $ echo "Hello, world"
|
@@ -192,7 +204,9 @@ There are some commonly used keys available as constants to make interacting wit
|
|
192
204
|
TTYtest::BACKSPACE
|
193
205
|
TTYtest::TAB
|
194
206
|
TTYtest::NEWLINE # \n
|
195
|
-
TTYtest::
|
207
|
+
TTYtest::ENTER # \n
|
208
|
+
TTYtest::VERTICAL_TAB # \v
|
209
|
+
TTYtest::SHIFT_ENTER # \v
|
196
210
|
TTYtest::FORM_FEED # \f or New Page NP
|
197
211
|
TTYtest::CTRLL
|
198
212
|
TTYtest::CARRIAGE_RETURN # \r
|
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/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)
|
84
|
+
lines.each do |line|
|
85
|
+
send_line_then_sleep(line)
|
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/version.rb
CHANGED
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: 0.9.
|
4
|
+
version: 0.9.13
|
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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|