test_bench-output 2.1.1.3 → 3.0.0.0.pre.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/test_bench/output/comment_style.rb +61 -0
  3. data/lib/test_bench/output/controls/comment_style.rb +21 -0
  4. data/lib/test_bench/output/controls/event.rb +2 -2
  5. data/lib/test_bench/output/controls/events/aborted.rb +9 -0
  6. data/lib/test_bench/output/controls/events/commented.rb +21 -0
  7. data/lib/test_bench/output/controls/events/context_finished.rb +9 -0
  8. data/lib/test_bench/output/controls/events/context_started.rb +9 -0
  9. data/lib/test_bench/output/controls/events/detailed.rb +21 -0
  10. data/lib/test_bench/output/controls/events/failed.rb +9 -0
  11. data/lib/test_bench/output/controls/events/file_executed.rb +9 -0
  12. data/lib/test_bench/output/controls/events/file_not_found.rb +9 -0
  13. data/lib/test_bench/output/controls/events/file_queued.rb +9 -0
  14. data/lib/test_bench/output/controls/events/skipped.rb +9 -0
  15. data/lib/test_bench/output/controls/events/test_finished.rb +9 -0
  16. data/lib/test_bench/output/controls/events/test_started.rb +9 -0
  17. data/lib/test_bench/output/controls/random.rb +2 -2
  18. data/lib/test_bench/output/controls/session.rb +17 -0
  19. data/lib/test_bench/output/controls/status.rb +7 -0
  20. data/lib/test_bench/output/controls/style.rb +14 -6
  21. data/lib/test_bench/output/controls/text.rb +16 -4
  22. data/lib/test_bench/output/controls.rb +21 -5
  23. data/lib/test_bench/output/detail_policy.rb +44 -0
  24. data/lib/test_bench/output/device/null.rb +3 -3
  25. data/lib/test_bench/output/device/substitute.rb +19 -33
  26. data/lib/test_bench/output/device.rb +73 -0
  27. data/lib/test_bench/output/get.rb +30 -0
  28. data/lib/test_bench/output/level.rb +51 -0
  29. data/lib/test_bench/output/output.rb +540 -36
  30. data/lib/test_bench/output/writer/style.rb +3 -3
  31. data/lib/test_bench/output/writer/substitute.rb +10 -23
  32. data/lib/test_bench/output/writer.rb +54 -147
  33. data/lib/test_bench/output.rb +10 -4
  34. metadata +49 -21
  35. data/lib/test_bench/output/controls/data.rb +0 -49
  36. data/lib/test_bench/output/controls/device.rb +0 -27
  37. data/lib/test_bench/output/controls/output.rb +0 -34
  38. data/lib/test_bench/output/controls/styling.rb +0 -27
  39. data/lib/test_bench/output/digest.rb +0 -113
  40. data/lib/test_bench/output/writer/buffer.rb +0 -57
  41. data/lib/test_bench/output/writer/defaults.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c05d72c3b0b2b4aedeab99af778ac2109da308eadf3006a11537132a13e2f3b
4
- data.tar.gz: 6dd801c1d9d25ae6004bc86a6e1ffb09767d75573622754ab6a45b09d593389e
3
+ metadata.gz: 3e0f38c7295b1224d2d8e379baedbc63eca93df6072eb3c3aa57262fc199428a
4
+ data.tar.gz: f3b40e1d2d46219fbf937284bc24a48cc9f1572c65baf888db1f7ecbdeae9b77
5
5
  SHA512:
