ttytest2 0.9.11 → 0.9.13

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.
@@ -11,7 +11,9 @@ module TTYtest
11
11
  BACKSPACE = 8.chr
12
12
  TAB = 9.chr # \t
13
13
  NEWLINE = 10.chr # \n
14
+ ENTER = 10.chr # \n
14
15
  VERTICAL_TAB = 11.chr # \v
16
+ SHIFT_ENTER = 11.chr # \v
15
17
  FORM_FEED = 12.chr # \f
16
18
  CTRLL = 12.chr
17
19
  CARRIAGE_RETURN = 13.chr # \r
@@ -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
@@ -21,65 +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
+
29
+ # @!method send_line(line)
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
+
34
+ # @!method send_line_then_sleep(line, sleep_time)
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
+
27
55
  # @!method send_newline
28
56
  # Simulate typing enter by sending newline character to the terminal.
29
- # @!method send_newlines
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)
30
66
  # Simulates sending newline the specified number of times.
31
67
  # @param [Integer] number of times to send newline
68
+
32
69
  # @!method send_delete
33
70
  # Simulate typing the delete key in the terminal.
34
- # @!method send_deletes
71
+
72
+ # @!method send_deletes(number_of_times)
35
73
  # Simulates typing delete the specified number of times.
36
74
  # @param [Integer] number of times to send delete
75
+
37
76
  # @!method send_backspace
38
77
  # Simulate typing the backspace key in the terminal.
39
- # @!method send_backspaces
78
+
79
+ # @!method send_backspaces(number_of_times)
40
80
  # Simulates typing backspace the specified number of times.
41
81
  # @param [Integer] number of times to send backspace
82
+
42
83
  # @!method send_left_arrow
43
84
  # Simulate typing the left arrow key in the terminal.
44
- # @!method send_left_arrows
85
+
86
+ # @!method send_left_arrows(number_of_times)
45
87
  # Simulates typing left arrow the specified number of times.
46
88
  # @param [Integer] number of times to send left arrow
89
+
47
90
  # @!method send_right_arrow
48
91
  # Simulate typing the right arrow key in the terminal.
49
- # @!method send_right_arrows
92
+
93
+ # @!method send_right_arrows(number_of_times)
50
94
  # Simulates typing right arrow the specified number of times.
51
95
  # @param [Integer] number of times to send right arrow
96
+
52
97
  # @!method send_down_arrow
53
98
  # Simulate typing the down arrow key in the terminal.
54
- # @!method send_down_arrows
99
+
100
+ # @!method send_down_arrows(number_of_times)
55
101
  # Simulates typing the down arrow the specified number of times.
56
102
  # @param [Integer] number of times to send down arrow
103
+
57
104
  # @!method send_up_arrow
58
105
  # Simulate typing the up arrow key in the terminal.
59
- # @!method send_up_arrows
106
+
107
+ # @!method send_up_arrows(number_of_times)
60
108
  # Simulates typing the up arrow the specified number of times.
61
109
  # @param [Integer] number of times to send up arrow
62
- # @!method send_keys_exact
110
+
111
+ # @!method send_keys_exact(keys)
63
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
+
64
115
  # @!method send_home
65
116
  # Simulates typing in the Home key in the terminal.
117
+
66
118
  # @!method send_end
67
119
  # Simulates typing in the End key in the terminal.
120
+
68
121
  # @!method send_clear
69
122
  # Clears the screen in the terminal using ascii clear command.
123
+
70
124
  # @!method send_escape
71
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
+
72
131
  # @!method capture
73
132
  # Capture the current state of the terminal
74
133
  # @return [Capture] instantaneous state of the terminal when called
75
134
  def_delegators :@driver_terminal,
76
135
  :send_keys, :send_keys_one_at_a_time,
136
+ :send_line, :send_line_then_sleep,
137
+ :send_lines, :send_lines_then_sleep, :send_line_then_sleep_and_repeat,
77
138
  :send_newline, :send_newlines,
139
+ :send_enter, :send_enters,
78
140
  :send_delete, :send_deletes,
79
141
  :send_backspace, :send_backspaces,
80
142
  :send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
81
143
  :send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
82
- :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,
83
145
  :capture
84
146
 
85
147
  # @!method print
