ttytest2 0.9.0 → 0.9.1

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: 9c871fc585971f615966d7797478185dd942e78b6cfcfc9324773edfd789664f
4
- data.tar.gz: 4a7a6b509c222510918cdad040e958c09bdd653700b3a3871f087cdadf7a5c9b
3
+ metadata.gz: da8ddbaf4a49037e8dda3fb31986824c75819abbee94fb7954263c36a8e63414
4
+ data.tar.gz: 7091feb0fdac4857c1c0bf47a7c8158d8c90bd48d1ff321fec53aeab185443ec
5
5
  SHA512:
6
- metadata.gz: 84d1c8b052ce38fdad9d0780774a0aae6a378b60804a156a74099e69b62f741f49b00887296e03a49030fe62c25d8bceef2b28e3a3ad2ddbd979cabbf7643b28
7
- data.tar.gz: 4fc3e3186fe6827bb987f18e2d04aa9cfbe49c6c31f3d8a5e8ab92c6ec6f81264df11298cddbdeb70c46630f20ba056d29608f2df90549d6e3cbd25dbe7f4d29
6
+ metadata.gz: baab5b496e22d73a133084b2a4d58fc2fb83c95325c02227a50847adcbb876fe23f7a71e80efd69c12c2730aff64866222004db102b21613c4e4301455c15cd8
7
+ data.tar.gz: d66c05f581f565f33c9305ec9c484346790184d64ca5bdfb4b9718d95c22b842dbd2f689634548863f93cdcaced2dc94f4048dc66e6101dba8d2ef4f4856bae9
data/README.md CHANGED
@@ -30,13 +30,24 @@ Available assertions:
30
30
  * specify the cursor is currently hidden: `assert_cursor_hidden`
31
31
  * specify the contents of the entire terminal window: `assert_contents(lines_of_terminal)`
32
32
 
33
- ### Sending output
33
+ ### Sending Output
34
34
 
35
35
  You can send output to the terminal with the following calls.
36
36
 
37
- * `send_keys(output)`
37
+ * `send_keys(output) # for canonical shells/cli's (or multi-character keys for noncanonical shells/cli's)`
38
+ * `send_keys_one_at_a_time(output) # for noncanonical shells/cli's`
39
+ * `send_keys_exact(output) # for sending tmux specific keys (DC for delete, Escape for ESC, etc.)`
40
+
41
+ ### Output Helpers
42
+
43
+ Helper functions to make sending output easier! They use the methods above under 'Sending Output' section under the hood.
44
+
38
45
  * `send_newline # equivalent to @tty.send_keys(%(\n))`
39
- * `send_keys_one_at_a_time(output)`
46
+ * `send_newlines(number_of_times) # equivalent to calling send_newline number_of_times`
47
+ * `send_backspace # equivalent to @tty.send_keys(TTYtest::BACKSPACE)`
48
+ * `send_backspaces(number_of_times) # equivalent to calling send_backspace number_of_times`
49
+ * `send_delete # equivalent to calling send_keys_exact(%(DC))`
50
+ * `send_deletes # equivalent to calling send_delete number_of_times`
40
51
 
41
52
  ### Example Canonical CLI/Shell
