test_bench-bootstrap 0.0.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/test_bench/bootstrap.rb +65 -35
  3. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 978ac1932ff9bd26c3df5224a36601e8c0904a86373cb0afce012719c304061a
4
- data.tar.gz: 6f2d19a75d8ba1e3b24682768df85a29472a69d10312eb678739ba06df403d51
3
+ metadata.gz: 04226ba70367c28b48c2c29d0691ffd31949b08017a342fb8f32c6e841a2d44c
4
+ data.tar.gz: 40d1d80234fa5b2fefb05e26335aa4ce85483e2995696fa319e563db32e1d4f3
5
5
  SHA512:
6
- metadata.gz: e80f1d090729ae650faac76d433e9d8aa7e7812a8da986593944b1797fbdaf97dd62def14b1326ed1aff098d0113a67991d6a49d48afc232c051a813e88f01d9
7
- data.tar.gz: d571f23a5dbed980a37788c157d2673b7c7abe697f2c64a7ff9597e772f48a8dd4c9a47d89221c49f03120dd6cea0b7b3fb67a6d9a246e1456b17172292f6b00
6
+ metadata.gz: c0fb1e8d99ad10a5085610837ae9ef987ded7d517692cd1d6ab854e5a6ff2c7f502ee39f5d6965fc7f036550bf07a8d0968d3836ee89ad2abab5b34ef2a9c892
7
+ data.tar.gz: 737d057fe58581cd3aa7f6b23872df01e26594f75eec2b306b9b47220c390a93d43019f4e1c30eceeb021e5be03780624c640f27bd65ec60ebdb84a68c6420f8
@@ -1,15 +1,13 @@
1
1
  module TestBench
2
2
  module Bootstrap
3
- def self.activate(receiver=nil)
4
- receiver ||= TOPLEVEL_BINDING.receiver
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(caller_locations.first)
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(caller_locations.first)
28
+ raise AssertionFailure.build(caller.first)
31
29
  end
32
30
 
33
31
  def refute(value)
34
32
  if value
35
- raise AssertionFailure.build(caller_locations.first)
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(caller_locations.first)
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{lib/test_bench/bootstrap\.rb}
113
+ omit_backtrace_pattern ||= %r{test_bench/bootstrap\.rb}
100
114
 
101
115
  omitting = false
102
116
 
103
- error_message = error.full_message(highlight: true, order: :bottom)
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 line.start_with?("\t") && omit_backtrace_pattern.match?(line)
126
+ if omit_backtrace_pattern.match?(line)
109
127
  if omitting
110
128
  next
111
129
  else
112
130
  omitting = true
113
131
 
114
- indentation = line.index("from ")
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(line, sgr_codes: [0x2, 0x3, 0x31])
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
- Output.write(line, sgr_code: 0x31)
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 * ';'}m#{text}\e[0m"
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 ||= caller_locations.first
209
+ caller_location ||= caller(0)
180
210
 
181
211
  instance = new
182
- instance.set_backtrace([caller_location.to_s])
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(false)
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
- file_patterns = ['test/automated/**/*.rb']
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[file_pattern].reject do |file|
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: 0.0.0
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: 2019-08-11 00:00:00.000000000 Z
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.0.1
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: []