ttytest2 1.0.0 → 1.0.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: 4322aa40df769e1ed8a2095f5766199175afae71233c8308b3a6ef30322fedb2
4
- data.tar.gz: 3d94b40f20cbea852a6462d23d3922a6a1e7ef95573815320047279f47e8c76d
3
+ metadata.gz: 4e4921ed7f9ec57ffb18c82a6ad29df778485f1d6d3bad878c06cdab50ba303a
4
+ data.tar.gz: c05db30206186a54ec5a5fa6b23dd333a173bb210b18aaff2201647e01ac99d1
5
5
  SHA512:
6
- metadata.gz: 90580621915fddc1ba3b6390fc58e7787fdfa86336cb576abd3224a68c8cb88fbf665425d960153bd0cf4d170aa02afb63f14f53acc2f1f37711d8bbb0c244a1
7
- data.tar.gz: 44047668527313f4bcea17522d2c8ee77bf9e0695ebd89a6c68a01411305cd3389eb5e22e43c1c4861662414b7721b6772fd26d84b1364a8a447d9363af0ab04
6
+ metadata.gz: 0032e2da8ae48c097f614acbf908d5860732c78c09a98fe6738490e2675a6af54e043f499eb9367a8cd362070d8988cd79400b4c546803a57282f23dce3f2dc4
7
+ data.tar.gz: 4250ea672cc1d031fe5403bd21980e2e80b06095e2dc0d67df65d94d6f35904905fc0098480afb884d5008425207537aa9c6a2b73724b3d6ff40a4fbeb53a877
data/README.md CHANGED
@@ -39,6 +39,7 @@ The assertions will wait a specified amount of time (configurable, default 2 sec
39
39
 
40
40
  ``` ruby
41
41
  require 'ttytest'
42
+
42
43
  @tty = TTYtest.new_terminal(%(PS1='$ ' /bin/sh), width: 80, height: 7)
43
44
  @tty.assert_row(0, '$')
44
45
  @tty.assert_cursor_position(2, 0)
@@ -68,6 +69,31 @@ TTY
68
69
  # $
69
70
  ```
70
71
 
72
+ ### Initializing
73
+
74
+ Call one of these methods to initialize an instance of ttytest2.
75
+
76
+ * `new_terminal(cmd, width, height)`: initialize new tmux terminal instance and run cmd.
77
+
78
+ * `new_default_sh_terminal()`: intialize new tmux terminal instance using sh, width of 80, height of 24.
79
+
80
+ * `new_sh_terminal(width, height)`: intialize new tmux terminal instance using sh and width and height parameters.
81
+
82
+ ``` ruby
83
+ require 'ttytest'
84
+
85
+ # these are all equivalent
86
+ @tty = TTYtest.new_terminal(%(PS1='$ ' /bin/sh))
87
+ @tty = TTYtest.new_terminal(%(PS1='$ ' /bin/sh), width: 80, height: 24)
88
+ @tty = TTYtest.new_default_sh_terminal
89
+ @tty = TTYtest.new_sh_terminal
90
+ @tty = TTYtest.new_sh_terminal(width: 80, height: 24)
91
+
92
+ # you can also use other shells, like bash
93
+ @tty = TTYtest.new_terminal('/bin/bash')
94
+ @tty = TTYtest.new_terminal('/bin/bash', width: 80, height: 24)
95
+ ```
96
+
71
97
  ### Assertions
72
98
 
73
99
  The main way to use TTYtest is through assertions.
@@ -755,7 +755,7 @@ def stdout_and_stderr_redirection_tests(row)
755
755
  end
756
756
 
757
757
  row = 0
758
- @tty = TTYtest.new_terminal(%(PS1='$ ' ./bin/ncsh), width: 120, height: 120)
758
+ @tty = TTYtest.new_terminal(%(./bin/ncsh), width: 120, height: 120)
759
759
 
760
760
  row = startup_tests(row, true)
761
761
  row = basic_tests row
@@ -776,7 +776,7 @@ tab_autocompletion_tests row
776
776
  @tty.send_newline
777
777
 
778
778
  row = 0
779
- @tty = TTYtest.new_terminal(%(PS1='$ ' ./bin/ncsh), width: 180, height: 150)
779
+ @tty = TTYtest.new_terminal(%(./bin/ncsh), width: 180, height: 150)
780
780
  row = startup_tests(row, false)
781
781
  row = syntax_error_tests row
782
782
  row = stderr_redirection_tests row
@@ -10,6 +10,7 @@ module TTYtest
10
10
  def assert_row(row_number, expected)
11
11
  expected = expected.rstrip
12
12
  actual = row(row_number)
13
+
13
14
  return if actual == expected
14
15
 
15
16
  raise MatchError,
@@ -26,6 +27,7 @@ module TTYtest
26
27
  expected = expected.rstrip
27
28
  actual = row(row_number)
28
29
  column_end += 1
30
+
29
31
  return if actual[column_start, column_end].eql?(expected)
30
32
 
31
33
  raise MatchError,
@@ -41,6 +43,7 @@ module TTYtest
41
43
  def assert_row_like(row_number, expected)
42
44
  expected = expected.rstrip
43
45
  actual = row(row_number)
46
+
44
47
  return if actual.include?(expected)
45
48
 
46
49
  raise MatchError,
@@ -55,6 +58,7 @@ module TTYtest
55
58
  def assert_row_starts_with(row_number, expected)
56
59
  expected = expected.rstrip
57
60
  actual = row(row_number)
61
+
58
62
  return if actual.start_with?(expected)
59
63
 
60
64
  raise MatchError,
@@ -68,6 +72,7 @@ module TTYtest
68
72
  def assert_row_ends_with(row_number, expected)
69
73
  expected = expected.rstrip
70
74
  actual = row(row_number)
75
+
71
76
  return if actual.end_with?(expected)
72
77
 
73
78
  raise MatchError,
@@ -88,6 +93,23 @@ module TTYtest
88
93
  "expected row #{row_number} to match regexp #{regexp_str} but it did not. Row value #{actual.inspect}\nEntire screen:\n#{self}"
89
94
  end
90
95
 
96
+ # Asserts the contents of a multiple rows each match against the passed in regular expression
97
+ # @param [Integer] row_start the row (starting from 0) to test against
98
+ # @param [Integer] row_end the last row to test against
99
+ # @param [String] regexp_str the regular expression as a string that will be used to match with.
100
+ # @raise [MatchError] if the row doesn't match against the regular expression
101
+ def assert_rows_each_match_regexp(row_start, row_end, regexp_str)
102
+ regexp = Regexp.new(regexp_str)
103
+ row_end += 1 if row_end.zero?
104
+
105
+ rows.slice(row_start, row_end).each_with_index do |actual_row, index|
106
+ next if actual_row.match?(regexp)
107
+
108
+ raise MatchError,
109
+ "expected row #{index} to match regexp #{regexp_str} but it did not. Row value #{actual_row.inspect}\nEntire screen:\n#{self}"
110
+ end
111
+ end
112
+
91
113
  # Asserts that the cursor is in the expected position
92
114
  # @param [Integer] x cursor x (row) position, starting from 0
93
115
  # @param [Integer] y cursor y (column) position, starting from 0
@@ -95,6 +117,7 @@ module TTYtest
95
117
  def assert_cursor_position(x, y)
96
118
  expected = [x, y]
97
119
  actual = [cursor_x, cursor_y]
120
+
98
121
  return if actual == expected
99
122
 
100
123
  raise MatchError,
@@ -115,14 +138,11 @@ module TTYtest
115
138
  raise MatchError, "expected cursor to be hidden was visible\nEntire screen:\n#{self}"
116
139
  end
117
140
 
118
- # Asserts the full contents of the terminal
119
- # @param [String] expected the full expected contents of the terminal. Trailing whitespace on each line is ignored
120
- # @raise [MatchError] if the terminal doesn't match the expected content
121
- def assert_contents(expected)
141
+ def matched(expected, actual)
122
142
  expected_rows = expected.split("\n")
123
143
  diff = []
124
144
  matched = true
125
- rows.each_with_index do |actual_row, index|
145
+ actual.each_with_index do |actual_row, index|
126
146
  expected_row = (expected_rows[index] || '').rstrip
127
147
  if actual_row != expected_row
128
148
  diff << "-#{expected_row}"
@@ -133,32 +153,30 @@ module TTYtest
133
153
  end
134
154
  end
135
155
 
156
+ [matched, diff]
157
+ end
158
+
159
+ # Asserts the full contents of the terminal
160
+ # @param [String] expected the full expected contents of the terminal. Trailing whitespace on each line is ignored
161
+ # @raise [MatchError] if the terminal doesn't match the expected content
162
+ def assert_contents(expected)
163
+ matched, diff = matched(expected, rows)
164
+
136
165
  return if matched
137
166
 
138
167
  raise MatchError,
139
168
  "screen did not match expected content:\n--- expected\n+++ actual\n#{diff.join("\n")}"
140
169
  end
141
170
  alias assert_matches assert_contents
171
+ alias assert_screen assert_contents
142
172
 
143
173
  # Asserts the contents of the terminal at specified rows
144
174
  # @param [String] expected the expected contents of the terminal at specified rows. Trailing whitespace on each line is ignored
145
175
  # @raise [MatchError] if the terminal doesn't match the expected content
146
176
  def assert_contents_at(row_start, row_end, expected)
147
- expected_rows = expected.split("\n")
148
- diff = []
149
- matched = true
150
177
  row_end += 1 if row_end.zero?
151
178
 
152
- rows.slice(row_start, row_end).each_with_index do |actual_row, index|
153
- expected_row = (expected_rows[index] || '').rstrip
154
- if actual_row != expected_row
155
- diff << "-#{expected_row}"
156
- diff << "+#{actual_row}"
157
- matched = false
158
- else
159
- diff << " #{actual_row}".rstrip
160
- end
161
- end
179
+ matched, diff = matched(expected, rows.slice(row_start, row_end))
162
180
 
163
181
  return if matched
164
182
 
@@ -166,6 +184,7 @@ module TTYtest
166
184
  "screen did not match expected content:\n--- expected\n+++ actual\n#{diff.join("\n")}"
167
185
  end
168
186
  alias assert_matches_at assert_contents_at
187
+ alias assert_rows assert_contents_at
169
188
 
170
189
  METHODS = public_instance_methods
171
190
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TTYtest
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
data/notes.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  to push new version to github
2
- git tag v1.0.0
2
+ git tag v1.0.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-1.0.0.gem
7
+ gem push ttytest2-1.0.1.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: 1.0.0
4
+ version: 1.0.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: 2025-02-28 00:00:00.000000000 Z
11
+ date: 2025-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler