test_bench 1.0.1.0 → 1.2.0.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/lib/test_bench.rb +12 -10
- data/lib/test_bench/cli.rb +2 -2
- data/lib/test_bench/cli/parse_arguments.rb +50 -37
- data/lib/test_bench/controls.rb +8 -2
- data/lib/test_bench/controls/error.rb +8 -8
- data/lib/test_bench/controls/output/batch_data.rb +52 -0
- data/lib/test_bench/controls/output/detail_setting.rb +29 -0
- data/lib/test_bench/controls/output/exercise.rb +7 -0
- data/lib/test_bench/controls/output/log_level.rb +7 -0
- data/lib/test_bench/controls/output/newline_character.rb +6 -1
- data/lib/test_bench/controls/output/summary/error.rb +5 -21
- data/lib/test_bench/controls/output/summary/session.rb +20 -0
- data/lib/test_bench/controls/pattern.rb +6 -2
- data/lib/test_bench/controls/time.rb +30 -2
- data/lib/test_bench/deactivation_variants.rb +0 -10
- data/lib/test_bench/fixtures.rb +3 -1
- data/lib/test_bench/output.rb +14 -2
- data/lib/test_bench/output/batch_data.rb +17 -0
- data/lib/test_bench/output/buffer.rb +114 -0
- data/lib/test_bench/output/log.rb +27 -0
- data/lib/test_bench/output/raw.rb +353 -0
- data/lib/test_bench/output/summary.rb +146 -0
- data/lib/test_bench/output/summary/session.rb +94 -0
- data/lib/test_bench/output/timer/substitute.rb +1 -1
- data/lib/test_bench/output/writer.rb +3 -3
- data/lib/test_bench/run.rb +9 -9
- data/lib/test_bench/test_bench.rb +23 -3
- metadata +18 -17
- data/lib/test_bench/controls/output/summary/run.rb +0 -59
- data/lib/test_bench/output/build.rb +0 -57
- data/lib/test_bench/output/levels/debug.rb +0 -229
- data/lib/test_bench/output/levels/failure.rb +0 -31
- data/lib/test_bench/output/levels/none.rb +0 -13
- data/lib/test_bench/output/levels/pass.rb +0 -286
- data/lib/test_bench/output/levels/summary.rb +0 -21
- data/lib/test_bench/output/summary/error.rb +0 -77
- data/lib/test_bench/output/summary/run.rb +0 -102
- data/lib/test_bench/output/summary/run/print.rb +0 -98
@@ -0,0 +1,146 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Output
|
3
|
+
class Summary
|
4
|
+
include Fixture::Output
|
5
|
+
|
6
|
+
include Writer::Dependency
|
7
|
+
|
8
|
+
def file_count
|
9
|
+
@file_count ||= 0
|
10
|
+
end
|
11
|
+
attr_writer :file_count
|
12
|
+
|
13
|
+
def test_count
|
14
|
+
@test_count ||= 0
|
15
|
+
end
|
16
|
+
attr_writer :test_count
|
17
|
+
|
18
|
+
def pass_count
|
19
|
+
@pass_count ||= 0
|
20
|
+
end
|
21
|
+
attr_writer :pass_count
|
22
|
+
|
23
|
+
def skip_count
|
24
|
+
@skip_count ||= 0
|
25
|
+
end
|
26
|
+
attr_writer :skip_count
|
27
|
+
|
28
|
+
def failure_count
|
29
|
+
@failure_count ||= 0
|
30
|
+
end
|
31
|
+
attr_writer :failure_count
|
32
|
+
|
33
|
+
def error_count
|
34
|
+
@error_count ||= 0
|
35
|
+
end
|
36
|
+
attr_writer :error_count
|
37
|
+
|
38
|
+
def elapsed_time
|
39
|
+
@elapsed_time ||= 0
|
40
|
+
end
|
41
|
+
attr_writer :elapsed_time
|
42
|
+
|
43
|
+
def timer
|
44
|
+
@timer ||= Timer::Substitute.build
|
45
|
+
end
|
46
|
+
attr_writer :timer
|
47
|
+
|
48
|
+
def errors_by_file
|
49
|
+
@errors_by_file ||= Hash.new do |hash, key|
|
50
|
+
hash[key] = []
|
51
|
+
end
|
52
|
+
end
|
53
|
+
attr_writer :errors_by_file
|
54
|
+
|
55
|
+
attr_accessor :current_file
|
56
|
+
|
57
|
+
def configure(writer: nil, device: nil, styling: nil)
|
58
|
+
Writer.configure(self, writer: writer, device: device, styling: styling)
|
59
|
+
Timer.configure(self)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.build(writer: nil, device: nil, styling: nil)
|
63
|
+
instance = new
|
64
|
+
instance.configure(writer: writer, device: device, styling: styling)
|
65
|
+
instance
|
66
|
+
end
|
67
|
+
|
68
|
+
def enter_file(file)
|
69
|
+
timer.start
|
70
|
+
|
71
|
+
self.current_file = file
|
72
|
+
end
|
73
|
+
|
74
|
+
def exit_file(_, _)
|
75
|
+
elapsed_time = timer.stop
|
76
|
+
|
77
|
+
self.elapsed_time += elapsed_time
|
78
|
+
|
79
|
+
self.file_count += 1
|
80
|
+
end
|
81
|
+
|
82
|
+
def finish_test(_, result)
|
83
|
+
self.test_count += 1
|
84
|
+
|
85
|
+
if result
|
86
|
+
self.pass_count += 1
|
87
|
+
else
|
88
|
+
self.failure_count += 1
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def skip_test(_)
|
93
|
+
self.skip_count += 1
|
94
|
+
end
|
95
|
+
|
96
|
+
def error(error)
|
97
|
+
errors_by_file[current_file] << error
|
98
|
+
|
99
|
+
self.error_count += 1
|
100
|
+
end
|
101
|
+
|
102
|
+
def finish(_)
|
103
|
+
error_summary
|
104
|
+
|
105
|
+
session_summary
|
106
|
+
end
|
107
|
+
|
108
|
+
def session_summary
|
109
|
+
Session.(file_count: file_count, test_count: test_count, pass_count: pass_count, skip_count: skip_count, failure_count: failure_count, error_count: error_count, elapsed_time: elapsed_time, writer: writer)
|
110
|
+
end
|
111
|
+
|
112
|
+
def error_summary
|
113
|
+
return if errors_by_file.empty?
|
114
|
+
|
115
|
+
writer
|
116
|
+
.escape_code(:bold)
|
117
|
+
.escape_code(:red)
|
118
|
+
.text('Error Summary:')
|
119
|
+
.escape_code(:reset_intensity)
|
120
|
+
.escape_code(:reset_fg)
|
121
|
+
.newline
|
122
|
+
|
123
|
+
errors_by_file.each do |file, errors|
|
124
|
+
error_count = errors.count
|
125
|
+
|
126
|
+
writer
|
127
|
+
.text(error_count.to_s.rjust(4, ' '))
|
128
|
+
.text(": #{file}")
|
129
|
+
.newline
|
130
|
+
|
131
|
+
errors.each do |error|
|
132
|
+
writer
|
133
|
+
.text(' ')
|
134
|
+
.escape_code(:red)
|
135
|
+
|
136
|
+
PrintError.error_message(error, writer: writer)
|
137
|
+
|
138
|
+
writer.escape_code(:reset_fg)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
writer.newline
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Output
|
3
|
+
class Summary
|
4
|
+
module Session
|
5
|
+
def self.call(file_count: nil, test_count: nil, pass_count: nil, skip_count: nil, failure_count: nil, error_count: nil, elapsed_time: nil, writer: nil)
|
6
|
+
file_count ||= 0
|
7
|
+
test_count ||= 0
|
8
|
+
pass_count ||= 0
|
9
|
+
skip_count ||= 0
|
10
|
+
failure_count ||= 0
|
11
|
+
error_count ||= 0
|
12
|
+
elapsed_time ||= 0
|
13
|
+
writer ||= Writer.build
|
14
|
+
|
15
|
+
failed = error_count > 0
|
16
|
+
|
17
|
+
if elapsed_time.nonzero?
|
18
|
+
tests_per_second = test_count / elapsed_time
|
19
|
+
end
|
20
|
+
|
21
|
+
if failed
|
22
|
+
writer.escape_code(:red)
|
23
|
+
end
|
24
|
+
|
25
|
+
writer
|
26
|
+
.text("Finished running #{numeric_label(file_count, 'file')}")
|
27
|
+
.newline
|
28
|
+
.text("Ran %s in %.3fs (%.1f tests/second)" % [
|
29
|
+
numeric_label(test_count, 'test'),
|
30
|
+
elapsed_time,
|
31
|
+
tests_per_second || 0])
|
32
|
+
.newline
|
33
|
+
|
34
|
+
if pass_count.nonzero? && !failed
|
35
|
+
writer
|
36
|
+
.escape_code(:green)
|
37
|
+
.text("#{pass_count} passed")
|
38
|
+
.escape_code(:reset_fg)
|
39
|
+
else
|
40
|
+
writer.text("#{pass_count} passed")
|
41
|
+
end
|
42
|
+
|
43
|
+
writer.text(", ")
|
44
|
+
|
45
|
+
if skip_count.nonzero? && !failed
|
46
|
+
writer
|
47
|
+
.escape_code(:yellow)
|
48
|
+
.text("#{skip_count} skipped")
|
49
|
+
.escape_code(:reset_fg)
|
50
|
+
else
|
51
|
+
writer.text("#{skip_count} skipped")
|
52
|
+
end
|
53
|
+
|
54
|
+
writer.text(", ")
|
55
|
+
|
56
|
+
if failure_count.nonzero?
|
57
|
+
writer
|
58
|
+
.escape_code(:bold)
|
59
|
+
.text("#{failure_count} failed")
|
60
|
+
.escape_code(:reset_intensity)
|
61
|
+
else
|
62
|
+
writer.text("0 failed")
|
63
|
+
end
|
64
|
+
|
65
|
+
writer.text(", ")
|
66
|
+
|
67
|
+
if failed
|
68
|
+
writer
|
69
|
+
.escape_code(:bold)
|
70
|
+
.text(numeric_label(error_count, 'total error'))
|
71
|
+
.escape_code(:reset_intensity)
|
72
|
+
.escape_code(:reset_fg)
|
73
|
+
else
|
74
|
+
writer.text("0 total errors")
|
75
|
+
end
|
76
|
+
|
77
|
+
2.times do
|
78
|
+
writer.newline
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.numeric_label(number, label, plural_text=nil)
|
83
|
+
plural_text ||= 's'
|
84
|
+
|
85
|
+
if number == 1
|
86
|
+
"#{number} #{label}"
|
87
|
+
else
|
88
|
+
"#{number} #{label}#{plural_text}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -106,7 +106,7 @@ module TestBench
|
|
106
106
|
|
107
107
|
def newline
|
108
108
|
sync
|
109
|
-
device.puts
|
109
|
+
device.puts('')
|
110
110
|
self.byte_offset += 1
|
111
111
|
self
|
112
112
|
end
|
@@ -130,7 +130,7 @@ module TestBench
|
|
130
130
|
end
|
131
131
|
|
132
132
|
def self.styling?(device, styling_setting=nil)
|
133
|
-
styling_setting ||= Defaults.
|
133
|
+
styling_setting ||= Defaults.styling
|
134
134
|
|
135
135
|
assure_styling_setting(styling_setting)
|
136
136
|
|
@@ -177,7 +177,7 @@ module TestBench
|
|
177
177
|
$stdout
|
178
178
|
end
|
179
179
|
|
180
|
-
def self.
|
180
|
+
def self.styling
|
181
181
|
styling = ::ENV['TEST_BENCH_OUTPUT_STYLING']
|
182
182
|
|
183
183
|
if styling.nil?
|
data/lib/test_bench/run.rb
CHANGED
@@ -3,14 +3,14 @@ module TestBench
|
|
3
3
|
Error = Class.new(RuntimeError)
|
4
4
|
|
5
5
|
def session
|
6
|
-
@session ||= Session::Substitute.build
|
6
|
+
@session ||= Fixture::Session::Substitute.build
|
7
7
|
end
|
8
8
|
attr_writer :session
|
9
9
|
|
10
|
-
def
|
11
|
-
@
|
10
|
+
def exclude_pattern
|
11
|
+
@exclude_pattern ||= Defaults.exclude_pattern
|
12
12
|
end
|
13
|
-
attr_writer :
|
13
|
+
attr_writer :exclude_pattern
|
14
14
|
|
15
15
|
attr_reader :paths
|
16
16
|
|
@@ -18,14 +18,14 @@ module TestBench
|
|
18
18
|
@paths = Array(paths)
|
19
19
|
end
|
20
20
|
|
21
|
-
def self.build(*paths,
|
21
|
+
def self.build(*paths, exclude: nil, session: nil, output: nil)
|
22
22
|
session ||= TestBench.session
|
23
23
|
|
24
24
|
instance = new(*paths)
|
25
25
|
|
26
|
-
instance.
|
26
|
+
instance.exclude_pattern = exclude unless exclude.nil?
|
27
27
|
|
28
|
-
Session.configure(instance, session: session)
|
28
|
+
Fixture::Session.configure(instance, session: session)
|
29
29
|
instance.session.output = output unless output.nil?
|
30
30
|
|
31
31
|
instance
|
@@ -80,7 +80,7 @@ module TestBench
|
|
80
80
|
glob_pattern = File.join(path, '**/*.rb')
|
81
81
|
|
82
82
|
Dir[glob_pattern].sort.each do |path|
|
83
|
-
next if
|
83
|
+
next if exclude_pattern.match?(path)
|
84
84
|
|
85
85
|
file(path)
|
86
86
|
end
|
@@ -91,7 +91,7 @@ module TestBench
|
|
91
91
|
end
|
92
92
|
|
93
93
|
module Defaults
|
94
|
-
def self.
|
94
|
+
def self.exclude_pattern
|
95
95
|
pattern = ENV.fetch('TEST_BENCH_EXCLUDE_FILE_PATTERN') do
|
96
96
|
'_init.rb$'
|
97
97
|
end
|
@@ -2,7 +2,9 @@ module TestBench
|
|
2
2
|
def self.session
|
3
3
|
@session ||= build_session.tap do |session|
|
4
4
|
at_exit do
|
5
|
-
|
5
|
+
exit_code = exit_code(session)
|
6
|
+
|
7
|
+
exit(exit_code) unless exit_code.zero?
|
6
8
|
end
|
7
9
|
end
|
8
10
|
end
|
@@ -65,7 +67,7 @@ module TestBench
|
|
65
67
|
end
|
66
68
|
|
67
69
|
def self.session_error_policy(abort_on_error=nil)
|
68
|
-
abort_on_error =
|
70
|
+
abort_on_error = Defaults.abort_on_error if abort_on_error.nil?
|
69
71
|
|
70
72
|
if abort_on_error
|
71
73
|
:abort
|
@@ -74,11 +76,29 @@ module TestBench
|
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
79
|
+
def self.exit_code(session, fail_deactivated_tests: nil)
|
80
|
+
if fail_deactivated_tests.nil?
|
81
|
+
fail_deactivated_tests = Defaults.fail_deactivated_tests
|
82
|
+
end
|
83
|
+
|
84
|
+
if session.failed?
|
85
|
+
1
|
86
|
+
elsif session.skip?
|
87
|
+
fail_deactivated_tests ? 2 : 0
|
88
|
+
else
|
89
|
+
0
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
77
93
|
Session = Fixture::Session
|
78
94
|
|
79
|
-
module
|
95
|
+
module Defaults
|
80
96
|
def self.abort_on_error
|
81
97
|
Environment::Boolean.fetch('TEST_BENCH_ABORT_ON_ERROR', false)
|
82
98
|
end
|
99
|
+
|
100
|
+
def self.fail_deactivated_tests
|
101
|
+
Environment::Boolean.fetch('TEST_BENCH_FAIL_DEACTIVATED_TESTS', true)
|
102
|
+
end
|
83
103
|
end
|
84
104
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test_bench
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Ladd
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: script
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test_bench-fixture
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description:
|
41
|
+
description:
|
42
42
|
email: nathanladd+github@gmail.com
|
43
43
|
executables:
|
44
44
|
- bench
|
@@ -55,12 +55,16 @@ files:
|
|
55
55
|
- lib/test_bench/controls/directory.rb
|
56
56
|
- lib/test_bench/controls/error.rb
|
57
57
|
- lib/test_bench/controls/fixture.rb
|
58
|
+
- lib/test_bench/controls/output/batch_data.rb
|
59
|
+
- lib/test_bench/controls/output/detail_setting.rb
|
58
60
|
- lib/test_bench/controls/output/escape_code.rb
|
61
|
+
- lib/test_bench/controls/output/exercise.rb
|
62
|
+
- lib/test_bench/controls/output/log_level.rb
|
59
63
|
- lib/test_bench/controls/output/newline_character.rb
|
60
64
|
- lib/test_bench/controls/output/print_error.rb
|
61
65
|
- lib/test_bench/controls/output/styling.rb
|
62
66
|
- lib/test_bench/controls/output/summary/error.rb
|
63
|
-
- lib/test_bench/controls/output/summary/
|
67
|
+
- lib/test_bench/controls/output/summary/session.rb
|
64
68
|
- lib/test_bench/controls/path.rb
|
65
69
|
- lib/test_bench/controls/pattern.rb
|
66
70
|
- lib/test_bench/controls/result.rb
|
@@ -71,16 +75,13 @@ files:
|
|
71
75
|
- lib/test_bench/fixtures.rb
|
72
76
|
- lib/test_bench/fixtures/configure_receiver.rb
|
73
77
|
- lib/test_bench/output.rb
|
74
|
-
- lib/test_bench/output/
|
75
|
-
- lib/test_bench/output/
|
76
|
-
- lib/test_bench/output/
|
77
|
-
- lib/test_bench/output/levels/none.rb
|
78
|
-
- lib/test_bench/output/levels/pass.rb
|
79
|
-
- lib/test_bench/output/levels/summary.rb
|
78
|
+
- lib/test_bench/output/batch_data.rb
|
79
|
+
- lib/test_bench/output/buffer.rb
|
80
|
+
- lib/test_bench/output/log.rb
|
80
81
|
- lib/test_bench/output/print_error.rb
|
81
|
-
- lib/test_bench/output/
|
82
|
-
- lib/test_bench/output/summary
|
83
|
-
- lib/test_bench/output/summary/
|
82
|
+
- lib/test_bench/output/raw.rb
|
83
|
+
- lib/test_bench/output/summary.rb
|
84
|
+
- lib/test_bench/output/summary/session.rb
|
84
85
|
- lib/test_bench/output/timer.rb
|
85
86
|
- lib/test_bench/output/timer/substitute.rb
|
86
87
|
- lib/test_bench/output/writer.rb
|
@@ -95,7 +96,7 @@ homepage: https://github.com/test-bench/test-bench
|
|
95
96
|
licenses:
|
96
97
|
- MIT
|
97
98
|
metadata: {}
|
98
|
-
post_install_message:
|
99
|
+
post_install_message:
|
99
100
|
rdoc_options: []
|
100
101
|
require_paths:
|
101
102
|
- lib
|
@@ -110,8 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
111
|
- !ruby/object:Gem::Version
|
111
112
|
version: '0'
|
112
113
|
requirements: []
|
113
|
-
rubygems_version: 3.1.
|
114
|
-
signing_key:
|
114
|
+
rubygems_version: 3.1.4
|
115
|
+
signing_key:
|
115
116
|
specification_version: 4
|
116
117
|
summary: Principled Test Framework for Ruby
|
117
118
|
test_files: []
|