@@ -13,7 +13,8 @@ module TTYtest
13
13
  ObjectSpace.define_finalizer(@id, proc {
14
14
  begin
15
15
  driver.tmux(*%W[kill-session -t #{name}])
16
- rescue ThreadError => _e # final session always throws, ThreadError can't alloc new
16
+ rescue ThreadError => _e # final session always throws during testing (running rake),
17
+ # throws error 'ThreadError can't alloc new'
17
18
  end
18
19
  })
19
20
  end
@@ -54,9 +55,41 @@ module TTYtest
54
55
  end
55
56
  end
56
57
 
58
+ # Send line to tmux, no need to worry about newline character
59
+ def send_line(line)
60
+ send_keys_one_at_a_time(line)
61
+ send_newline unless line[-1] == '\n'
62
+ end
63
+
64
+ # Send line then sleep for sleep_time
65
+ def send_line_then_sleep(line, sleep_time)
66
+ send_line(line)
67
+ sleep sleep_time
68
+ end
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
+
57
89
  def send_newline
58
90
  driver.tmux(*%W[send-keys -t #{name} -l], %(\n))
59
91
  end
92
+ alias send_enter send_newline
60
93
 
61
94
  def send_newlines(number_of_times)
62
95
  while number_of_times.positive?
@@ -64,6 +97,7 @@ module TTYtest
64
97
  number_of_times -= 1
65
98
  end
66
99
  end
100
+ alias send_enters send_newlines
67
101
 
68
102
  def send_delete
69
103
  send_keys_exact(%(DC))
@@ -156,6 +190,13 @@ module TTYtest
156
190
  send_keys_exact(%(Escape))
157
191
  end
158
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
+
159
200
  private
160
201
 
161
202
  attr_reader :driver, :name
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TTYtest
4
- VERSION = '0.9.11'
4
+ VERSION = '0.9.13'
5
5
  end
data/notes.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  to push new version to github
2
- git tag v0.9.11
2
+ git tag v0.9.13
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-0.9.11.gem
7
+ gem push ttytest2-0.9.13.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: 0.9.11
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-01-06 00:00:00.000000000 Z
11
+ date: 2025-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,8 +94,7 @@ files:
94
94
  - Gemfile
95
95
  - README.md
96
96
  - Rakefile
97
- - examples/canonical_integration_tests.rb
98
- - examples/noncanonical_integration_tests.rb
97
+ - examples/integration_tests.rb
99
98
  - lib/ttytest.rb
100
99
  - lib/ttytest/capture.rb
101
100
  - lib/ttytest/constants.rb
@@ -1,85 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- # example testing a noncanonical shell, ncsh
5
-
6
- require 'ttytest'
7
-
8
- START_COL = 19
9
-
10
- def assert_check_new_row(row)
11
- @tty.assert_row_starts_with(row, "#{ENV['USER']}:")
12
- @tty.assert_row_like(row, 'ncsh')
13
- @tty.assert_row_ends_with(row, '$')
14
- @tty.assert_cursor_position(START_COL, row)
15
- end
16
-
17
- @tty = TTYtest.new_terminal(%(PS1='$ ' ./bin/ncsh), width: 80, height: 24)
18
-
19
- row = 0
20
-
21
- # # # # Basic Tests # # # #
22
- puts 'Starting basic tests'
23
-
24
- @tty.assert_row_starts_with(row, 'ncsh: startup time: ')
25
- row += 1
26
-
27
- assert_check_new_row(row)
28
- @tty.send_keys(%(ls))
29
- @tty.assert_cursor_position(START_COL + 2, 1)
30
- @tty.send_newline
31
- @tty.assert_row_ends_with(row, 'ls')
32
- row += 1
33
- @tty.assert_row_starts_with(row, 'LICENSE')
34
- row = 9
35
-
36
- assert_check_new_row(row)
37
- @tty.send_keys(%(echo hello))
38
- @tty.send_newline
39
- row += 1
40
- @tty.assert_row(row, 'hello')
41
- row += 1
42
-
43
- assert_check_new_row(row)
44
- @tty.send_keys(%(lss)) # send a bad command
45
- @tty.send_newline
46
- row += 1
47
- @tty.assert_row(row, 'ncsh: Could not find command or directory: No such file or directory')
48
- row += 1
49
-
50
- puts 'Starting backspace tests'
51
-
52
- # end of line backspace
53
- assert_check_new_row(row)
54
- @tty.send_keys(%(l))
55
- @tty.send_backspace
56
- assert_check_new_row(row)
57
-
58
- # multiple end of line backspaces
59
- @tty.send_keys(%(lsssss))
60
- @tty.send_backspaces(4)
61
- @tty.assert_row_ends_with(row, 'ls')
62
- @tty.send_backspaces(2)
63
- @tty.send_keys(%(echo hello)) # make sure buffer is properly formed after backspaces
64
- @tty.send_newline
65
- row += 1
66
- @tty.assert_row(row, 'hello')
67
- row += 1
68
-
69
- # midline backspace
70
- assert_check_new_row(row)
71
- @tty.send_keys(%(lsssss))
72
- @tty.assert_cursor_position(START_COL + 6, row)
73
- @tty.send_left_arrows(2)
74
- @tty.assert_cursor_position(START_COL + 4, row)
75
- @tty.send_backspaces(4)
76
- @tty.assert_cursor_position(START_COL, row)
77
- @tty.assert_row_ends_with(row, '$ ss')
78
- @tty.send_right_arrows(2)
79
- @tty.assert_cursor_position(START_COL + 2, row)
80
- @tty.send_backspaces(2)
81
- @tty.assert_cursor_position(START_COL, row)
82
- @tty.send_keys(%(echo hello)) # make sure buffer is properly formed after backspaces
83
- @tty.send_newline
84
- row += 1
85
- @tty.assert_row(row, 'hello')
@@ -1,80 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- # example testing a canonical shell called shl
5
-
6
- require 'ttytest'
7
-
8
- START_COL = 19
9
-
10
- def assert_check_new_row(row)
11
- @tty.assert_row_starts_with(row, "#{ENV['USER']}:")
12
- @tty.assert_row_like(row, 'shl')
13
- @tty.assert_row_ends_with(row, '$')
14
- @tty.assert_cursor_position(START_COL, row)
15
- end
16
-
17
- @tty = TTYtest.new_terminal(%(PS1='$ ' ./bin/shl), width: 80, height: 24)
18
-
19
- row = 0
20
-
21
- @tty.assert_row_starts_with(row, 'shl: startup time: ')
22
- row += 1
23
-
24
- assert_check_new_row(row)
25
- @tty.send_keys_one_at_a_time(%(ls))
26
- @tty.assert_cursor_position(START_COL + 2, 1)
27
- @tty.send_newline
28
- @tty.assert_row_ends_with(row, 'ls')
29
- row += 1
30
- @tty.assert_row_starts_with(row, 'LICENSE')
31
- row = 9
32
-
33
- assert_check_new_row(row)
34
- @tty.send_keys_one_at_a_time(%(echo hello))
35
- @tty.send_newline
36
- row += 1
37
- @tty.assert_row(row, 'hello')
38
- row += 1
39
-
40
- assert_check_new_row(row)
41
- @tty.send_keys_one_at_a_time(%(lss)) # send a bad command
42
- @tty.send_newline
43
- row += 1
44
- @tty.assert_row(row, 'shl: Could not find command or directory: No such file or directory')
45
- row += 1
46
-
47
- # end of line backspace
48
- assert_check_new_row(row)
49
- @tty.send_keys_one_at_a_time(%(l))
50
- @tty.send_backspace
51
- assert_check_new_row(row)
52
-
53
- # multiple end of line backspaces
54
- @tty.send_keys_one_at_a_time(%(lsssss))
55
- @tty.send_backspaces(4)
56
- @tty.assert_row_ends_with(row, '$ ls')
57
- @tty.send_backspaces(2)
58
- @tty.send_keys_one_at_a_time(%(echo hello)) # make sure buffer is properly formed after backspaces
59
- @tty.send_newline
60
- row += 1
61
- @tty.assert_row(row, 'hello')
62
- row += 1
63
-
64
- # midline backspace
65
- assert_check_new_row(row)
66
- @tty.send_keys_one_at_a_time(%(lsssss))
67
- @tty.assert_cursor_position(START_COL + 6, row)
68
- @tty.send_left_arrows(2)
69
- @tty.assert_cursor_position(START_COL + 4, row)
70
- @tty.send_backspaces(4)
71
- @tty.assert_cursor_position(START_COL, row)
72
- @tty.assert_row_ends_with(row, '$ ss')
73
- @tty.send_right_arrows(2)
74
- @tty.assert_cursor_position(START_COL + 2, row)
75
- @tty.send_backspaces(2)
76
- @tty.assert_cursor_position(START_COL, row)
77
- @tty.send_keys_one_at_a_time(%(echo hello)) # make sure buffer is properly formed after backspaces
78
- @tty.send_newline
79
- row += 1
80
- @tty.assert_row(row, 'hello')