42
53
 
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'ttytest'
5
+
6
+ START_COL = 19
7
+
8
+ def assert_check_new_row(row)
9
+ @tty.assert_row_starts_with(row, "#{ENV['USER']}:")
10
+ @tty.assert_row_like(row, 'ncsh')
11
+ @tty.assert_row_ends_with(row, '$')
12
+ @tty.assert_cursor_position(START_COL, row)
13
+ end
14
+
15
+ @tty = TTYtest.new_terminal(%(PS1='$ ' ./bin/ncsh), width: 80, height: 24)
16
+
17
+ row = 0
18
+
19
+ # # # # Basic Tests # # # #
20
+ puts 'Starting basic tests'
21
+
22
+ @tty.assert_row_starts_with(row, 'ncsh: startup time: ')
23
+ row += 1
24
+
25
+ assert_check_new_row(row)
26
+ @tty.send_keys(%(ls))
27
+ @tty.assert_cursor_position(START_COL + 2, 1)
28
+ @tty.send_newline
29
+ @tty.assert_row_ends_with(row, 'ls')
30
+ row += 1
31
+ @tty.assert_row_starts_with(row, 'LICENSE')
32
+ row = 9
33
+
34
+ assert_check_new_row(row)
35
+ @tty.send_keys(%(echo hello))
36
+ @tty.send_newline
37
+ row += 1
38
+ @tty.assert_row(row, 'hello')
39
+ row += 1
40
+
41
+ assert_check_new_row(row)
42
+ @tty.send_keys(%(lss)) # send a bad command
43
+ @tty.send_newline
44
+ row += 1
45
+ @tty.assert_row(row, 'ncsh: Could not find command or directory: No such file or directory')
46
+ row += 1
47
+
48
+ puts 'Starting backspace tests'
49
+
50
+ # end of line backspace
51
+ assert_check_new_row(row)
52
+ @tty.send_keys(%(l))
53
+ @tty.send_backspace
54
+ assert_check_new_row(row)
55
+
56
+ # multiple end of line backspaces
57
+ @tty.send_keys(%(lsssss))
58
+ @tty.send_backspace
59
+ @tty.send_backspace
60
+ @tty.send_backspace
61
+ @tty.send_backspace
62
+ @tty.assert_row_ends_with(row, '$ ls')
63
+ @tty.send_backspace
64
+ @tty.send_backspace
65
+ @tty.send_keys(%(echo hello)) # make sure buffer is properly formed after backspaces
66
+ @tty.send_newline
67
+ row += 1
68
+ @tty.assert_row(row, 'hello')
69
+ row += 1
70
+
71
+ # midline backspace
72
+ assert_check_new_row(row)
73
+ @tty.send_keys(%(lsssss))
74
+ @tty.assert_cursor_position(START_COL + 6, row)
75
+ @tty.send_keys(TTYtest::LEFT_ARROW)
76
+ @tty.send_keys(TTYtest::LEFT_ARROW)
77
+ @tty.assert_cursor_position(START_COL + 4, row)
78
+ @tty.send_backspace
79
+ @tty.send_backspace
80
+ @tty.send_backspace
81
+ @tty.send_backspace
82
+ @tty.assert_cursor_position(START_COL, row)
83
+ @tty.assert_row_ends_with(row, '$ ss')
84
+ @tty.send_keys(TTYtest::RIGHT_ARROW)
85
+ @tty.send_keys(TTYtest::RIGHT_ARROW)
86
+ @tty.assert_cursor_position(START_COL + 2, row)
87
+ @tty.send_backspace
88
+ @tty.send_backspace
89
+ @tty.assert_cursor_position(START_COL, row)
90
+ @tty.send_keys(%(echo hello)) # make sure buffer is properly formed after backspaces
91
+ @tty.send_newline
92
+ row += 1
93
+ @tty.assert_row(row, 'hello')
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'ttytest'
5
+
6
+ START_COL = 19
7
+
8
+ def assert_check_new_row(row)
9
+ @tty.assert_row_starts_with(row, "#{ENV['USER']}:")
10
+ @tty.assert_row_like(row, 'ncsh')
11
+ @tty.assert_row_ends_with(row, '$')
12
+ @tty.assert_cursor_position(START_COL, row)
13
+ end
14
+
15
+ @tty = TTYtest.new_terminal(%(PS1='$ ' ./bin/ncsh), width: 80, height: 24)
16
+
17
+ row = 0
18
+
19
+ # # # # Basic Tests # # # #
20
+ puts 'Starting basic tests'
21
+
22
+ @tty.assert_row_starts_with(row, 'ncsh: startup time: ')
23
+ row += 1
24
+
25
+ assert_check_new_row(row)
26
+ @tty.send_keys_one_at_a_time(%(ls))
27
+ @tty.assert_cursor_position(START_COL + 2, 1)
28
+ @tty.send_newline
29
+ @tty.assert_row_ends_with(row, 'ls')
30
+ row += 1
31
+ @tty.assert_row_starts_with(row, 'LICENSE')
32
+ row = 9
33
+
34
+ assert_check_new_row(row)
35
+ @tty.send_keys_one_at_a_time(%(echo hello))
36
+ @tty.send_newline
37
+ row += 1
38
+ @tty.assert_row(row, 'hello')
39
+ row += 1
40
+
41
+ assert_check_new_row(row)
42
+ @tty.send_keys_one_at_a_time(%(lss)) # send a bad command
43
+ @tty.send_newline
44
+ row += 1
45
+ @tty.assert_row(row, 'ncsh: Could not find command or directory: No such file or directory')
46
+ row += 1
47
+
48
+ puts 'Starting backspace tests'
49
+
50
+ # end of line backspace
51
+ assert_check_new_row(row)
52
+ @tty.send_keys_one_at_a_time(%(l))
53
+ @tty.send_backspace
54
+ assert_check_new_row(row)
55
+
56
+ # multiple end of line backspaces
57
+ @tty.send_keys_one_at_a_time(%(lsssss))
58
+ @tty.send_backspace
59
+ @tty.send_backspace
60
+ @tty.send_backspace
61
+ @tty.send_backspace
62
+ @tty.assert_row_ends_with(row, '$ ls')
63
+ @tty.send_backspace
64
+ @tty.send_backspace
65
+ @tty.send_keys_one_at_a_time(%(echo hello)) # make sure buffer is properly formed after backspaces
66
+ @tty.send_newline
67
+ row += 1
68
+ @tty.assert_row(row, 'hello')
69
+ row += 1
70
+
71
+ # midline backspace
72
+ assert_check_new_row(row)
73
+ @tty.send_keys_one_at_a_time(%(lsssss))
74
+ @tty.assert_cursor_position(START_COL + 6, row)
75
+ @tty.send_keys(TTYtest::LEFT_ARROW)
76
+ @tty.send_keys(TTYtest::LEFT_ARROW)
77
+ @tty.assert_cursor_position(START_COL + 4, row)
78
+ @tty.send_backspace
79
+ @tty.send_backspace
80
+ @tty.send_backspace
81
+ @tty.send_backspace
82
+ @tty.assert_cursor_position(START_COL, row)
83
+ @tty.assert_row_ends_with(row, '$ ss')
84
+ @tty.send_keys(TTYtest::RIGHT_ARROW)
85
+ @tty.send_keys(TTYtest::RIGHT_ARROW)
86
+ @tty.assert_cursor_position(START_COL + 2, row)
87
+ @tty.send_backspace
88
+ @tty.send_backspace
89
+ @tty.assert_cursor_position(START_COL, row)
90
+ @tty.send_keys_one_at_a_time(%(echo hello)) # make sure buffer is properly formed after backspaces
91
+ @tty.send_newline
92
+ row += 1
93
+ @tty.assert_row(row, 'hello')
@@ -36,7 +36,11 @@ module TTYtest
36
36
  # Capture the current state of the terminal
