test_bench-output 2.0.0.0 → 2.0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb58227223c8abb68522bff5b4af2946eb2fb6c47e6f6fbc133ee1da18b8fa9d
4
- data.tar.gz: 465d3286eae938f746daa2aa27563a0228ae75072698cae85bf34e44b5cb0470
3
+ metadata.gz: 44124298b8ecfb9056b6123c05e2a87faf4e18b23edf4a4814d6b5ff70ec84b4
4
+ data.tar.gz: 62594161f48edaec2d591237d41b1e44536ef4c463fb9f08e0b7fec128009022
5
5
  SHA512:
6
- metadata.gz: 8cbb111e63fb42e142442c64de35668ceb32b14478ccc7016543be1dab5ce0060b236e6df7c7df2946311aa7eb78d423899eedc269f0fe8f20e8335e3472e129
7
- data.tar.gz: 5c99c2ce3f0c926b92b631b99664ff41a7271ee5b78e6a5c685e1644bb94737ca86dfa77496042ea2f7c597f57a54c1f66a29a4dc2d6c09c99293ec639681a7d
6
+ metadata.gz: 8947d95122a55c810d05c11508a0fe41a44d5ed0b40374b44600a23f560be08b937e2e6e1b70531f79553add57e37ea1e095d8f2c474ae2c0e62829119d300a3
7
+ data.tar.gz: a2130f9e78e9dc958173c9b19695ddad02311bd43fae3a4a92d1e5bd53e38013c15aaba97d6505fde0b59c9c820e851561b4727ac7fb8e66d2aded13ee2c0057
@@ -1,13 +1,16 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  module Controls
4
4
  module Data
5
- def self.example(suffix=nil)
6
- suffix = "-#{suffix}" if not suffix.nil?
5
+ def self.example
6
+ "some-data"
7
+ end
8
+
9
+ def self.random
10
+ suffix = Random.string
7
11
 
8
- "some-data#{suffix}"
12
+ "#{example}-#{suffix}"
9
13
  end
10
- def self.random = example(Random.string)
11
14
 
12
15
  module Digest
13
16
  def self.example
@@ -24,7 +27,9 @@ module TestBench
24
27
  '0123456789:;<=>'
25
28
  end
26
29
 
27
- def self.digest = Digest.digest
30
+ def self.digest
31
+ Digest.digest
32
+ end
28
33
  end
29
34
 
30
35
  module DifferentLength
@@ -32,7 +37,9 @@ module TestBench
32
37
  [Digest.digest].pack('Q>')
33
38
  end
34
39
 
35
- def self.digest = Digest.digest
40
+ def self.digest
41
+ Digest.digest
42
+ end
36
43
  end
37
44
  end
38
45
  end
@@ -1,5 +1,5 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  module Controls
4
4
  module Device
5
5
  def self.example
@@ -0,0 +1,7 @@
1
+ module TestBench
2
+ module Output
3
+ module Controls
4
+ Event = Telemetry::Controls::Event
5
+ end
6
+ end
7
+ end
@@ -1,42 +1,31 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  module Controls
4
4
  module Output
5
- def self.example(details: nil, styling: nil, mode: nil)
6
- styling ||= false
5
+ def self.example_class(&block)
6
+ Class.new do
7
+ include TestBench::Output
7
8
 
8
- output = TestBench::Output.new
9
-
10
- if details == true
11
- output.detail_policy = TestBench::Output::Detail.on
12
- elsif details == false
13
- output.detail_policy = TestBench::Output::Detail.off
14
- else
15
- output.detail_policy = TestBench::Output::Detail.failure
16
- end
17
-
18
- if styling
19
- output.writer.styling!
20
- end
21
-
22
- if not mode.nil?
23
- output.mode = mode
9
+ class_exec(&block)
24
10
  end
25
-
26
- output
27
11
  end
28
12
 
29
- module Styling
30
- def self.example
31
- Output.example(styling: true)
32
- end
13
+ class Example
14
+ include TestBench::Output
33
15
  end
34
16
 