6
- metadata.gz: abf3ad29e5cd19c4a0a4083d456fabeb0f322a14e82940ad8f8bb47bb247ed2aa0eed912374bd69324f64562906a164fa2c9419f29b3bb6f397a5124ac13c7f7
7
- data.tar.gz: dc1e161175bb55ca0f82a666aa4556c4b5a3f0a6fa388db7e59dbd7afb79a2d87199ef1c4f6598f53485fa0edeb6753e8b0b5fe4116e431fa1765921604718b9
6
+ metadata.gz: 554435db7dfcfcd909037034b7781f9caecd142ccd655354be24ceb3d96b775303d0c149841a3b77f297bd0c56ffc39c554cb0012964174627a1cd3f113d97e2
7
+ data.tar.gz: 61e48708d47b1f7f32b27ecf3f1818ef3811e4b427f2766e1707b11618d751cf930a281639350f5143f0f460cc6fbbe18c99756cfd0469e0d47a64f872f3f4b8
@@ -0,0 +1,61 @@
1
+ module TestBench
2
+ class Output
3
+ module CommentStyle
4
+ Error = Class.new(RuntimeError)
5
+
6
+ def self.fetch(comment_disposition)
7
+ comment_style = get(comment_disposition)
8
+
9
+ comment_style ||= normal
10
+
11
+ comment_style
12
+ end
13
+
14
+ def self.get(comment_disposition)
15
+ comment_style, _ = comment_styles.rassoc(comment_disposition)
16
+ comment_style
17
+ end
18
+
19
+ def self.get_disposition(comment_style)
20
+ comment_styles.fetch(comment_style) do
21
+ raise Error, "Incorrect comment style: #{comment_style.inspect}"
22
+ end
23
+ end
24
+
25
+ def self.comment_styles
26
+ {
27
+ :detect => 'detect',
28
+ :normal => 'normal',
29
+ :heading => 'heading',
30
+ :block => 'block',
31
+ :line_number => 'line_number',
32
+ :raw => 'raw'
33
+ }
34
+ end
35
+
36
+ def self.detect
37
+ :detect
38
+ end
39
+
40
+ def self.normal
41
+ :normal
42
+ end
43
+
44
+ def self.heading
45
+ :heading
46
+ end
47
+
48
+ def self.block
49
+ :block
50
+ end
51
+
52
+ def self.line_number
53
+ :line_number
54
+ end
55
+
56
+ def self.raw
57
+ :raw
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,21 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ module CommentStyle
5
+ def self.example
6
+ :normal
7
+ end
8
+
9
+ def self.disposition
10
+ 'normal'
11
+ end
12
+
13
+ module Disposition
14
+ def self.example
15
+ Session::CommentDisposition.example
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,7 +1,7 @@
1
1
  module TestBench
2
- module Output
2
+ class Output
3
3
  module Controls
4
- Event = Telemetry::Controls::Event
4
+ Event = Session::Event
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,9 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ module Events
5
+ Aborted = Session::Events::Aborted
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ module Events
5
+ module Commented
6
+ def self.example(text: nil, style: nil)
7
+ style ||= self.style
8
+
9
+ disposition = Output::CommentStyle.get_disposition(style)
10
+
11
+ Session::Events::Commented.example(text:, disposition:)
12
+ end
13
+
14
+ def self.style
15
+ CommentStyle.example
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ module Events
5
+ ContextFinished = Session::Events::ContextFinished
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ module Events
5
+ ContextStarted = Session::Events::ContextStarted
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ module Events
5
+ module Detailed
6
+ def self.example(text: nil, style: nil)
7
+ style ||= self.style
8
+
9
+ disposition = Output::CommentStyle.get_disposition(style)
10
+
11
+ Session::Events::Detailed.example(text:, disposition:)
12
+ end
13
+
14
+ def self.style
15
+ CommentStyle.example
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ module Events
5
+ Failed = Session::Events::Failed
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ module Events
5
+ FileExecuted = Session::Events::FileExecuted
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ module Events
5
+ FileNotFound = Session::Events::FileNotFound
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ module Events
5
+ FileQueued = Session::Events::FileQueued
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ module Events
5
+ Skipped = Session::Events::Skipped
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ module Events
5
+ TestFinished = Session::Events::TestFinished
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ module Events
5
+ TestStarted = Session::Events::TestStarted
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,7 +1,7 @@
1
1
  module TestBench
2
- module Output
2
+ class Output
3
3
  module Controls
4
- Random = Telemetry::Controls::Random
4
+ Random = Session::Random
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,17 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ module Session
5
+ Events = TestBench::Session::Controls::Events
6
+
7
+ Event = TestBench::Session::Controls::Event
8
+
9
+ Status = TestBench::Session::Controls::Status
10
+
11
+ Random = TestBench::Session::Controls::Random
12
+
13
+ CommentDisposition = TestBench::Session::Controls::CommentDisposition
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module TestBench
2
+ class Output
3
+ module Controls
4
+ Status = Session::Status
5
+ end
6
+ end
7
+ end
@@ -1,28 +1,36 @@
1
1
  module TestBench
2
- module Output
2
+ class Output
3
3
  module Controls
4
4
  module Style
