expect-pty 0.3.1 → 0.3.2
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/.rubocop.yml +32 -3
- data/CHANGELOG.md +6 -0
- data/CONTRIBUTING.md +21 -0
- data/Gemfile +2 -1
- data/README.md +15 -4
- data/benchmark/matching.rb +72 -0
- data/benchmark/relay.rb +48 -0
- data/benchmark/send_slow.rb +41 -0
- data/benchmark/support.rb +94 -0
- data/docs/INTERNAL_CONTRACTS.md +44 -0
- data/docs/PERFORMANCE.md +44 -0
- data/docs/RELEASING.md +6 -6
- data/docs/VERIFICATION.md +8 -0
- data/examples/kibitz/kibitz.rb +2 -0
- data/expect-pty.gemspec +2 -1
- data/lib/expect/interaction.rb +10 -3
- data/lib/expect/matcher.rb +15 -3
- data/lib/expect/pattern.rb +3 -3
- data/lib/expect/relay.rb +3 -1
- data/lib/expect/relay_writer.rb +2 -0
- data/lib/expect/session_resources.rb +28 -10
- data/lib/expect/version.rb +1 -1
- data/lib/expect.rb +50 -16
- data/script/ci +5 -0
- data/test/cleanup_test.rb +163 -0
- data/test/configuration_test.rb +43 -0
- data/test/io_test.rb +35 -0
- data/test/pattern_offset_test.rb +41 -0
- data/test/relay_recovery_test.rb +37 -0
- data/test/scan_reuse_test.rb +109 -0
- metadata +12 -2
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "test_helper"
|
|
4
|
+
|
|
5
|
+
class ScanReuseTest < ExpectTest
|
|
6
|
+
def test_each_scan_snapshots_a_session_once_across_non_adjacent_groups
|
|
7
|
+
first, = pipe_session
|
|
8
|
+
second, = pipe_session
|
|
9
|
+
first.buffer = "ready"
|
|
10
|
+
list = Expect::PatternList.new
|
|
11
|
+
list.on("missing", from: first).on("other", from: second).on("ready", from: first)
|
|
12
|
+
matcher = Expect::Matcher.new(list, 0)
|
|
13
|
+
snapshots = 0
|
|
14
|
+
original = first.method(:buffer)
|
|
15
|
+
first.stub(:buffer, lambda {
|
|
16
|
+
snapshots += 1
|
|
17
|
+
original.call
|
|
18
|
+
}) do
|
|
19
|
+
2.times do
|
|
20
|
+
result = matcher.__send__(:find_match)
|
|
21
|
+
assert_same first, result[0]
|
|
22
|
+
assert_equal 3, result[1].number
|
|
23
|
+
assert_equal [0, 5, []], result[2]
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
assert_equal 2, snapshots
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_callback_replacement_and_nested_match_are_visible_on_the_next_scan
|
|
30
|
+
first, = pipe_session
|
|
31
|
+
second, = pipe_session
|
|
32
|
+
first.buffer = "start"
|
|
33
|
+
events = []
|
|
34
|
+
result = Expect.expect_result(timeout: 0) do
|
|
35
|
+
on("start", from: first) do |session|
|
|
36
|
+
events << session.match
|
|
37
|
+
session.buffer = "nested finish"
|
|
38
|
+
session.expect("nested ", timeout: 0)
|
|
39
|
+
events << session.match
|
|
40
|
+
session.continue
|
|
41
|
+
end
|
|
42
|
+
on("missing", from: second)
|
|
43
|
+
on("finish", from: first) { |session| events << session.match }
|
|
44
|
+
end
|
|
45
|
+
assert_equal 3, result.number
|
|
46
|
+
assert_equal ["start", "nested ", "finish"], events
|
|
47
|
+
assert_empty first.buffer
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_shared_io_keeps_first_session_and_identity_despite_equal_hashes
|
|
51
|
+
first, writer = pipe_session
|
|
52
|
+
second = Expect.open(first.to_io)
|
|
53
|
+
@sessions << second
|
|
54
|
+
other, other_writer = pipe_session
|
|
55
|
+
# IO 的业务相等性不能替代 IO.select 返回对象的身份。
|
|
56
|
+
[first.to_io, other.to_io].each do |io|
|
|
57
|
+
io.define_singleton_method(:hash) { 0 }
|
|
58
|
+
io.define_singleton_method(:eql?) { |_other| true }
|
|
59
|
+
end
|
|
60
|
+
writer.write("first")
|
|
61
|
+
other_writer.write("other")
|
|
62
|
+
result = Expect.expect_result(timeout: 0) do
|
|
63
|
+
on("missing", from: [first, second, other])
|
|
64
|
+
on("other", from: other)
|
|
65
|
+
end
|
|
66
|
+
assert_same other, result.session
|
|
67
|
+
assert_equal "first", first.buffer
|
|
68
|
+
assert_empty second.buffer
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_regexps_share_one_combined_text_and_literal_only_does_not_build_it
|
|
72
|
+
session, = pipe_session
|
|
73
|
+
session.listeners = [StringIO.new]
|
|
74
|
+
[0, 4].each do |count|
|
|
75
|
+
session.__send__(:sequences=, {})
|
|
76
|
+
count.times { |index| session.on_sequence(/missing#{index}/) }
|
|
77
|
+
session.on_sequence("STOP")
|
|
78
|
+
history = session.__send__(:relay_history)
|
|
79
|
+
concatenations = 0
|
|
80
|
+
original = history.method(:+)
|
|
81
|
+
history.define_singleton_method(:+) do |other|
|
|
82
|
+
concatenations += 1
|
|
83
|
+
original.call(other)
|
|
84
|
+
end
|
|
85
|
+
assert Expect.__send__(:relay_buffer, session, { session => "payload".b })
|
|
86
|
+
assert_equal count.zero? ? 0 : 1, concatenations
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_escape_callback_can_change_rules_before_rescanning
|
|
91
|
+
session, = pipe_session
|
|
92
|
+
output = StringIO.new
|
|
93
|
+
session.listeners = [output]
|
|
94
|
+
events = []
|
|
95
|
+
session.on_sequence(/ONE/) do
|
|
96
|
+
events << :one
|
|
97
|
+
session.on_sequence(/TWO/) do
|
|
98
|
+
events << :two
|
|
99
|
+
false
|
|
100
|
+
end
|
|
101
|
+
true
|
|
102
|
+
end
|
|
103
|
+
buffers = { session => "aONEbTWOtail".b }
|
|
104
|
+
refute Expect.__send__(:relay_buffer, session, buffers)
|
|
105
|
+
assert_equal %i[one two], events
|
|
106
|
+
assert_equal "ab", output.string
|
|
107
|
+
assert_equal "tail", buffers.fetch(session)
|
|
108
|
+
end
|
|
109
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: expect-pty
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- expect-pty contributors
|
|
@@ -105,11 +105,18 @@ extra_rdoc_files: []
|
|
|
105
105
|
files:
|
|
106
106
|
- ".rubocop.yml"
|
|
107
107
|
- CHANGELOG.md
|
|
108
|
+
- CONTRIBUTING.md
|
|
108
109
|
- Gemfile
|
|
109
110
|
- LICENSE
|
|
110
111
|
- README.md
|
|
111
112
|
- Rakefile
|
|
113
|
+
- benchmark/matching.rb
|
|
114
|
+
- benchmark/relay.rb
|
|
115
|
+
- benchmark/send_slow.rb
|
|
116
|
+
- benchmark/support.rb
|
|
112
117
|
- docs/COMPATIBILITY.md
|
|
118
|
+
- docs/INTERNAL_CONTRACTS.md
|
|
119
|
+
- docs/PERFORMANCE.md
|
|
113
120
|
- docs/RELEASING.md
|
|
114
121
|
- docs/VERIFICATION.md
|
|
115
122
|
- examples/dialogue.rb
|
|
@@ -134,6 +141,7 @@ files:
|
|
|
134
141
|
- lib/expect/version.rb
|
|
135
142
|
- script/ci
|
|
136
143
|
- script/release.rb
|
|
144
|
+
- test/cleanup_test.rb
|
|
137
145
|
- test/compare_upstream.rb
|
|
138
146
|
- test/configuration_test.rb
|
|
139
147
|
- test/edge_case_test.rb
|
|
@@ -150,10 +158,12 @@ files:
|
|
|
150
158
|
- test/kibitz_test.rb
|
|
151
159
|
- test/matching_test.rb
|
|
152
160
|
- test/multi_session_test.rb
|
|
161
|
+
- test/pattern_offset_test.rb
|
|
153
162
|
- test/process_test.rb
|
|
154
163
|
- test/relay_recovery_test.rb
|
|
155
164
|
- test/release_test.rb
|
|
156
165
|
- test/ruby_api_test.rb
|
|
166
|
+
- test/scan_reuse_test.rb
|
|
157
167
|
- test/script_logging_test.rb
|
|
158
168
|
- test/support/interact_probe.rb
|
|
159
169
|
- test/support/kibitz_probe.rb
|
|
@@ -182,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
182
192
|
- !ruby/object:Gem::Version
|
|
183
193
|
version: '0'
|
|
184
194
|
requirements: []
|
|
185
|
-
rubygems_version: 4.0.
|
|
195
|
+
rubygems_version: 4.0.16
|
|
186
196
|
specification_version: 4
|
|
187
197
|
summary: Ruby PTY automation with the Expect.pm interaction model
|
|
188
198
|
test_files: []
|