35
- module Pending
36
- def self.example
37
- output = Styling.example
38
- output.pending_writer.buffer.limit = nil
39
- output
17
+ module Configure
18
+ class Example
19
+ include TestBench::Output
20
+ attr_accessor :some_attr
21
+
22
+ def configure(some_attr: nil, **arguments)
23
+ self.some_attr = some_attr
24
+ end
25
+
26
+ def configured?(some_attr)
27
+ self.some_attr == some_attr
28
+ end
40
29
  end
41
30
  end
42
31
  end
@@ -1,7 +1,7 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  module Controls
4
- Random = Session::Controls::Random
4
+ Random = Telemetry::Controls::Random
5
5
  end
6
6
  end
7
7
  end
@@ -1,5 +1,5 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  module Controls
4
4
  module Style
5
5
  def self.example
@@ -1,9 +1,14 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  module Controls
4
4
  module Styling
5
- def self.example = Writer::Styling.on
6
- def self.other_example = Writer::Styling.off
5
+ def self.example
6
+ Writer::Styling.on
7
+ end
8
+
9
+ def self.other_example
10
+ Writer::Styling.off
11
+ end
7
12
 
8
13
  def self.random
9
14
  stylings = [
@@ -1,14 +1,16 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  module Controls
4
4
  module Text
5
- def self.example(suffix=nil)
6
- suffix = " #{suffix}" if not suffix.nil?
7
-
8
- "Some text#{suffix}"
5
+ def self.example
6
+ "Some text"
9
7
  end
10
8
 
11
- def self.random = example(Random.string)
9
+ def self.random
10
+ suffix = Random.string
11
+
12
+ "#{example} #{suffix}"
13
+ end
12
14
 
13
15
  module NonPrintableCharacters
14
16
  def self.example
@@ -1,4 +1,4 @@
1
- require 'test_bench/session/controls'
1
+ require 'test_bench/telemetry/controls'
2
2
 
3
3
  require 'test_bench/output/controls/random'
4
4
  require 'test_bench/output/controls/data'
@@ -6,7 +6,5 @@ require 'test_bench/output/controls/device'
6
6
  require 'test_bench/output/controls/text'
7
7
  require 'test_bench/output/controls/styling'
8
8
  require 'test_bench/output/controls/style'
9
- require 'test_bench/output/controls/result'
10
- require 'test_bench/output/controls/detail'
11
- require 'test_bench/output/controls/events'
12
9
  require 'test_bench/output/controls/output'
10
+ require 'test_bench/output/controls/event'
@@ -1,5 +1,5 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  module Device
4
4
  class Null
5
5
  def self.build
@@ -1,5 +1,5 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  module Device
4
4
  module Substitute
5
5
  def self.build
@@ -17,11 +17,8 @@ module TestBench
17
17
  end
18
18
  attr_writer :flushed_data
19
19
 
20
- def tty
21
- @tty ||= false
22
- end
23
- alias :tty? :tty
24
- attr_writer :tty
20
+ attr_accessor :tty
21
+ def tty? = !!tty
25
22
 
26
23
  def write(data)
27
24
  bytes_written = data.bytesize
@@ -1,5 +1,5 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  class Digest
4
4
  def last_digest
5
5
  @last_digest ||= 0
@@ -1,334 +1,65 @@
1
1
  module TestBench
2
- class Output
3
- include Session::Handler
2
+ module Output
3
+ def self.included(cls)
4
+ cls.class_exec do
5
+ include Telemetry::Sink::Handler
4
6
 
5
- def pending_writer
6
- @pending_writer ||= Writer::Substitute.build
7
- end
8
- attr_writer :pending_writer
9
-
10
- def passing_writer
11
- @passing_writer ||= Writer::Substitute.build
12
- end
13
- attr_writer :passing_writer
14
-
15
- def failing_writer
16
- @failing_writer ||= Writer::Substitute.build
17
- end
18
- attr_writer :failing_writer
19
-
20
- def failures
21
- @failures ||= []
22
- end
23
- attr_writer :failures
24
-
25
- def mode
26
- @mode ||= Mode.initial
27
- end
28
- attr_writer :mode
29
-
30
- def failures
31
- @failures ||= []
32
- end
33
- attr_writer :failures
34
-
35
- def branch_count
36
- @branch_count ||= 0
37
- end
38
- attr_writer :branch_count
39
-
40
- def detail_policy
41
- @detail_policy ||= Detail.default
42
- end
43
- alias :detail :detail_policy
44
- attr_writer :detail_policy
45
-
46
- def self.build(device: nil, styling: nil, detail: nil)
47
- instance = new
48
-
49
- Writer.configure(instance, device:, styling:, attr_name: :pending_writer)
50
-
51
- if not detail.nil?
52
- instance.detail_policy = detail
7
+ extend Build
8
+ extend RegisterTelemetry
9
+ extend Configure
53
10
  end
54
-
55
- instance
56
11
  end
57
12
 
58
- def self.register(telemetry, **arguments)
59
- instance = build(**arguments)
60
-
61
- telemetry.register(instance)
62
- instance
13
+ def writer
14
+ @writer ||= Writer::Substitute.build
63
15
  end
16
+ attr_writer :writer
64
17
 
65
- def receive(event)
66
- case event
67
- when ContextStarted, TestStarted
68
- branch
69
- end
70
-
71
- if initial?
72
- handle(event)
73
-
74
- else
75
- self.mode = Mode.failing
76
- handle(event)
77
-
78
- self.mode = Mode.passing
79
- handle(event)
80
-
81
- self.mode = Mode.pending
82
- handle(event)
83
- end
84
-
85
- case event
86
- when ContextFinished, TestFinished
87
- merge(event.result)
88
- end
18
+ def configure(writer: nil, device: nil, styling: nil)
19
+ Writer.configure(self, writer:, device:, styling:)
89
20
  end
90
21
 
91
- handle Detailed do |text, quote, heading|
92
- if not detail?
93
- return
22
+ module Build
23
+ def build(writer: nil, device: nil, styling: nil, **arguments)
24
+ instance = new
25
+ instance.configure(writer:, device:, styling:, **arguments)
26
+ instance
94
27
  end
95
-
96
- comment(text, quote, heading)
97
- end
98
-
99
- handle Commented do |text, quote, heading|
100
- comment(text, quote, heading)
101
28
  end
102
29
 
103
- handle ContextStarted do |title|
104
- if not title.nil?
105
- writer.
106
- indent.
107
- style(:green).
108
- puts(title)
109
-
110
- writer.indent!
111
-
112
- if branch_count == 1
113
- failures.clear
114
- end
115
- end
116
- end
117
-
118
- handle ContextFinished do |title|
119
- if not title.nil?
120
- writer.deindent!
121
-
122
- if branch_count == 1
123
- writer.puts
124
-
125
- if failing? && failures.any?
126
- writer.
127
- style(:bold, :red).
128
- puts("Failure#{'s' if not failures.one?}:")
129
-
130
- failures.each do |failure_message|
131
- writer.
132
- print('- ').
133
- style(:red).
134
- puts(failure_message)
135
- end
136
-
137
- writer.puts
138
- end
139
- end
30
+ module RegisterTelemetry
31
+ def register_telemetry(telemetry, **arguments)
32
+ instance = build(**arguments)
33
+ telemetry.register(instance)
34
+ instance
140
35
  end
36
+ alias :register :register_telemetry
141
37
  end
142
38
 
143
- handle TestStarted do |title|
144
- if title.nil?
145
- if passing?
146
- return
147
- else
148
- title = 'Test'
149
- end
150
- end
151
-
152
- writer.indent
39
+ module Configure
40
+ def configure(receiver, attr_name: nil, **arguments)
41
+ attr_name ||= :output
153
42
 
154
- if passing?
155
- writer.style(:green)
156
- elsif failing?
157
- if not writer.styling?
158
- title = "#{title} (failed)"
159
- end
160
-
161
- writer.style(:bold, :red)
162
- elsif pending?
163
- writer.style(:faint)
43
+ instance = build(**arguments)
44
+ receiver.public_send(:"#{attr_name}=", instance)
164
45
  end
165
-
166
- writer.puts(title)
167
-
168
- writer.indent!
169
46
  end
170
47
 
171
- handle TestFinished do |title, result|
172
- if passing? && title.nil?
173
- return
48
+ module Substitute
49
+ def self.build
50
+ Output.new
174
51
  end
175
52
 
176
- writer.deindent!
177
- end
178
-
179
- handle Failed do |message|
180
- if failing?
181
- failures << message
182
- end
183
-
184
- writer
185
- .indent
186
- .style(:red)
187
- .puts(message)
188
- end
189
-
190
- def comment(text, quote, heading)
191
- if not heading.nil?
192
- writer.style(:bold, :underline).puts(heading)
193
- end
194
-
195
- if text.empty?
196
- writer.
197
- indent.
198
- style(:faint, :italic).
199
- puts('(empty)')
200
- return
201
- end
202
-
203
- if not quote
204
- writer.puts(text)
205
- else
206
- text.each_line do |line|
207
- line.chomp!
208
-
209
- writer.
210
- indent.
211
- style(:faint).
212
- print('> ').
213
- style(:reset_intensity).
214
- puts(line)
215
- end
216
- end
217
- end
218
-
219
- def current_writer
220
- if initial? || pending?
221
- pending_writer
222
- elsif passing?
223
- passing_writer
224
- elsif failing?
225
- failing_writer
226
- end
227
- end
228
- alias :writer :current_writer
229
-
230
- def branch
231
- if branch_count.zero?
232
- self.mode = Mode.pending
233
-
234
- pending_writer.sync = false
235
-
236
- parent_writer = pending_writer
237
- else
238
- parent_writer = passing_writer
239
- end
240
-
241
- self.branch_count += 1
242
-
243
- self.passing_writer, self.failing_writer = parent_writer.branch
244
- end
245
-
246
- def merge(result)
247
- self.branch_count -= 1
248
-
249
- if not branched?
250
- pending_writer.sync = true
251
-
252
- self.mode = Mode.initial
253
- end
254
-
255
- if result
256
- writer = passing_writer
257
- else
258
- writer = failing_writer
259
- end
260
-
261
- writer.flush
262
-
263
- self.passing_writer = writer.device
264
- self.failing_writer = writer.alternate_device
265
- end
266
-
267
- def branched?
268
- branch_count > 0
269
- end
270
-
271
- def initial?
272
- mode == Mode.initial
273
- end
274
-
275
- def pending?
276
- mode == Mode.pending
277
- end
278
-
279
- def passing?
280
- mode == Mode.passing
281
- end
282
-
283
- def failing?
284
- mode == Mode.failing
285
- end
286
-
287
- def detail?
288
- Detail.detail?(detail_policy, mode)
289
- end
290
-
291
- module Mode
292
- def self.initial = :initial
293
- def self.pending = :pending
294
- def self.passing = :passing
295
- def self.failing = :failing
296
- end
297
-
298
- module Detail
299
- Error = Class.new(RuntimeError)
300
-
301
- def self.detail?(policy, mode)
302
- case policy
303
- when on
304
- true
305
- when off
306
- false
307
- when failure
308
- if mode == Mode.failing || mode == Mode.initial
309
- true
53
+ class Output < Telemetry::Substitute::Sink
54
+ def handle(event_or_event_data)
55
+ if event_or_event_data.is_a?(Telemetry::Event)
56
+ event_data = Telemetry::Event::Export.(event_or_event_data)
310
57
  else
311
- false
58
+ event_data = event_or_event_data
312
59
  end
313
- else
314
- raise Error, "Unknown detail policy #{policy.inspect}"
315
- end
316
- end
317
-
318
- def self.on = :on
319
- def self.off = :off
320
- def self.failure = :failure
321
60
 
322
- def self.default
323
- policy = ENV.fetch('TEST_BENCH_DETAIL') do
324
- return default!
61
+ receive(event_data)
325
62
  end
326
-
327
- policy.to_sym
328
- end
329
-
330
- def self.default!
331
- :failure
332
63
  end
333
64
  end
334
65
  end
@@ -1,5 +1,5 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  class Writer
4
4
  class Buffer
5
5
  attr_accessor :limit
@@ -9,6 +9,19 @@ module TestBench
9
9
  end
10
10
  attr_writer :contents
11
11
 
12
+ def self.build
13
+ instance = new
14
+ instance.limit = 0
15
+ instance
16
+ end
17
+
18
+ def self.configure(receiver, attr_name: nil)
19
+ attr_name ||= :buffer
20
+
21
+ instance = build
22
+ receiver.public_send(:"#{attr_name}=", instance)
23
+ end
24
+
12
25
  def receive(data)
13
26
  bytes = data.bytesize
14
27
 
@@ -31,15 +44,11 @@ module TestBench
31
44
  !limit.nil?
32
45
  end
33
46
 
34
- def flush(device=nil, alternate_device=nil)
35
- if not device.nil?
47
+ def flush(*devices)
48
+ devices.each do |device|
36
49
  device.write(contents)
37
50
  end
38
51
 
39
- if not alternate_device.nil?
40
- alternate_device.write(contents)
41
- end
42
-
43
52
  contents.clear
44
53
  end
45
54
  end
@@ -1,5 +1,5 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  class Writer
4
4
  module Defaults
5
5
  def self.device
@@ -1,5 +1,5 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  class Writer
4
4
  module Style
5
5
  Error = Class.new(RuntimeError)
@@ -1,26 +1,36 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  class Writer
4
4
  module Substitute
5
5
  def self.build
6
6
  Writer.build
7
7
  end
8
8
 
9
- class Writer < Writer
10
- def written_data
11
- device.written_data
9
+ def self.included(cls)
10
+ cls.class_exec do
11
+ extend Build
12
12
  end
13
- alias :written_text :written_data
13
+ end
14
14
 
15
- def self.build
15
+ def written_data
16
+ device.written_data
17
+ end
18
+ alias :written_text :written_data
19
+
20
+ def styling!
21
+ self.styling_policy = Styling.on
22
+ end
23
+
24
+ module Build
25
+ def build
16
26
  instance = new
17
27
  instance.buffer.limit = 0
18
28
  instance
19
29
  end
30
+ end
20
31
 
21
- def styling!
22
- self.styling_policy = Styling.on
23
- end
32
+ class Writer < Writer
33
+ include Substitute
24
34
  end
25
35
  end
26
36
  end
@@ -1,18 +1,11 @@
1
1
  module TestBench
2
- class Output
2
+ module Output
3
3
  class Writer
4
- attr_accessor :peer
5
-
6
4
  def device
7
5
  @device ||= Device::Substitute.build
8
6
  end
9
7
  attr_writer :device
10
8
 
11
- def alternate_device
12
- @alternate_device ||= Device::Substitute.build
13
- end
14
- attr_writer :alternate_device
15
-
16
9
  def styling_policy
17
10
  @styling_policy ||= Styling.default
18
11
  end
@@ -34,41 +27,34 @@ module TestBench
34
27
  end
35
28
  attr_writer :column_sequence
36
29
 
37
- def indentation_depth
38
- @indentation_depth ||= 0
39
- end
40
- attr_writer :indentation_depth
41
-
42
30
  def buffer
43
31
  @buffer ||= Buffer.new
44
32
  end
45
33
  attr_writer :buffer
46
34
 
35
+ def configure
36
+ Buffer.configure(self)
37
+ end
38
+
47
39
  def self.build(device=nil, styling: nil)
48
40
  device ||= Defaults.device
49
41
 
50
42
  instance = new
51
-
52
43
  instance.device = device
53
- instance.alternate_device = Device::Null.build
54
-
55
- if device.tty?
56
- Buffer::Console.configure(instance, device:)
57
- else
58
- instance.buffer.limit = 0
59
- end
60
-
61
- if not styling.nil?
62
- instance.styling_policy = styling
63
- end
64
-
44
+ instance.styling_policy = styling
45
+ instance.configure
65
46
  instance
66
47
  end
67
48
 
68
- def self.configure(receiver, styling: nil, device: nil, attr_name: nil)
49
+ def self.configure(receiver, writer: nil, styling: nil, device: nil, attr_name: nil)
69
50
  attr_name ||= :writer
70
51
 
71
- instance = build(device, styling: styling)
52
+ if not writer.nil?
53
+ instance = writer
54
+ else
55
+ instance = build(device, styling:)
56
+ end
57
+
72
58
  receiver.public_send(:"#{attr_name}=", instance)
73
59
  end
74
60
 
@@ -76,43 +62,10 @@ module TestBench
76
62
  @sync.nil? ? @sync = true : @sync
77
63
  end
78
64
 
79
- def self.follow(previous_writer)
80
- device = previous_writer
81
-
82
- alternate_device = previous_writer.peer
83
- alternate_device ||= Device::Null.build
84
-
85
- previous_digest = previous_writer.digest
86
- digest = previous_digest.clone
87
-
88
- writer = new
89
- writer.sync = false
90
- writer.device = device
91
- writer.alternate_device = alternate_device
92
- writer.styling_policy = previous_writer.styling_policy
93
- writer.digest = digest
94
- writer.sequence = previous_writer.sequence
95
- writer.column_sequence = previous_writer.column_sequence
96
- writer.indentation_depth = previous_writer.indentation_depth
97
- writer.digest = previous_writer.digest.clone
98
- writer
99
- end
100
-
101
- def branch
102
- alternate = self.class.follow(self)
103
- primary = self.class.follow(self)
104
-
105
- primary.peer = alternate
106
-
107
- return primary, alternate
108
- end
109
-
110
65
  def puts(text=nil)
111
- if column_sequence.zero?
112
- indent
113
- end
114
-
115
66
  if not text.nil?
67
+ text = text.chomp
68
+
116
69
  print(text)
117
70
  end
118
71
 
@@ -141,12 +94,6 @@ module TestBench
141
94
  self
142
95
  end
143
96
 
144
- def indent
145
- indentation = ' ' * indentation_depth
146
-
147
- print(indentation)
148
- end
149
-
150
97
  def print(text)
151
98
  text = text.dump[1...-1]
152
99
 
@@ -159,10 +106,7 @@ module TestBench
159
106
 
160
107
  def write(data)
161
108
  if sync
162
- device.write(data)
163
- alternate_device.write(data)
164
-
165
- bytes_written = data.bytesize
109
+ bytes_written = write!(data)
166
110
  else
167
111
  bytes_written = buffer.receive(data)
168
112
  end
@@ -175,12 +119,18 @@ module TestBench
175
119
  bytes_written
176
120
  end
177
121
 
122
+ def write!(data)
123
+ device.write(data)
124
+
125
+ data.bytesize
126
+ end
127
+
178
128
  def tty?
179
129
  device.tty?
180
130
  end
181
131
 
182
132
  def flush
183
- buffer.flush(device, alternate_device)
133
+ buffer.flush(device)
184
134
  end
185
135
 
186
136
  def sync=(sync)
@@ -203,28 +153,6 @@ module TestBench
203
153
  sequence >= self.sequence
204
154
  end
205
155
 
206
- def increase_indentation
207
- self.indentation_depth += 1
208
- end
209
- alias :indent! :increase_indentation
210
-
211
- def decrease_indentation
212
- self.indentation_depth -= 1
213
- end
214
- alias :deindent! :decrease_indentation
215
-
216
- def follows?(other_writer)
217
- if sequence < other_writer.sequence
218
- false
219
- elsif device == other_writer
220
- true
221
- elsif device == other_writer.peer
222
- true
223
- else
224
- false
225
- end
226
- end
227
-
228
156
  def styling?
229
157
  Styling.styling?(styling_policy, device.tty?)
230
158
  end
@@ -233,6 +161,12 @@ module TestBench
233
161
  Error = Class.new(RuntimeError)
234
162
 
235
163
  def self.styling?(policy, console)
164
+ assure_styling(policy, console)
165
+ end
166
+
167
+ def self.assure_styling(policy, console=nil)
168
+ console ||= false
169
+
236
170
  case policy
237
171
  when on
238
172
  true
@@ -1,6 +1,6 @@
1
1
  require 'io/console'
2
2
 
3
- require 'test_bench/session'
3
+ require 'test_bench/telemetry'
4
4
 
5
5
  require 'test_bench/output/digest'
6
6
 
@@ -8,10 +8,9 @@ require 'test_bench/output/device/null'
8
8
  require 'test_bench/output/device/substitute'
9
9
 
10
10
  require 'test_bench/output/writer/buffer'
11
- require 'test_bench/output/writer/buffer/console'
12
- require 'test_bench/output/writer/defaults'
13
11
  require 'test_bench/output/writer'
14
12
  require 'test_bench/output/writer/style'
15
13
  require 'test_bench/output/writer/substitute'
14
+ require 'test_bench/output/writer/defaults'
16
15
 
17
16
  require 'test_bench/output/output'
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_bench-output
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.0
4
+ version: 2.0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Ladd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-27 00:00:00.000000000 Z
11
+ date: 2023-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: test_bench-session
14
+ name: test_bench-telemetry
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: test_bench-bootstrap
28
+ name: test_bench-isolated
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -47,12 +47,10 @@ files:
47
47
  - lib/test_bench/output.rb
48
48
  - lib/test_bench/output/controls.rb
49
49
  - lib/test_bench/output/controls/data.rb
50
- - lib/test_bench/output/controls/detail.rb
51
50
  - lib/test_bench/output/controls/device.rb
52
- - lib/test_bench/output/controls/events.rb
51
+ - lib/test_bench/output/controls/event.rb
53
52
  - lib/test_bench/output/controls/output.rb
54
53
  - lib/test_bench/output/controls/random.rb
55
- - lib/test_bench/output/controls/result.rb
56
54
  - lib/test_bench/output/controls/style.rb
57
55
  - lib/test_bench/output/controls/styling.rb
58
56
  - lib/test_bench/output/controls/text.rb
@@ -62,7 +60,6 @@ files:
62
60
  - lib/test_bench/output/output.rb
63
61
  - lib/test_bench/output/writer.rb
64
62
  - lib/test_bench/output/writer/buffer.rb
65
- - lib/test_bench/output/writer/buffer/console.rb
66
63
  - lib/test_bench/output/writer/defaults.rb
67
64
  - lib/test_bench/output/writer/style.rb
68
65
  - lib/test_bench/output/writer/substitute.rb
@@ -85,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
82
  - !ruby/object:Gem::Version
86
83
  version: '0'
87
84
  requirements: []
88
- rubygems_version: 3.3.23
85
+ rubygems_version: 3.4.10
89
86
  signing_key:
90
87
  specification_version: 4
91
88
  summary: ruby
@@ -1,22 +0,0 @@
1
- module TestBench
2
- class Output
3
- module Controls
4
- module Detail
5
- def self.example = TestBench::Output::Detail.on
6
- def self.other_example = TestBench::Output::Detail.off
7
-
8
- def self.random
9
- details = [
10
- TestBench::Output::Detail.on,
11
- TestBench::Output::Detail.off,
12
- TestBench::Output::Detail.failure
13
- ]
14
-
15
- index = Random.integer % details.count
16
-
17
- details[index]
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,7 +0,0 @@
1
- module TestBench
2
- class Output
3
- module Controls
4
- Events = Session::Controls::Events
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module TestBench
2
- class Output
3
- module Controls
4
- Result = Session::Controls::Result
5
- end
6
- end
7
- end
@@ -1,184 +0,0 @@
1
- module TestBench
2
- class Output
3
- class Writer
4
- class Buffer
5
- class Console
6
- def device
7
- @device ||= Device::Null.build
8
- end
9
- attr_writer :device
10
-
11
- def geometry
12
- @geometry ||= Geometry.get
13
- end
14
- attr_writer :geometry
15
-
16
- def cursor_saved
17
- @cursor_saved ||= false
18
- end
19
- alias :cursor_saved? :cursor_saved
20
- attr_writer :cursor_saved
21
-
22
- def self.build(device=nil)
23
- device ||= Defaults.device
24
-
25
- instance = new
26
-
27
- if device.tty?
28
- instance.device = device
29
- end
30
-
31
- instance
32
- end
33
-
34
- def self.configure(receiver, device: nil, attr_name: nil)
35
- attr_name ||= :buffer
36
-
37
- instance = build(device)
38
- receiver.public_send(:"#{attr_name}=", instance)
39
- end
40
-
41
- def set_geometry(width, height, row, column)
42
- geometry = Geometry.new(width, height, row, column)
43
- self.geometry = geometry
44
- end
45
-
46
- def receive(text)
47
- if not cursor_saved?
48
- device.write("\e[s")
49
- self.cursor_saved = true
50
- end
51
-
52
- write_ahead_text = geometry.next(text)
53
-
54
- if not write_ahead_text.empty?
55
- device.write(write_ahead_text)
56
- elsif geometry.bottom_row?
57
- buffering_message = "Output is buffering"
58
-
59
- device.write("\e[2m#{buffering_message}\e[22m")
60
- geometry.next!(buffering_message)
61
- end
62
-
63
- device.flush
64
-
65
- write_ahead_text.length
66
- end
67
-
68
- def flush(...)
69
- if cursor_saved?
70
- device.write("\e[u")
71
- self.cursor_saved = false
72
- end
73
- end
74
-
75
- def capacity
76
- geometry.capacity
77
- end
78
-
79
- def next_position(text)
80
- geometry.next_position(text)
81
- end
82
-
83
- Geometry = Struct.new(:width, :height, :row, :column) do
84
- def self.get
85
- instance = new
86
-
87
- STDIN.raw do |stdin|
88
- instance.height, instance.width = stdin.winsize
89
-
90
- instance.row, instance.column = stdin.cursor
91
- end
92
-
93
- instance
94
- end
95
-
96
- def bottom_row?
97
- row + 1 == height && column == 0
98
- end
99
-
100
- def next(text)
101
- write_ahead_text = text.slice!(0, capacity)
102
-
103
- next!(write_ahead_text)
104
-
105
- write_ahead_text
106
- end
107
-
108
- def next!(text)
109
- escape_sequence_pattern = %r{\A\e\[[[:digit:]]+(?:;[[:digit:]]+)*[[:alpha:]]$}
110
- if escape_sequence_pattern.match?(text)
111
- return
112
- end
113
-
114
- row, column, _scroll_rows = next_position(text)
115
-
116
- self.row = row
117
- self.column = column
118
- end
119
-
120
- def capacity
121
- capacity = 0
122
-
123
- rows_remaining = height - row - 1
124
-
125
- if rows_remaining > 0
126
- capacity += (rows_remaining - 1) * width
127
-
128
- final_row = width - column
129
- capacity += final_row
130
- end
131
-
132
- capacity
133
- end
134
-
135
- def next_position(text)
136
- text_length = text.length
137
-
138
- newline = text.end_with?("\n")
139
- if newline
140
- text_length -= 1
141
- end
142
-
143
- row = self.row
144
- column = self.column
145
-
146
- text_rows, text_columns = text_length.divmod(width)
147
-
148
- row += text_rows
149
-
150
- columns_remaining = width - column
151
- if columns_remaining > text_columns
152
- column += text_columns
153
- else
154
- row += 1
155
- column = text_columns - columns_remaining
156
- end
157
-
158
- if newline
159
- reached_next_line = column == 0 && row > self.row
160
-
161
- newline_needed = !reached_next_line
162
- if newline_needed
163
- row += 1
164
- column = 0
165
- end
166
- end
167
-
168
- if row >= height
169
- row_limit = height - 1
170
-
171
- scroll_rows = row - row_limit
172
- row = row_limit
173
- else
174
- scroll_rows = 0
175
- end
176
-
177
- return row, column, scroll_rows
178
- end
179
- end
180
- end
181
- end
182
- end
183
- end
184
- end