test_bench 1.0.1.0 → 1.2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/test_bench.rb +12 -10
  3. data/lib/test_bench/cli.rb +2 -2
  4. data/lib/test_bench/cli/parse_arguments.rb +50 -37
  5. data/lib/test_bench/controls.rb +8 -2
  6. data/lib/test_bench/controls/error.rb +8 -8
  7. data/lib/test_bench/controls/output/batch_data.rb +52 -0
  8. data/lib/test_bench/controls/output/detail_setting.rb +29 -0
  9. data/lib/test_bench/controls/output/exercise.rb +7 -0
  10. data/lib/test_bench/controls/output/log_level.rb +7 -0
  11. data/lib/test_bench/controls/output/newline_character.rb +6 -1
  12. data/lib/test_bench/controls/output/summary/error.rb +5 -21
  13. data/lib/test_bench/controls/output/summary/session.rb +20 -0
  14. data/lib/test_bench/controls/pattern.rb +6 -2
  15. data/lib/test_bench/controls/time.rb +30 -2
  16. data/lib/test_bench/deactivation_variants.rb +0 -10
  17. data/lib/test_bench/fixtures.rb +3 -1
  18. data/lib/test_bench/output.rb +14 -2
  19. data/lib/test_bench/output/batch_data.rb +17 -0
  20. data/lib/test_bench/output/buffer.rb +114 -0
  21. data/lib/test_bench/output/log.rb +27 -0
  22. data/lib/test_bench/output/raw.rb +353 -0
  23. data/lib/test_bench/output/summary.rb +146 -0
  24. data/lib/test_bench/output/summary/session.rb +94 -0
  25. data/lib/test_bench/output/timer/substitute.rb +1 -1
  26. data/lib/test_bench/output/writer.rb +3 -3
  27. data/lib/test_bench/run.rb +9 -9
  28. data/lib/test_bench/test_bench.rb +23 -3
  29. metadata +18 -17
  30. data/lib/test_bench/controls/output/summary/run.rb +0 -59
  31. data/lib/test_bench/output/build.rb +0 -57
  32. data/lib/test_bench/output/levels/debug.rb +0 -229
  33. data/lib/test_bench/output/levels/failure.rb +0 -31
  34. data/lib/test_bench/output/levels/none.rb +0 -13
  35. data/lib/test_bench/output/levels/pass.rb +0 -286
  36. data/lib/test_bench/output/levels/summary.rb +0 -21
  37. data/lib/test_bench/output/summary/error.rb +0 -77
  38. data/lib/test_bench/output/summary/run.rb +0 -102
  39. data/lib/test_bench/output/summary/run/print.rb +0 -98
