test_bench-bootstrap 0.0.0 → 2.1.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.
- checksums.yaml +4 -4
- data/lib/test_bench/bootstrap.rb +65 -35
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04226ba70367c28b48c2c29d0691ffd31949b08017a342fb8f32c6e841a2d44c
|
4
|
+
data.tar.gz: 40d1d80234fa5b2fefb05e26335aa4ce85483e2995696fa319e563db32e1d4f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0fb1e8d99ad10a5085610837ae9ef987ded7d517692cd1d6ab854e5a6ff2c7f502ee39f5d6965fc7f036550bf07a8d0968d3836ee89ad2abab5b34ef2a9c892
|
7
|
+
data.tar.gz: 737d057fe58581cd3aa7f6b23872df01e26594f75eec2b306b9b47220c390a93d43019f4e1c30eceeb021e5be03780624c640f27bd65ec60ebdb84a68c6420f8
|
data/lib/test_bench/bootstrap.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
module TestBench
|
2
2
|
module Bootstrap
|
3
|
-
def self.activate
|
4
|
-
|
5
|
-
|
6
|
-
receiver.extend(Fixture)
|
3
|
+
def self.activate
|
4
|
+
Object.include(Fixture)
|
7
5
|
end
|
8
6
|
|
9
7
|
module Fixture
|
10
8
|
def assert(value)
|
11
9
|
unless value
|
12
|
-
raise AssertionFailure.build(
|
10
|
+
raise AssertionFailure.build(caller.first)
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
@@ -27,24 +25,24 @@ module TestBench
|
|
27
25
|
end
|
28
26
|
end
|
29
27
|
|
30
|
-
raise AssertionFailure.build(
|
28
|
+
raise AssertionFailure.build(caller.first)
|
31
29
|
end
|
32
30
|
|
33
31
|
def refute(value)
|
34
32
|
if value
|
35
|
-
raise AssertionFailure.build(
|
33
|
+
raise AssertionFailure.build(caller.first)
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
|
-
def refute_raises(error_class, &block)
|
37
|
+
def refute_raises(error_class=nil, &block)
|
40
38
|
block.()
|
41
39
|
|
42
|
-
rescue error_class => error
|
40
|
+
rescue (error_class || StandardError) => error
|
43
41
|
unless error.instance_of?(error_class)
|
44
42
|
raise error
|
45
43
|
end
|
46
44
|
|
47
|
-
raise AssertionFailure.build(
|
45
|
+
raise AssertionFailure.build(caller.first)
|
48
46
|
end
|
49
47
|
|
50
48
|
def context(prose=nil, &block)
|
@@ -70,6 +68,10 @@ module TestBench
|
|
70
68
|
end
|
71
69
|
end
|
72
70
|
|
71
|
+
def _context(prose=nil, &block)
|
72
|
+
context(prose)
|
73
|
+
end
|
74
|
+
|
73
75
|
def test(prose=nil, &block)
|
74
76
|
if block.nil?
|
75
77
|
Output.write(prose || 'Test', sgr_code: 0x33)
|
@@ -90,81 +92,109 @@ module TestBench
|
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
95
|
+
def _test(prose=nil, &block)
|
96
|
+
test(prose)
|
97
|
+
end
|
98
|
+
|
93
99
|
def comment(text)
|
94
100
|
Output.write(text)
|
95
101
|
end
|
96
102
|
|
103
|
+
def fixture(cls, *args, **kwargs, &block)
|
104
|
+
fixture = TestBench::Fixture.(cls, *args, **kwargs, &block)
|
105
|
+
|
106
|
+
passed = !fixture.test_session.failed?
|
107
|
+
|
108
|
+
assert(passed)
|
109
|
+
end
|
110
|
+
|
97
111
|
def self.print_error(error)
|
98
112
|
omit_backtrace_pattern = ENV['TEST_BENCH_OMIT_BACKTRACE_PATTERN']
|
99
|
-
omit_backtrace_pattern ||= %r{
|
113
|
+
omit_backtrace_pattern ||= %r{test_bench/bootstrap\.rb}
|
100
114
|
|
101
115
|
omitting = false
|
102
116
|
|
103
|
-
|
117
|
+
Output.write("\e[1mTraceback\e[22m (most recent call last):", sgr_code: 0x31)
|
118
|
+
|
119
|
+
rjust_length = error.backtrace.length.to_s.length
|
120
|
+
|
121
|
+
error.backtrace[1..-1].reverse_each.with_index do |line, index|
|
122
|
+
line = line.dup
|
104
123
|
|
105
|
-
error_message.each_line.with_index do |line, index|
|
106
124
|
line.chomp!
|
107
125
|
|
108
|
-
if
|
126
|
+
if omit_backtrace_pattern.match?(line)
|
109
127
|
if omitting
|
110
128
|
next
|
111
129
|
else
|
112
130
|
omitting = true
|
113
131
|
|
114
|
-
|
115
|
-
|
116
|
-
line.slice!(indentation..-1)
|
117
|
-
line.gsub!(%r{[[:digit:]]}, '?')
|
118
|
-
line.concat("*omitted*")
|
132
|
+
header = index.to_s.gsub(/./, '?').rjust(rjust_length, ' ')
|
119
133
|
|
120
|
-
Output.write(
|
134
|
+
Output.write("#{header}: *omitted*", sgr_codes: [0x2, 0x3, 0x31], tab_indent: true)
|
121
135
|
end
|
122
136
|
else
|
123
137
|
omitting = false
|
124
138
|
|
125
|
-
|
139
|
+
header = index.to_s.rjust(rjust_length, ' ')
|
140
|
+
|
141
|
+
Output.write("#{header}: #{line}", sgr_code: 0x31, tab_indent: true)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
if error.message.empty?
|
146
|
+
if error.instance_of?(RuntimeError)
|
147
|
+
Output.write("#{error.backtrace[0]}: \e[1;4munhandled exception\e[24;22m", sgr_code: 0x31)
|
148
|
+
return
|
126
149
|
end
|
150
|
+
|
151
|
+
error.message = error.class
|
127
152
|
end
|
153
|
+
|
154
|
+
Output.write("#{error.backtrace[0]} \e[1m#{error} (\e[4m#{error.class}\e[24m)\e[22m", sgr_code: 0x31)
|
128
155
|
end
|
129
156
|
end
|
130
157
|
|
131
158
|
module Output
|
132
159
|
extend self
|
133
160
|
|
134
|
-
def write(text, device: nil, sgr_code: nil, sgr_codes: nil)
|
135
|
-
indent(text, device: device, sgr_code: sgr_code, sgr_codes: sgr_codes)
|
161
|
+
def write(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil)
|
162
|
+
indent(text, device: device, sgr_code: sgr_code, sgr_codes: sgr_codes, tab_indent: tab_indent)
|
136
163
|
end
|
137
164
|
|
138
|
-
def indent(text, device: nil, sgr_code: nil, sgr_codes: nil, &block)
|
165
|
+
def indent(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil, &block)
|
139
166
|
device ||= $stdout
|
140
167
|
|
141
168
|
unless text.nil?
|
142
169
|
sgr_codes = Array(sgr_codes)
|
170
|
+
|
143
171
|
unless sgr_code.nil?
|
144
172
|
sgr_codes << sgr_code
|
145
173
|
end
|
146
174
|
|
175
|
+
sgr_codes.compact!
|
176
|
+
|
147
177
|
unless sgr_codes.empty?
|
148
178
|
sgr_codes.map! do |sgr_code|
|
149
179
|
sgr_code.to_s(16)
|
150
180
|
end
|
151
181
|
|
152
|
-
text = "\e[#{sgr_codes
|
182
|
+
text = "\e[#{sgr_codes.join(';')}m#{text}\e[0m"
|
153
183
|
end
|
154
184
|
|
155
|
-
text = "#{' ' * indentation}#{text}"
|
185
|
+
text = "#{"\t" if tab_indent}#{' ' * indentation}#{text}"
|
156
186
|
|
157
187
|
device.puts(text)
|
158
188
|
end
|
159
189
|
|
160
190
|
return if block.nil?
|
161
191
|
|
162
|
-
self.indentation += 1
|
192
|
+
self.indentation += 1 unless text.nil?
|
163
193
|
|
164
194
|
begin
|
165
195
|
block.()
|
166
196
|
ensure
|
167
|
-
self.indentation -= 1
|
197
|
+
self.indentation -= 1 unless text.nil?
|
168
198
|
end
|
169
199
|
end
|
170
200
|
|
@@ -176,10 +206,10 @@ module TestBench
|
|
176
206
|
|
177
207
|
class AssertionFailure < RuntimeError
|
178
208
|
def self.build(caller_location=nil)
|
179
|
-
caller_location ||=
|
209
|
+
caller_location ||= caller(0)
|
180
210
|
|
181
211
|
instance = new
|
182
|
-
instance.set_backtrace([caller_location
|
212
|
+
instance.set_backtrace([caller_location])
|
183
213
|
instance
|
184
214
|
end
|
185
215
|
|
@@ -190,7 +220,7 @@ module TestBench
|
|
190
220
|
|
191
221
|
class Failure < SystemExit
|
192
222
|
def self.build
|
193
|
-
new(
|
223
|
+
new(1, "TestBench::Bootstrap is aborting")
|
194
224
|
end
|
195
225
|
end
|
196
226
|
|
@@ -202,7 +232,9 @@ module TestBench
|
|
202
232
|
exclude_file_pattern ||= %r{automated_init\.rb}
|
203
233
|
|
204
234
|
if argv.empty?
|
205
|
-
|
235
|
+
tests_dir = ENV['TEST_BENCH_TESTS_DIR'] || 'test/automated'
|
236
|
+
|
237
|
+
file_patterns = [File.join(tests_dir, '**', '*.rb')]
|
206
238
|
else
|
207
239
|
file_patterns = argv
|
208
240
|
end
|
@@ -212,7 +244,7 @@ module TestBench
|
|
212
244
|
file_pattern = File.join(file_pattern, '**/*.rb')
|
213
245
|
end
|
214
246
|
|
215
|
-
files = Dir
|
247
|
+
files = Dir.glob(file_pattern).reject do |file|
|
216
248
|
File.basename(file).match?(exclude_file_pattern)
|
217
249
|
end
|
218
250
|
|
@@ -229,6 +261,4 @@ module TestBench
|
|
229
261
|
end
|
230
262
|
end
|
231
263
|
end
|
232
|
-
|
233
|
-
Bootstrap.activate
|
234
264
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test_bench-bootstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Ladd
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description:
|
14
14
|
email: nathanladd+github@gmail.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
@@ -21,7 +21,7 @@ homepage: https://github.com/test-bench/test-bench-bootstrap
|
|
21
21
|
licenses:
|
22
22
|
- MIT
|
23
23
|
metadata: {}
|
24
|
-
post_install_message:
|
24
|
+
post_install_message:
|
25
25
|
rdoc_options: []
|
26
26
|
require_paths:
|
27
27
|
- lib
|
@@ -36,8 +36,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
38
|
requirements: []
|
39
|
-
rubygems_version: 3.
|
40
|
-
signing_key:
|
39
|
+
rubygems_version: 3.1.4
|
40
|
+
signing_key:
|
41
41
|
specification_version: 4
|
42
42
|
summary: A minimal test framework for testing TestBench
|
43
43
|
test_files: []
|