5
5
  def self.example
6
6
  :bold
7
7
  end
8
8
 
9
+ def self.code
10
+ '1'
11
+ end
12
+
9
13
  def self.other_example
10
- :italic
14
+ Other.example
11
15
  end
12
16
 
13
- module Unknown
17
+ module Other
14
18
  def self.example
15
- :unknown
19
+ :italic
20
+ end
21
+
22
+ def self.code
23
+ '3'
16
24
  end
17
25
  end
18
26
 
19
27
  module Code
20
28
  def self.example
21
- '1'
29
+ Style.code
22
30
  end
23
31
 
24
32
  def self.other_example
25
- '3'
33
+ Other.code
26
34
  end
27
35
  end
28
36
  end
@@ -1,15 +1,27 @@
1
1
  module TestBench
2
- module Output
2
+ class Output
3
3
  module Controls
4
4
  module Text
5
5
  def self.example
6
6
  "Some text"
7
7
  end
8
8
 
9
- def self.random
10
- suffix = Random.string
9
+ def self.other_example
10
+ "Some other text"
11
+ end
12
+
13
+ module NewlineTerminated
14
+ def self.example(lines: nil)
15
+ lines ||= 1
16
+
17
+ line_count = lines
18
+
19
+ lines = (1..line_count).map do |line_number|
20
+ "Line #{line_number}\n"
21
+ end
11
22
 
12
- "#{example} #{suffix}"
23
+ lines.join
24
+ end
13
25
  end
14
26
  end
15
27
  end
@@ -1,10 +1,26 @@
1
- require 'test_bench/telemetry/controls'
1
+ require 'test_bench/session/controls'
2
+
3
+ require 'test_bench/output/controls/session'
2
4
 
3
5
  require 'test_bench/output/controls/random'
4
- require 'test_bench/output/controls/data'
5
- require 'test_bench/output/controls/device'
6
+ require 'test_bench/output/controls/status'
6
7
  require 'test_bench/output/controls/text'
7
- require 'test_bench/output/controls/styling'
8
+
8
9
  require 'test_bench/output/controls/style'
9
- require 'test_bench/output/controls/output'
10
+
11
+ require 'test_bench/output/controls/comment_style'
12
+
13
+ require 'test_bench/output/controls/events/failed'
14
+ require 'test_bench/output/controls/events/aborted'
15
+ require 'test_bench/output/controls/events/skipped'
16
+ require 'test_bench/output/controls/events/commented'
17
+ require 'test_bench/output/controls/events/detailed'
18
+ require 'test_bench/output/controls/events/test_started'
19
+ require 'test_bench/output/controls/events/test_finished'
20
+ require 'test_bench/output/controls/events/context_started'
21
+ require 'test_bench/output/controls/events/context_finished'
22
+ require 'test_bench/output/controls/events/file_queued'
23
+ require 'test_bench/output/controls/events/file_executed'
24
+ require 'test_bench/output/controls/events/file_not_found'
25
+
10
26
  require 'test_bench/output/controls/event'
@@ -0,0 +1,44 @@
1
+ module TestBench
2
+ class Output
3
+ module DetailPolicy
4
+ Error = Class.new(RuntimeError)
5
+
6
+ def self.failure
7
+ :failure
8
+ end
9
+
10
+ def self.on
11
+ :on
12
+ end
13
+
14
+ def self.off
15
+ :off
16
+ end
17
+
18
+ def self.detail?(detail_policy, result=nil)
19
+ result ||= Session::Result.none
20
+
21
+ case detail_policy
22
+ when failure
23
+ [
24
+ Session::Result.failed,
25
+ Session::Result.aborted
26
+ ].include?(result)
27
+
28
+ when on
29
+ true
30
+
31
+ when off
32
+ false
33
+
34
+ else
35
+ raise Error, "Incorrect detail policy: #{detail_policy.inspect}"
36
+ end
37
+ end
38
+
39
+ def self.assure_policy(detail_policy)
40
+ detail?(detail_policy)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,8 +1,8 @@
1
1
  module TestBench
2
- module Output
3
- module Device
2
+ class Output
3
+ class Device
4
4
  class Null
5
- def self.build
5
+ def self.instance
6
6
  @instance ||= new
7
7
  end
8
8
 
@@ -1,56 +1,42 @@
1
1
  module TestBench