37
37
  # @return [Capture] instantaneous state of the terminal when called
38
38
  def_delegators :@driver_terminal,
39
- :send_keys, :send_keys_one_at_a_time, :send_newline, :send_delete, :send_backspace, :send_keys_exact,
39
+ :send_keys, :send_keys_one_at_a_time,
40
+ :send_newline, :send_newlines,
41
+ :send_delete, :send_deletes,
42
+ :send_backspace, :send_backspaces,
43
+ :send_keys_exact,
40
44
  :capture
41
45
 
42
46
  # @!method rows
@@ -57,14 +57,35 @@ module TTYtest
57
57
  driver.tmux(*%W[send-keys -t #{name} -l], %(\n))
58
58
  end
59
59
 
60
+ def send_newlines(number_of_times)
61
+ while number_of_times.positive?
62
+ send_newline
63
+ number_of_times -= 1
64
+ end
65
+ end
66
+
60
67
  def send_delete
61
68
  send_keys_exact(%(DC))
62
69
  end
63
70
 
71
+ def send_deletes(number_of_times)
72
+ while number_of_times.positive?
73
+ send_delete
74
+ number_of_times -= 1
75
+ end
76
+ end
77
+
64
78
  def send_backspace
65
79
  send_keys_exact(%(BSpace))
66
80
  end
67
81
 
82
+ def send_backspaces(number_of_times)
83
+ while number_of_times.positive?
84
+ send_backspace
85
+ number_of_times -= 1
86
+ end
87
+ end
88
+
68
89
  # Useful to send send-keys commands to tmux without sending them as a string literal.
69
90
  # So you can send Escape for escape key, DC for delete, etc.
70
91
  # Uses the same key bindings as bind-key as well. C-c represents Ctrl + C keys, F1 is F1 key, etc.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TTYtest
4
- VERSION = '0.9.0'
4
+ VERSION = '0.9.1'
5
5
  end
data/notes.txt CHANGED
@@ -1,7 +1,7 @@
1
- to push new version to github,
2
- git tag v0.9.0
1
+ to push new version to github
2
+ git tag v0.9.1
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.0.gem
7
+ gem push ttytest2-0.9.1.gem
data/ttytest2.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.email = ['alexeski@gmail.com']
12
12
 
13
13
  spec.summary = 'ttytest2 is an integration test framework for interactive tty applications. Based on TTYtest!'
14
- spec.description = 'ttytest2 allows running shell and/or cli applications inside of tmux and then making assertions on the output.'
14
+ spec.description = 'ttytest2 allows running shell/cli applications inside of tmux and then making assertions on the output.'
15
15
  spec.homepage = 'https://github.com/a-eski/ttytest2'
16
16
  spec.license = 'MIT'
17
17
 
@@ -24,8 +24,8 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.required_ruby_version = '>= 3.2.3'
26
26
 
27
- spec.add_development_dependency 'bundler'
27
+ spec.add_development_dependency 'bundler', '~> 2.5'
28
28
  spec.add_development_dependency 'minitest', '~> 5.0'
29
29
  spec.add_development_dependency 'rake', '~> 13.0'
30
- spec.add_development_dependency 'yard'
30
+ spec.add_development_dependency 'yard', '~> 0.9'
31
31
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ttytest2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Eski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-19 00:00:00.000000000 Z
11
+ date: 2024-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '2.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '2.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -56,18 +56,18 @@ dependencies:
56
56
  name: yard
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '0.9'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
69
- description: ttytest2 allows running shell and/or cli applications inside of tmux
70
- and then making assertions on the output.
68
+ version: '0.9'
69
+ description: ttytest2 allows running shell/cli applications inside of tmux and then
70
+ making assertions on the output.
71
71
  email:
72
72
  - alexeski@gmail.com
73
73
  executables: []
@@ -79,6 +79,8 @@ files:
79
79
  - Gemfile
80
80
  - README.md
81
81
  - Rakefile
82
+ - examples/canonical_integration_tests.rb
83
+ - examples/noncanonical_integration_tests.rb
82
84
  - lib/ttytest.rb
83
85
  - lib/ttytest/capture.rb
84
86
  - lib/ttytest/constants.rb