test_bench-bootstrap 2.1.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/test_bench/bootstrap.rb +186 -74
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4e2e358c29830ece30c5a9516c4cf96fe2d6748cb1a3c88e9d3d05727c66f9a
|
4
|
+
data.tar.gz: d07c4e27d9c6440427ff716ff8fe6cf405940287417c5f0f69e90560d6c140da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 787ba756e146d4b72a0a7dd265df1baa3c4ddab27bf78e3e0d271dd1b333a7006e1e486b0369c9727ffed7bf15adb9e150fe8a13b7f743b2833a0b78ee9cf881
|
7
|
+
data.tar.gz: faf41a1355cf5cc3a20cc46aa25cd1e1b62b4bb69da66ef25bc20b2efdacabdfe6d0f736908120f6ecab24f7b011d4ecee36bfa94ce78d0271da878260023681
|
data/lib/test_bench/bootstrap.rb
CHANGED
@@ -4,15 +4,94 @@ module TestBench
|
|
4
4
|
Object.include(Fixture)
|
5
5
|
end
|
6
6
|
|
7
|
+
if RUBY_ENGINE != 'mruby'
|
8
|
+
class Abort < SystemExit
|
9
|
+
def self.build
|
10
|
+
new(1)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Abort
|
16
|
+
def self.call
|
17
|
+
Output.raw_write("#{Bootstrap} is aborting\n")
|
18
|
+
instance = build
|
19
|
+
raise instance
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Backtrace
|
24
|
+
if RUBY_ENGINE != 'mruby'
|
25
|
+
def self.frame(frame_index)
|
26
|
+
frame_index += 1
|
27
|
+
|
28
|
+
caller[frame_index]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class AssertionFailure < RuntimeError
|
34
|
+
def self.build(frame_index=nil)
|
35
|
+
frame_index ||= 0
|
36
|
+
|
37
|
+
frame = Backtrace.frame(frame_index)
|
38
|
+
|
39
|
+
instance = new
|
40
|
+
instance.set_backtrace([frame])
|
41
|
+
instance
|
42
|
+
end
|
43
|
+
|
44
|
+
def message
|
45
|
+
"Assertion failed"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module Path
|
50
|
+
if RUBY_ENGINE != 'mruby'
|
51
|
+
def self.match?(pattern, string)
|
52
|
+
::File.fnmatch?(pattern, string)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.search(path, include_pattern=nil, exclude_pattern=nil)
|
56
|
+
files = []
|
57
|
+
|
58
|
+
if ::File.directory?(path)
|
59
|
+
search_directory(path, files, include_pattern, exclude_pattern)
|
60
|
+
elsif ::File.exist?(path)
|
61
|
+
files << path
|
62
|
+
else
|
63
|
+
raise LoadError, "no such file or directory -- #{path}"
|
64
|
+
end
|
65
|
+
|
66
|
+
files
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.search_directory(dir, files, include_pattern=nil, exclude_pattern=nil)
|
70
|
+
include_pattern ||= '*.rb'
|
71
|
+
|
72
|
+
::Dir[::File.join(dir, '**', '*')].each do |path|
|
73
|
+
next if ::File.directory?(path)
|
74
|
+
|
75
|
+
if match?(include_pattern, path)
|
76
|
+
if exclude_pattern.nil? || !match?(exclude_pattern, path)
|
77
|
+
files << path
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
7
85
|
module Fixture
|
8
86
|
def assert(value)
|
9
87
|
unless value
|
10
|
-
raise AssertionFailure.build(
|
88
|
+
raise AssertionFailure.build(1)
|
11
89
|
end
|
12
90
|
end
|
13
91
|
|
14
92
|
def assert_raises(error_class=nil, &block)
|
15
93
|
begin
|
94
|
+
Output.raw_write("assert_raises\n")
|
16
95
|
block.()
|
17
96
|
|
18
97
|
rescue (error_class || StandardError) => error
|
@@ -25,12 +104,12 @@ module TestBench
|
|
25
104
|
end
|
26
105
|
end
|
27
106
|
|
28
|
-
raise AssertionFailure.build(
|
107
|
+
raise AssertionFailure.build(1)
|
29
108
|
end
|
30
109
|
|
31
110
|
def refute(value)
|
32
111
|
if value
|
33
|
-
raise AssertionFailure.build(
|
112
|
+
raise AssertionFailure.build(1)
|
34
113
|
end
|
35
114
|
end
|
36
115
|
|
@@ -42,7 +121,7 @@ module TestBench
|
|
42
121
|
raise error
|
43
122
|
end
|
44
123
|
|
45
|
-
raise AssertionFailure.build(
|
124
|
+
raise AssertionFailure.build(1)
|
46
125
|
end
|
47
126
|
|
48
127
|
def context(prose=nil, &block)
|
@@ -62,9 +141,9 @@ module TestBench
|
|
62
141
|
block.()
|
63
142
|
|
64
143
|
rescue => error
|
65
|
-
|
144
|
+
Output.error(error)
|
66
145
|
|
67
|
-
|
146
|
+
Abort.()
|
68
147
|
end
|
69
148
|
end
|
70
149
|
|
@@ -85,10 +164,10 @@ module TestBench
|
|
85
164
|
|
86
165
|
rescue => error
|
87
166
|
Output.indent(prose, sgr_codes: [0x1, 0x31]) do
|
88
|
-
|
167
|
+
Output.error(error)
|
89
168
|
end
|
90
169
|
|
91
|
-
|
170
|
+
Abort.()
|
92
171
|
end
|
93
172
|
end
|
94
173
|
|
@@ -100,6 +179,10 @@ module TestBench
|
|
100
179
|
Output.write(text)
|
101
180
|
end
|
102
181
|
|
182
|
+
def detail(text)
|
183
|
+
comment(text)
|
184
|
+
end
|
185
|
+
|
103
186
|
def fixture(cls, *args, **kwargs, &block)
|
104
187
|
fixture = TestBench::Fixture.(cls, *args, **kwargs, &block)
|
105
188
|
|
@@ -107,66 +190,79 @@ module TestBench
|
|
107
190
|
|
108
191
|
assert(passed)
|
109
192
|
end
|
193
|
+
end
|
194
|
+
|
195
|
+
module Output
|
196
|
+
extend self
|
197
|
+
|
198
|
+
def write(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil)
|
199
|
+
indent(text, device: device, sgr_code: sgr_code, sgr_codes: sgr_codes, tab_indent: tab_indent)
|
200
|
+
end
|
110
201
|
|
111
|
-
def
|
112
|
-
omit_backtrace_pattern =
|
113
|
-
omit_backtrace_pattern ||= %r{test_bench/bootstrap\.rb}
|
202
|
+
def error(error)
|
203
|
+
omit_backtrace_pattern = Defaults.omit_backtrace_pattern
|
114
204
|
|
115
205
|
omitting = false
|
116
206
|
|
117
|
-
|
207
|
+
write("\e[1mTraceback\e[22m (most recent call last):", sgr_code: 0x31)
|
118
208
|
|
119
209
|
rjust_length = error.backtrace.length.to_s.length
|
120
210
|
|
121
|
-
error.backtrace[1..-1].
|
122
|
-
line = line.dup
|
211
|
+
reverse_backtrace = error.backtrace[1..-1].reverse
|
123
212
|
|
124
|
-
|
213
|
+
reverse_backtrace.each_with_index do |frame, index|
|
214
|
+
frame = frame.dup
|
215
|
+
frame.chomp!
|
125
216
|
|
126
|
-
|
217
|
+
previous_frame = frame
|
218
|
+
|
219
|
+
file, _ = frame.split(':', 2)
|
220
|
+
|
221
|
+
line = ' ' * rjust_length
|
222
|
+
|
223
|
+
index_text = index.to_s
|
224
|
+
index_range = (-index_text.length..-1)
|
225
|
+
|
226
|
+
if Path.match?(omit_backtrace_pattern, file)
|
127
227
|
if omitting
|
128
228
|
next
|
129
229
|
else
|
130
230
|
omitting = true
|
131
231
|
|
132
|
-
|
232
|
+
line[index_range] = '?' * index_text.length
|
233
|
+
line += ": *omitted*"
|
133
234
|
|
134
|
-
|
235
|
+
write(line, sgr_codes: [0x2, 0x3, 0x31], tab_indent: true)
|
135
236
|
end
|
136
237
|
else
|
137
238
|
omitting = false
|
138
239
|
|
139
|
-
|
240
|
+
line[index_range] = index_text
|
241
|
+
line += ": #{frame}"
|
140
242
|
|
141
|
-
|
243
|
+
write(line, sgr_code: 0x31, tab_indent: true)
|
142
244
|
end
|
143
245
|
end
|
144
246
|
|
145
247
|
if error.message.empty?
|
146
248
|
if error.instance_of?(RuntimeError)
|
147
|
-
|
249
|
+
write("#{error.backtrace[0]}: \e[1;4munhandled exception\e[24;22m", sgr_code: 0x31)
|
148
250
|
return
|
149
251
|
end
|
150
252
|
|
151
253
|
error.message = error.class
|
152
254
|
end
|
153
255
|
|
154
|
-
|
256
|
+
write("#{error.backtrace[0]}: \e[1m#{error} (\e[4m#{error.class}\e[24m)\e[22m", sgr_code: 0x31)
|
155
257
|
end
|
156
|
-
end
|
157
258
|
|
158
|
-
|
159
|
-
|
160
|
-
|
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)
|
259
|
+
def newline
|
260
|
+
write('')
|
163
261
|
end
|
164
262
|
|
165
263
|
def indent(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil, &block)
|
166
|
-
device ||= $stdout
|
167
|
-
|
168
264
|
unless text.nil?
|
169
|
-
sgr_codes
|
265
|
+
sgr_codes ||= []
|
170
266
|
unless sgr_code.nil?
|
171
267
|
sgr_codes << sgr_code
|
172
268
|
end
|
@@ -179,9 +275,9 @@ module TestBench
|
|
179
275
|
text = "\e[#{sgr_codes.join(';')}m#{text}\e[0m"
|
180
276
|
end
|
181
277
|
|
182
|
-
text = "#{"\t" if tab_indent}#{' ' * indentation}#{text}"
|
278
|
+
text = "#{"\t" if tab_indent}#{' ' * indentation}#{text}\n"
|
183
279
|
|
184
|
-
|
280
|
+
raw_write(text, device)
|
185
281
|
end
|
186
282
|
|
187
283
|
return if block.nil?
|
@@ -195,67 +291,83 @@ module TestBench
|
|
195
291
|
end
|
196
292
|
end
|
197
293
|
|
198
|
-
def
|
199
|
-
|
200
|
-
end
|
201
|
-
attr_writer :indentation
|
202
|
-
end
|
294
|
+
def raw_write(text, device=nil)
|
295
|
+
device ||= self.device
|
203
296
|
|
204
|
-
|
205
|
-
def self.build(caller_location=nil)
|
206
|
-
caller_location ||= caller(0)
|
207
|
-
|
208
|
-
instance = new
|
209
|
-
instance.set_backtrace([caller_location])
|
210
|
-
instance
|
297
|
+
device.write(text)
|
211
298
|
end
|
212
299
|
|
213
|
-
def
|
214
|
-
|
300
|
+
def indentation
|
301
|
+
@indentation ||= 0
|
215
302
|
end
|
216
|
-
|
303
|
+
attr_writer :indentation
|
217
304
|
|
218
|
-
|
219
|
-
|
220
|
-
new(1, "TestBench::Bootstrap is aborting")
|
305
|
+
def device
|
306
|
+
@device ||= Defaults.output_device
|
221
307
|
end
|
222
308
|
end
|
223
309
|
|
224
310
|
module Run
|
225
|
-
def self.call(
|
226
|
-
|
227
|
-
|
228
|
-
exclude_file_pattern = ENV['TEST_BENCH_EXCLUDE_FILE_PATTERN']
|
229
|
-
exclude_file_pattern ||= %r{automated_init\.rb}
|
311
|
+
def self.call(paths=nil, exclude_pattern: nil)
|
312
|
+
paths ||= []
|
313
|
+
exclude_pattern ||= Defaults.exclude_file_pattern
|
230
314
|
|
231
|
-
if
|
232
|
-
|
233
|
-
|
234
|
-
file_patterns = [File.join(tests_dir, '**', '*.rb')]
|
235
|
-
else
|
236
|
-
file_patterns = argv
|
315
|
+
if paths.is_a?(String)
|
316
|
+
paths = [paths]
|
237
317
|
end
|
238
318
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
end
|
243
|
-
|
244
|
-
files = Dir.glob(file_pattern).reject do |file|
|
245
|
-
File.basename(file).match?(exclude_file_pattern)
|
246
|
-
end
|
319
|
+
if paths.empty?
|
320
|
+
paths << Defaults.tests_dir
|
321
|
+
end
|
247
322
|
|
248
|
-
|
249
|
-
|
323
|
+
paths.each do |path|
|
324
|
+
Path.search(path, '*.rb', exclude_pattern).each do |file|
|
325
|
+
Output.write "Running #{file}"
|
250
326
|
|
251
327
|
begin
|
252
|
-
load
|
328
|
+
load(file)
|
253
329
|
ensure
|
254
|
-
|
330
|
+
Output.newline
|
255
331
|
end
|
256
332
|
end
|
257
333
|
end
|
258
334
|
end
|
259
335
|
end
|
336
|
+
|
337
|
+
module Defaults
|
338
|
+
def self.get(env_var, default)
|
339
|
+
if env.key?(env_var)
|
340
|
+
env[env_var]
|
341
|
+
else
|
342
|
+
default
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
def self.exclude_file_pattern
|
347
|
+
get('TEST_BENCH_EXCLUDE_FILE_PATTERN', '*_init.rb')
|
348
|
+
end
|
349
|
+
|
350
|
+
def self.omit_backtrace_pattern
|
351
|
+
get('TEST_BENCH_OMIT_BACKTRACE_PATTERN', '*/test_bench/bootstrap.rb')
|
352
|
+
end
|
353
|
+
|
354
|
+
def self.tests_dir
|
355
|
+
get('TEST_BENCH_TESTS_DIRECTORY', 'test/automated')
|
356
|
+
end
|
357
|
+
|
358
|
+
if RUBY_ENGINE == 'mruby'
|
359
|
+
def self.env
|
360
|
+
{}
|
361
|
+
end
|
362
|
+
else
|
363
|
+
def self.output_device
|
364
|
+
$stdout
|
365
|
+
end
|
366
|
+
|
367
|
+
def self.env
|
368
|
+
::ENV
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
260
372
|
end
|
261
373
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test_bench-bootstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Ladd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: nathanladd+github@gmail.com
|
@@ -36,7 +36,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
38
|
requirements: []
|
39
|
-
rubygems_version: 3.
|
39
|
+
rubygems_version: 3.3.4
|
40
40
|
signing_key:
|
41
41
|
specification_version: 4
|
42
42
|
summary: A minimal test framework for testing TestBench
|