2
- module Output
3
- module Device
2
+ class Output
3
+ class Device
4
4
  module Substitute
5
5
  def self.build
6
6
  Device.new
7
7
  end
8
8
 
9
9
  class Device
10
- def written_data
11
- @written_data ||= String.new
10
+ def written_text
11
+ @written_text ||= String.new
12
12
  end
13
- attr_writer :written_data
14
-
15
- def flushed_data
16
- @flushed_data ||= String.new
17
- end
18
- attr_writer :flushed_data
13
+ attr_writer :written_text
19
14
 
20
15
  attr_accessor :tty
21
- def tty? = !!tty
22
-
23
- def write(data)
24
- bytes_written = data.bytesize
25
-
26
- written_data << data
27
16
 
28
- bytes_written
17
+ def tty?
18
+ tty ? true : false
29
19
  end
30
20
 
31
- def flush
32
- flushed_data << written_data
21
+ def set_tty
22
+ self.tty = true
33
23
  end
34
24
 
35
- def written?(data=nil)
36
- if data.nil?
37
- !written_data.empty?
38
- else
39
- written_data == data
40
- end
25
+ def write(text)
26
+ bytes_written = text.bytesize
27
+
28
+ written_text << text
29
+
30
+ bytes_written
41
31
  end
42
32
 
43
- def flushed?(data=nil)
44
- if data.nil?
45
- !flushed_data.empty?
33
+ def written?(text=nil)
34
+ if text.nil?
35
+ !written_text.empty?
46
36
  else
47
- flushed_data == data
37
+ written_text == text
48
38
  end
49
39
  end
50
-
51
- def tty!
52
- self.tty = true
53
- end
54
40
  end
55
41
  end
56
42
  end
@@ -0,0 +1,73 @@
1
+ module TestBench
2
+ class Output
3
+ class Device
4
+ Error = Class.new(RuntimeError)
5
+
6
+ def raw_device
7
+ @raw_device ||= Substitute.build
8
+ end
9
+ attr_writer :raw_device
10
+
11
+ def self.build(target_device=nil)
12
+ target_device ||= Defaults.target_device
13
+
14
+ raw_device = raw_device(target_device)
15
+
16
+ instance = new
17
+ instance.raw_device = raw_device
18
+ instance
19
+ end
20
+
21
+ def self.configure(receiver, device: nil, attr_name: nil)
22
+ attr_name ||= :device
23
+
24
+ if device.instance_of?(self)
25
+ instance = device
26
+ else
27
+ target_device = device
28
+
29
+ instance = build(target_device)
30
+ end
31
+
32
+ receiver.public_send(:"#{attr_name}=", instance)
33
+ end
34
+
35
+ def self.raw_device(target_device)
36
+ case target_device
37
+ in :stdout
38
+ STDOUT
39
+ in :stderr
40
+ STDERR
41
+ in :null
42
+ Null.instance
43
+ in Symbol
44
+ raise Error, "Incorrect output device: #{target_device.inspect}"
45
+ else
46
+ target_device
47
+ end
48
+ end
49
+
50
+ def write(text)
51
+ raw_device.write(text)
52
+
53
+ text.bytesize
54
+ end
55
+
56
+ def tty?
57
+ raw_device.tty?
58
+ end
59
+
60
+ module Defaults
61
+ def self.target_device
62
+ env_target_device = ENV.fetch('TEST_BENCH_OUTPUT_DEVICE') do
63
+ STDOUT.sync = true
64
+
65
+ 'stdout'
66
+ end
67
+
68
+ env_target_device.to_sym
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,30 @@
1
+ module TestBench
2
+ class Output
3
+ module Get
4
+ Error = Class.new(RuntimeError)
5
+
6
+ def self.call(substitute_session, styling: nil)
7
+ styling ||= false
8
+
9
+ if not substitute_session.instance_of?(Session::Substitute::Session)
10
+ raise Error, "Not a substitute session: #{substitute_session.inspect}"
11
+ end
12
+
13
+ output = Output.new
14
+
15
+ if styling
16
+ output.writer.set_styling
17
+ end
18
+
19
+ event_records = substitute_session.sink.records
20
+ event_records.each do |record|
21
+ event_data = record.event_data
22
+
23
+ output.receive(event_data)
24
+ end
25
+
26
+ output.writer.written_text
27
+ end
28
+ end
29
+ end
30
+ end