@@ -1,59 +0,0 @@
1
- module TestBench
2
- module Controls
3
- module Output
4
- module Summary
5
- module Run
6
- def self.example(writer: nil, timer: nil)
7
- run_summary = Example.new
8
- run_summary.writer = writer unless writer.nil?
9
- run_summary.timer = timer unless timer.nil?
10
- run_summary
11
- end
12
-
13
- class Example
14
- include TestBench::Fixture::Output
15
- include TestBench::Output::Summary::Run
16
-
17
- TestBench::Fixture::Output.instance_methods.each do |method|
18
- define_method(method) do |*|
19
- end
20
- end
21
- end
22
-
23
- module Text
24
- def self.example
25
- <<~TEXT
26
- Finished running 0 files
27
- Ran 0 tests in 0.000s (0.0 tests/second)
28
- 0 passed, 0 skipped, 0 failed, 0 total errors
29
-
30
- TEXT
31
- end
32
-
33
- module Pass
34
- def self.example
35
- <<~TEXT
36
- Finished running 1 file
37
- Ran 1 test in 0.000s (0.0 tests/second)
38
- 1 passed, 0 skipped, 0 failed, 0 total errors
39
-
40
- TEXT
41
- end
42
- end
43
-
44
- module Failure
45
- def self.example
46
- <<~TEXT
47
- Finished running 1 file
48
- Ran 1 test in 0.000s (0.0 tests/second)
49
- 0 passed, 0 skipped, 1 failed, 1 total error
50
-
51
- TEXT
52
- end
53
- end
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,57 +0,0 @@
1
- module TestBench
2
- module Output
3
- module Build
4
- Error = Class.new(RuntimeError)
5
-
6
- def self.call(level: nil, **args)
7
- level ||= Defaults.level
8
-
9
- level_setting = level
10
-
11
- cls = level_class(level_setting)
12
-
13
- cls.build(**args)
14
- end
15
-
16
- def self.level_class(level_setting)
17
- assure_level(level_setting)
18
-
19
- levels.fetch(level_setting)
20
- end
21
-
22
- def self.levels
23
- {
24
- :none => Levels::None,
25
- :summary => Levels::Summary,
26
- :failure => Levels::Failure,
27
- :pass => Levels::Pass,
28
- :debug => Levels::Debug
29
- }
30
- end
31
-
32
- def self.level_settings
33
- levels.keys
34
- end
35
-
36
- def self.assure_level(level_setting)
37
- unless level_settings.include?(level_setting)
38
- raise Error, "Unknown output level #{level_setting.inspect} (Valid levels: #{level_settings.map(&:inspect) * ', '})"
39
- end
40
- end
41
-
42
- module Defaults
43
- def self.level
44
- verbose = Environment::Boolean.fetch('VERBOSE')
45
-
46
- if verbose.nil?
47
- level_text = ENV.fetch('TEST_BENCH_OUTPUT_LEVEL', 'pass')
48
-
49
- level_text.to_sym
50
- else
51
- :debug
52
- end
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,229 +0,0 @@
1
- module TestBench
2
- module Output
3
- module Levels
4
- class Debug
5
- include TestBench::Fixture::Output
6
-
7
- include Writer::Dependency
8
-
9
- include PrintError
10
-
11
- include Output::Summary::Error
12
- include Output::Summary::Run
13
-
14
- def previous_byte_offset
15
- @previous_byte_offset ||= 0
16
- end
17
- attr_writer :previous_byte_offset
18
-
19
- def self.build(omit_backtrace_pattern: nil, reverse_backtraces: nil, writer: nil, styling: nil, device: nil)
20
- instance = new
21
-
22
- instance.omit_backtrace_pattern = omit_backtrace_pattern unless omit_backtrace_pattern.nil?
23
- instance.reverse_backtraces = reverse_backtraces unless reverse_backtraces.nil?
24
-
25
- Writer.configure(instance, writer: writer, styling: styling, device: device)
26
- Timer.configure(instance)
27
-
28
- instance
29
- end
30
-
31
- def comment(text)
32
- writer
33
- .indent
34
- .text(text)
35
- .newline
36
- end
37
-
38
- def error(error)
39
- print_error(error)
40
- end
41
-
42
- def finish_test(title, result)
43
- writer.decrease_indentation
44
-
45
- fg_color = result ? :green : :red
46
-
47
- writer.indent
48
-
49
- writer
50
- .escape_code(fg_color)
51
- .text("Finished test")
52
-
53
- unless title.nil?
54
- writer
55
- .text(' ')
56
- .escape_code(:bold)
57
- .text(title.inspect)
58
- .escape_code(:reset_intensity)
59
- end
60
-
61
- writer
62
- .text(" (Result: #{result ? 'pass' : 'failure'})")
63
- .escape_code(:reset_fg)
64
- .newline
65
- end
66
-
67
- def skip_test(title)
68
- writer.indent
69
-
70
- writer
71
- .escape_code(:yellow)
72
- .text("Skipped test")
73
-
74
- unless title.nil?
75
- writer
76
- .text(' ')
77
- .escape_code(:bold)
78
- .text(title.inspect)
79
- .escape_code(:reset_intensity)
80
- end
81
-
82
- writer
83
- .escape_code(:reset_fg)
84
- .newline
85
- end
86
-
87
- def start_test(title)
88
- if title.nil?
89
- text = "Starting test"
90
- else
91
- text = "Starting test #{title.inspect}"
92
- end
93
-
94
- writer
95
- .indent
96
- .escape_code(:cyan)
97
- .text(text)
98
- .escape_code(:reset_fg)
99
- .newline
100
-
101
- writer.increase_indentation
102
- end
103
-
104
- def enter_context(title)
105
- return if title.nil?
106
-
107
- writer
108
- .indent
109
- .escape_code(:green)
110
- .text(title)
111
- .escape_code(:reset_fg)
112
- .newline
113
-
114
- writer.increase_indentation
115
- end
116
-
117
- def exit_context(title, result)
118
- return if title.nil?
119
-
120
- writer.decrease_indentation
121
-
122
- fg_color = result ? :green : :red
123
-
124
- text = "Finished context #{title.inspect} (Result: #{result ? 'pass' : 'failure'})"
125
-
126
- writer
127
- .indent
128
- .escape_code(:faint)
129
- .escape_code(:italic)
130
- .escape_code(fg_color)
131
- .text(text)
132
- .escape_code(:reset_fg)
133
- .escape_code(:reset_italic)
134
- .escape_code(:reset_intensity)
135
- .newline
136
-
137
- writer.newline if writer.indentation_depth.zero?
138
- end
139
-
140
- def skip_context(title)
141
- return if title.nil?
142
-
143
- writer
144
- .indent
145
- .escape_code(:yellow)
146
- .text(title)
147
- .escape_code(:reset_fg)
148
- .newline
149
-
150
- writer.newline if writer.indentation_depth.zero?
151
- end
152
-
153
- def start_fixture(fixture)
154
- fixture_class = fixture.class.inspect
155
-
156
- writer
157
- .indent
158
- .escape_code(:blue)
159
- .text("Starting fixture (Fixture: #{fixture_class})")
160
- .escape_code(:reset_fg)
161
- .newline
162
-
163
- writer.increase_indentation
164
- end
165
-
166
- def finish_fixture(fixture, result)
167
- fixture_class = fixture.class.inspect
168
-
169
- writer.decrease_indentation
170
-
171
- writer
172
- .indent
173
- .escape_code(:magenta)
174
- .text("Finished fixture (Fixture: #{fixture_class}, Result: #{result ? 'pass' : 'failure'})")
175
- .escape_code(:reset_fg)
176
- .newline
177
-
178
- writer.newline if writer.indentation_depth.zero?
179
- end
180
-
181
- def enter_file(file)
182
- text = "Running #{file}"
183
-
184
- writer.text(text).newline
185
-
186
- self.previous_byte_offset = writer.byte_offset
187
- end
188
-
189
- def exit_file(file, _)
190
- unless writer.byte_offset > previous_byte_offset
191
- writer
192
- .escape_code(:faint)
193
- .text("(Nothing written)")
194
- .escape_code(:reset_intensity)
195
- .newline
196
-
197
- writer.newline
198
- end
199
- end
200
-
201
- def enter_assert_block(caller_location)
202
- text = "Entered assert block (Caller Location: #{caller_location})"
203
-
204
- writer
205
- .indent
206
- .escape_code(:blue)
207
- .text(text)
208
- .escape_code(:reset_fg)
209
- .newline
210
-
211
- writer.increase_indentation
212
- end
213
-
214
- def exit_assert_block(caller_location, result)
215
- writer.decrease_indentation
216
-
217
- text = "Exited assert block (Caller Location: #{caller_location}, Result: #{result ? 'pass' : 'failure'})"
218
-
219
- writer
220
- .indent
221
- .escape_code(:cyan)
222
- .text(text)
223
- .escape_code(:reset_fg)
224
- .newline
225
- end
226
- end
227
- end
228
- end
229
- end
@@ -1,31 +0,0 @@
1
- module TestBench
2
- module Output
3
- module Levels
4
- class Failure
5
- include TestBench::Fixture::Output
6
-
7
- include Output::PrintError
8
- include Output::Summary::Error
9
-
10
- def self.build(omit_backtrace_pattern: nil, reverse_backtraces: nil, writer: nil, styling: nil, device: nil)
11
- warn "Warning: #{self} is deprecated. It will remain in the TestBench v2 series, but will be removed from TestBench v3"
12
-
13
- instance = new
14
-
15
- instance.omit_backtrace_pattern = omit_backtrace_pattern unless omit_backtrace_pattern.nil?
16
- instance.reverse_backtraces = reverse_backtraces unless reverse_backtraces.nil?
17
-
18
- Writer.configure(instance, writer: writer, styling: styling, device: device)
19
-
20
- instance
21
- end
22
-
23
- def error(error)
24
- print_error(error)
25
-
26
- writer.newline
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,13 +0,0 @@
1
- module TestBench
2
- module Output
3
- module Levels
4
- class None < Fixture::Output::Null
5
- def self.build
6
- warn "Warning: #{self} is deprecated. It will remain in the TestBench v2 series, but will be removed from TestBench v3"
7
-
8
- new
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,286 +0,0 @@
1
- module TestBench
2
- module Output
3
- module Levels
4
- class Pass
5
- include TestBench::Fixture::Output
6
-
7
- include Writer::Dependency
8
-
9
- include PrintError
10
-
11
- include Output::Summary::Error
12
- include Output::Summary::Run
13
-
14
- attr_accessor :previous_error
15
-
16
- def previous_byte_offset
17
- @previous_byte_offset ||= 0
18
- end
19
- attr_writer :previous_byte_offset
20
-
21
- def assert_block_stack
22
- @assert_block_stack ||= AssertBlockStack.new(writer)
23
- end
24
- attr_writer :assert_block_stack
25
-
26
- def test_stack
27
- @test_stack ||= []
28
- end
29
- attr_writer :test_stack
30
-
31
- def self.build(omit_backtrace_pattern: nil, reverse_backtraces: nil, writer: nil, styling: nil, device: nil)
32
- instance = new
33
-
34
- instance.omit_backtrace_pattern = omit_backtrace_pattern unless omit_backtrace_pattern.nil?
35
- instance.reverse_backtraces = reverse_backtraces unless reverse_backtraces.nil?
36
-
37
- Writer.configure(instance, writer: writer, styling: styling, device: device)
38
- Timer.configure(instance)
39
-
40
- instance
41
- end
42
-
43
- def comment(text)
44
- writer
45
- .indent
46
- .text(text)
47
- .newline
48
- end
49
-
50
- def error(error)
51
- self.previous_error = error
52
- end
53
-
54
- def print_previous_error
55
- print_error(previous_error)
56
-
57
- self.previous_error = nil
58
- end
59
-
60
- def start_test(_)
61
- test_stack.push(true)
62
- end
63
-
64
- def finish_test(title, result)
65
- test_stack.pop
66
-
67
- unless result && title.nil?
68
- writer.indent
69
-
70
- writer.escape_code(:bold) unless result
71
-
72
- fg_color = result ? :green : :red
73
-
74
- writer
75
- .escape_code(fg_color)
76
- .text(title || 'Test')
77
- .escape_code(:reset_fg)
78
-
79
- writer.escape_code(:reset_intensity) unless result
80
-
81
- writer.newline
82
- end
83
-
84
- unless previous_error.nil?
85
- writer.increase_indentation
86
-
87
- print_previous_error
88
-
89
- writer.decrease_indentation
90
- end
91
-
92
- unless result
93
- assert_block_stack.print_captured_text
94
- end
95
- end
96
-
97
- def skip_test(title)
98
- title ||= 'Test'
99
-
100
- writer.indent
101
-
102
- if writer.styling?
103
- writer
104
- .escape_code(:yellow)
105
- .text(title)
106
- .escape_code(:reset_fg)
107
- else
108
- writer.text("#{title} (skipped)")
109
- end
110
-
111
- writer.newline
112
- end
113
-
114
- def enter_context(title)
115
- test_stack.push(false)
116
-
117
- return if title.nil?
118
-
119
- writer
120
- .indent
121
- .escape_code(:green)
122
- .text(title)
123
- .escape_code(:reset_fg)
124
- .newline
125
-
126
- writer.increase_indentation
127
- end
128
-
129
- def exit_context(title, result)
130
- test_stack.pop
131
-
132
- print_previous_error unless previous_error.nil?
133
-
134
- unless result
135
- assert_block_stack.print_captured_text
136
- end
137
-
138
- return if title.nil?
139
-
140
- writer.decrease_indentation
141
-
142
- writer.newline if writer.indentation_depth.zero?
143
- end
144
-
145
- def skip_context(title)
146
- return if title.nil?
147
-
148
- writer.indent
149
-
150
- if writer.styling?
151
- writer
152
- .escape_code(:yellow)
153
- .text(title)
154
- .escape_code(:reset_fg)
155
- else
156
- writer.text("#{title} (skipped)")
157
- end
158
-
159
- writer.newline
160
-
161
- writer.newline if writer.indentation_depth.zero?
162
- end
163
-
164
- def enter_file(file)
165
- text = "Running #{file}"
166
-
167
- writer.text(text).newline
168
-
169
- self.previous_byte_offset = writer.byte_offset
170
- end
171
-
172
- def exit_file(file, result)
173
- print_previous_error unless previous_error.nil?
174
-
175
- unless result
176
- assert_block_stack.print_captured_text
177
- end
178
-
179
- unless writer.byte_offset > previous_byte_offset
180
- writer
181
- .escape_code(:faint)
182
- .text("(Nothing written)")
183
- .escape_code(:reset_intensity)
184
- .newline
185
-
186
- writer.newline
187
- end
188
- end
189
-
190
- def finish_fixture(_, result)
191
- print_previous_error unless previous_error.nil?
192
-
193
- unless result
194
- assert_block_stack.print_captured_text
195
- end
196
- end
197
-
198
- def enter_assert_block(_)
199
- inside_test = inside_test?
200
-
201
- test_stack.push(false)
202
-
203
- assert_block_stack.push
204
-
205
- writer.increase_indentation
206
- writer.increase_indentation if inside_test
207
- end
208
-
209
- def exit_assert_block(_, result)
210
- test_stack.pop
211
-
212
- print_previous_error unless previous_error.nil?
213
-
214
- unless result
215
- assert_block_stack.print_captured_text
216
- end
217
-
218
- discard_captured_text = result
219
-
220
- assert_block_stack.pop(discard_captured_text)
221
-
222
- writer.decrease_indentation if inside_test?
223
- writer.decrease_indentation
224
- end
225
-
226
- def inside_test?
227
- test_stack[-1]
228
- end
229
-
230
- class AssertBlockStack
231
- def stack
232
- @stack ||= []
233
- end
234
-
235
- attr_accessor :captured_text
236
-
237
- attr_reader :writer
238
-
239
- def initialize(writer)
240
- @writer = writer
241
- end
242
-
243
- def push
244
- capture_text = String.new
245
-
246
- previous_device = writer.device
247
-
248
- writer.device = StringIO.new(capture_text)
249
-
250
- entry = Entry.new(capture_text, previous_device)
251
-
252
- stack.push(entry)
253
-
254
- entry
255
- end
256
-
257
- def pop(discard)
258
- entry = stack.pop
259
-
260
- writer.device = entry.previous_device
261
-
262
- unless discard
263
- self.captured_text = entry.capture_text
264
- end
265
-
266
- entry
267
- end
268
-
269
- def print_captured_text
270
- return if captured_text.nil?
271
-
272
- writer.text(captured_text)
273
-
274
- self.captured_text = nil
275
- end
276
-
277
- def inside_test?
278
- test_stack[-1]
279
- end
280
-
281
- Entry = Struct.new(:capture_text, :previous_device)
282
- end
283
- end
284
- end
285
- end
286
- end