test_bench-bootstrap 2.1.2 → 4.0.0
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 +137 -108
- 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: dc965093b2dc0c70333aafb0c18143768a68ab13217930d7860a5e613920622d
|
4
|
+
data.tar.gz: d949906c02222df28b64b59cfc2e66e77104c673084ab65b0041ecf37772e524
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce599074b28ff8ec821a3e7b1e2cf613c487730bb030975bb0e1bd6ccea4328fd70a65adc7cef80b81366254479d8368e196926035fee0f8434a85eaad0868d7
|
7
|
+
data.tar.gz: c20d7770dddc587baa8dd5608aa4469cd69a8512c61586f95d9dbea49c6817cb9347221f0e81a0c9bbd91a81e6fcde04a1132dbd12291e9969fcea21c830a01d
|
data/lib/test_bench/bootstrap.rb
CHANGED
@@ -4,10 +4,72 @@ module TestBench
|
|
4
4
|
Object.include(Fixture)
|
5
5
|
end
|
6
6
|
|
7
|
+
module Backtrace
|
8
|
+
if RUBY_ENGINE != 'mruby'
|
9
|
+
def self.frame(frame_index)
|
10
|
+
frame_index += 1
|
11
|
+
|
12
|
+
caller[frame_index]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class AssertionFailure < RuntimeError
|
18
|
+
def self.build(frame_index=nil)
|
19
|
+
frame_index ||= 0
|
20
|
+
|
21
|
+
frame = Backtrace.frame(frame_index)
|
22
|
+
|
23
|
+
instance = new
|
24
|
+
instance.set_backtrace([frame])
|
25
|
+
instance
|
26
|
+
end
|
27
|
+
|
28
|
+
def message
|
29
|
+
"Assertion failed"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module Path
|
34
|
+
if RUBY_ENGINE != 'mruby'
|
35
|
+
def self.match?(pattern, string)
|
36
|
+
::File.fnmatch?(pattern, string)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.search(path, include_pattern=nil, exclude_pattern=nil)
|
40
|
+
files = []
|
41
|
+
|
42
|
+
if ::File.directory?(path)
|
43
|
+
search_directory(path, files, include_pattern, exclude_pattern)
|
44
|
+
elsif ::File.exist?(path)
|
45
|
+
files << path
|
46
|
+
else
|
47
|
+
raise LoadError, "no such file or directory -- #{path}"
|
48
|
+
end
|
49
|
+
|
50
|
+
files
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.search_directory(dir, files, include_pattern=nil, exclude_pattern=nil)
|
54
|
+
include_pattern ||= '*.rb'
|
55
|
+
|
56
|
+
::Dir[::File.join(dir, '**', '*')].each do |path|
|
57
|
+
next if ::File.directory?(path)
|
58
|
+
|
59
|
+
if match?(include_pattern, path)
|
60
|
+
if exclude_pattern.nil? || !match?(exclude_pattern, path)
|
61
|
+
files << path
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
7
69
|
module Fixture
|
8
70
|
def assert(value)
|
9
71
|
unless value
|
10
|
-
raise AssertionFailure.build(
|
72
|
+
raise AssertionFailure.build(1)
|
11
73
|
end
|
12
74
|
end
|
13
75
|
|
@@ -25,12 +87,12 @@ module TestBench
|
|
25
87
|
end
|
26
88
|
end
|
27
89
|
|
28
|
-
raise AssertionFailure.build(
|
90
|
+
raise AssertionFailure.build(1)
|
29
91
|
end
|
30
92
|
|
31
93
|
def refute(value)
|
32
94
|
if value
|
33
|
-
raise AssertionFailure.build(
|
95
|
+
raise AssertionFailure.build(1)
|
34
96
|
end
|
35
97
|
end
|
36
98
|
|
@@ -42,7 +104,7 @@ module TestBench
|
|
42
104
|
raise error
|
43
105
|
end
|
44
106
|
|
45
|
-
raise AssertionFailure.build(
|
107
|
+
raise AssertionFailure.build(1)
|
46
108
|
end
|
47
109
|
|
48
110
|
def context(prose=nil, &block)
|
@@ -58,14 +120,7 @@ module TestBench
|
|
58
120
|
return
|
59
121
|
end
|
60
122
|
|
61
|
-
|
62
|
-
block.()
|
63
|
-
|
64
|
-
rescue => error
|
65
|
-
Fixture.print_error(error)
|
66
|
-
|
67
|
-
raise Failure.build
|
68
|
-
end
|
123
|
+
block.()
|
69
124
|
end
|
70
125
|
|
71
126
|
def _context(prose=nil, &block)
|
@@ -84,11 +139,9 @@ module TestBench
|
|
84
139
|
Output.indent(prose, sgr_code: 0x32)
|
85
140
|
|
86
141
|
rescue => error
|
87
|
-
Output.indent(prose, sgr_codes: [0x1, 0x31])
|
88
|
-
Fixture.print_error(error)
|
89
|
-
end
|
142
|
+
Output.indent(prose, sgr_codes: [0x1, 0x31])
|
90
143
|
|
91
|
-
raise
|
144
|
+
raise error
|
92
145
|
end
|
93
146
|
end
|
94
147
|
|
@@ -100,6 +153,10 @@ module TestBench
|
|
100
153
|
Output.write(text)
|
101
154
|
end
|
102
155
|
|
156
|
+
def detail(text)
|
157
|
+
comment(text)
|
158
|
+
end
|
159
|
+
|
103
160
|
def fixture(cls, *args, **kwargs, &block)
|
104
161
|
fixture = TestBench::Fixture.(cls, *args, **kwargs, &block)
|
105
162
|
|
@@ -107,52 +164,6 @@ module TestBench
|
|
107
164
|
|
108
165
|
assert(passed)
|
109
166
|
end
|
110
|
-
|
111
|
-
def self.print_error(error)
|
112
|
-
omit_backtrace_pattern = ENV['TEST_BENCH_OMIT_BACKTRACE_PATTERN']
|
113
|
-
omit_backtrace_pattern ||= %r{test_bench/bootstrap\.rb}
|
114
|
-
|
115
|
-
omitting = false
|
116
|
-
|
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
|
123
|
-
|
124
|
-
line.chomp!
|
125
|
-
|
126
|
-
if omit_backtrace_pattern.match?(line)
|
127
|
-
if omitting
|
128
|
-
next
|
129
|
-
else
|
130
|
-
omitting = true
|
131
|
-
|
132
|
-
header = index.to_s.gsub(/./, '?').rjust(rjust_length, ' ')
|
133
|
-
|
134
|
-
Output.write("#{header}: *omitted*", sgr_codes: [0x2, 0x3, 0x31], tab_indent: true)
|
135
|
-
end
|
136
|
-
else
|
137
|
-
omitting = false
|
138
|
-
|
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
|
149
|
-
end
|
150
|
-
|
151
|
-
error.message = error.class
|
152
|
-
end
|
153
|
-
|
154
|
-
Output.write("#{error.backtrace[0]} \e[1m#{error} (\e[4m#{error.class}\e[24m)\e[22m", sgr_code: 0x31)
|
155
|
-
end
|
156
167
|
end
|
157
168
|
|
158
169
|
module Output
|
@@ -162,11 +173,13 @@ module TestBench
|
|
162
173
|
indent(text, device: device, sgr_code: sgr_code, sgr_codes: sgr_codes, tab_indent: tab_indent)
|
163
174
|
end
|
164
175
|
|
165
|
-
def
|
166
|
-
|
176
|
+
def newline
|
177
|
+
write('')
|
178
|
+
end
|
167
179
|
|
180
|
+
def indent(text, device: nil, sgr_code: nil, sgr_codes: nil, tab_indent: nil, &block)
|
168
181
|
unless text.nil?
|
169
|
-
sgr_codes
|
182
|
+
sgr_codes ||= []
|
170
183
|
unless sgr_code.nil?
|
171
184
|
sgr_codes << sgr_code
|
172
185
|
end
|
@@ -179,9 +192,9 @@ module TestBench
|
|
179
192
|
text = "\e[#{sgr_codes.join(';')}m#{text}\e[0m"
|
180
193
|
end
|
181
194
|
|
182
|
-
text = "#{"\t" if tab_indent}#{' ' * indentation}#{text}"
|
195
|
+
text = "#{"\t" if tab_indent}#{' ' * indentation}#{text}\n"
|
183
196
|
|
184
|
-
|
197
|
+
raw_write(text, device)
|
185
198
|
end
|
186
199
|
|
187
200
|
return if block.nil?
|
@@ -195,67 +208,83 @@ module TestBench
|
|
195
208
|
end
|
196
209
|
end
|
197
210
|
|
198
|
-
def
|
199
|
-
|
200
|
-
end
|
201
|
-
attr_writer :indentation
|
202
|
-
end
|
211
|
+
def raw_write(text, device=nil)
|
212
|
+
device ||= self.device
|
203
213
|
|
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
|
214
|
+
device.write(text)
|
211
215
|
end
|
212
216
|
|
213
|
-
def
|
214
|
-
|
217
|
+
def indentation
|
218
|
+
@indentation ||= 0
|
215
219
|
end
|
216
|
-
|
220
|
+
attr_writer :indentation
|
217
221
|
|
218
|
-
|
219
|
-
|
220
|
-
new(1, "TestBench::Bootstrap is aborting")
|
222
|
+
def device
|
223
|
+
@device ||= Defaults.output_device
|
221
224
|
end
|
222
225
|
end
|
223
226
|
|
224
227
|
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}
|
228
|
+
def self.call(paths=nil, exclude_pattern: nil)
|
229
|
+
paths ||= []
|
230
|
+
exclude_pattern ||= Defaults.exclude_file_pattern
|
230
231
|
|
231
|
-
if
|
232
|
-
|
233
|
-
|
234
|
-
file_patterns = [File.join(tests_dir, '**', '*.rb')]
|
235
|
-
else
|
236
|
-
file_patterns = argv
|
232
|
+
if paths.is_a?(String)
|
233
|
+
paths = [paths]
|
237
234
|
end
|
238
235
|
|
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
|
236
|
+
if paths.empty?
|
237
|
+
paths << Defaults.tests_dir
|
238
|
+
end
|
247
239
|
|
248
|
-
|
249
|
-
|
240
|
+
paths.each do |path|
|
241
|
+
Path.search(path, '*.rb', exclude_pattern).each do |file|
|
242
|
+
Output.write "Running #{file}"
|
250
243
|
|
251
244
|
begin
|
252
|
-
load
|
245
|
+
load(file)
|
253
246
|
ensure
|
254
|
-
|
247
|
+
Output.newline
|
255
248
|
end
|
256
249
|
end
|
257
250
|
end
|
258
251
|
end
|
259
252
|
end
|
253
|
+
|
254
|
+
module Defaults
|
255
|
+
def self.get(env_var, default)
|
256
|
+
if env.key?(env_var)
|
257
|
+
env[env_var]
|
258
|
+
else
|
259
|
+
default
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def self.exclude_file_pattern
|
264
|
+
get('TEST_BENCH_EXCLUDE_FILE_PATTERN', '*_init.rb')
|
265
|
+
end
|
266
|
+
|
267
|
+
def self.omit_backtrace_pattern
|
268
|
+
get('TEST_BENCH_OMIT_BACKTRACE_PATTERN', '*/test_bench/bootstrap.rb')
|
269
|
+
end
|
270
|
+
|
271
|
+
def self.tests_dir
|
272
|
+
get('TEST_BENCH_TESTS_DIRECTORY', 'test/automated')
|
273
|
+
end
|
274
|
+
|
275
|
+
if RUBY_ENGINE == 'mruby'
|
276
|
+
def self.env
|
277
|
+
{}
|
278
|
+
end
|
279
|
+
else
|
280
|
+
def self.output_device
|
281
|
+
$stdout
|
282
|
+
end
|
283
|
+
|
284
|
+
def self.env
|
285
|
+
::ENV
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
260
289
|
end
|
261
290
|
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: 4.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-09-16 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
|