power_assert 0.2.0 → 0.2.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/power_assert.rb +15 -8
- data/lib/power_assert/enable_tracepoint_events.rb +5 -0
- data/lib/power_assert/version.rb +1 -1
- data/test/test_power_assert.rb +108 -40
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61a285182186fe82f7d5e42eb9ce9942edfd11ba
|
4
|
+
data.tar.gz: f03a6ff069821625f498c48b359d41697d8278bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4a379fc1cc3569968450a0c37d32f48bd46524b31e5fa73988cd540e4a78f40dfb5297e0fbd14c4c77e5375340a9e033733d4689d2f0e23004af96d2adc78a7
|
7
|
+
data.tar.gz: 48a718d7da45368b3bf5363d6948efcbd29c6a748c29ba56f6f046e214ff728e20f9947434db9e7ac64276b420e7855eaf290f5f227e91f462888b26aad64257
|
data/lib/power_assert.rb
CHANGED
@@ -64,16 +64,22 @@ module PowerAssert
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def inspect
|
67
|
-
@value.inspect
|
68
|
-
|
69
|
-
|
67
|
+
inspect = @value.inspect
|
68
|
+
if Encoding.compatible?(Encoding.default_external, inspect)
|
69
|
+
inspect
|
70
|
+
else
|
71
|
+
begin
|
72
|
+
"#{inspect.encode(Encoding.default_external)}(#{inspect.encoding})"
|
73
|
+
rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
|
74
|
+
inspect.force_encoding(Encoding.default_external)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
rescue => e
|
78
|
+
"InspectionFailure: #{e.class}: #{e.message.each_line.first}"
|
70
79
|
end
|
71
80
|
end
|
72
81
|
private_constant :SafeInspectable
|
73
82
|
|
74
|
-
class InspectationFailure; end
|
75
|
-
private_constant :InspectationFailure
|
76
|
-
|
77
83
|
class Context
|
78
84
|
Value = Struct.new(:name, :value, :column)
|
79
85
|
Ident = Struct.new(:type, :name, :column)
|
@@ -151,7 +157,7 @@ module PowerAssert
|
|
151
157
|
if vals.empty?
|
152
158
|
return line
|
153
159
|
end
|
154
|
-
fmt = (vals[0].column
|
160
|
+
fmt = (0..vals[0].column).map {|i| vals.find {|v| v.column == i } ? "%<#{i}>s" : ' ' }.join
|
155
161
|
ret = []
|
156
162
|
ret << line.chomp
|
157
163
|
ret << sprintf(fmt, vals.each_with_object({}) {|v, h| h[v.column.to_s.to_sym] = '|' }).chomp
|
@@ -159,7 +165,8 @@ module PowerAssert
|
|
159
165
|
inspected_vals = vals.each_with_object({}) do |j, h|
|
160
166
|
h[j.column.to_s.to_sym] = [SafeInspectable.new(i.value).inspect, '|', ' '][i.column <=> j.column]
|
161
167
|
end
|
162
|
-
|
168
|
+
l = sprintf(fmt, inspected_vals)
|
169
|
+
ret << (l.valid_encoding? ? l.rstrip : l)
|
163
170
|
end
|
164
171
|
ret.join("\n")
|
165
172
|
end
|
data/lib/power_assert/version.rb
CHANGED
data/test/test_power_assert.rb
CHANGED
@@ -148,6 +148,38 @@ class TestPowerAssert < Test::Unit::TestCase
|
|
148
148
|
false
|
149
149
|
end
|
150
150
|
|
151
|
+
def test_lazy_inspection
|
152
|
+
PowerAssert.configure do |c|
|
153
|
+
assert !c.lazy_inspection
|
154
|
+
end
|
155
|
+
assert_equal <<END.chomp, assertion_message {
|
156
|
+
'a'.sub(/./, 'b').sub!(/./, 'c')
|
157
|
+
| |
|
158
|
+
| "c"
|
159
|
+
"b"
|
160
|
+
END
|
161
|
+
'a'.sub(/./, 'b').sub!(/./, 'c')
|
162
|
+
}
|
163
|
+
|
164
|
+
PowerAssert.configure do |c|
|
165
|
+
c.lazy_inspection = true
|
166
|
+
end
|
167
|
+
begin
|
168
|
+
assert_equal <<END.chomp, assertion_message {
|
169
|
+
'a'.sub(/./, 'b').sub!(/./, 'c')
|
170
|
+
| |
|
171
|
+
| "c"
|
172
|
+
"c"
|
173
|
+
END
|
174
|
+
'a'.sub(/./, 'b').sub!(/./, 'c')
|
175
|
+
}
|
176
|
+
ensure
|
177
|
+
PowerAssert.configure do |c|
|
178
|
+
c.lazy_inspection = false
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
151
183
|
def test_assertion_message
|
152
184
|
a = 0
|
153
185
|
@b = 1
|
@@ -266,14 +298,15 @@ END
|
|
266
298
|
}
|
267
299
|
|
268
300
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
301
|
+
a = :a
|
302
|
+
assert_equal <<END.chomp, assertion_message {
|
303
|
+
a == :b
|
304
|
+
| |
|
305
|
+
| false
|
306
|
+
:a
|
275
307
|
END
|
276
|
-
|
308
|
+
a == :b
|
309
|
+
}
|
277
310
|
|
278
311
|
|
279
312
|
if PowerAssert.respond_to?(:clear_global_method_cache, true)
|
@@ -289,9 +322,76 @@ END
|
|
289
322
|
}
|
290
323
|
end
|
291
324
|
end
|
325
|
+
end
|
326
|
+
|
327
|
+
def test_inspection_failure
|
328
|
+
assert_match Regexp.new(<<END.chomp.gsub('|', "\\|")),
|
329
|
+
assertion_message { BasicObjectSubclass.new.foo }
|
330
|
+
| | |
|
331
|
+
| | "foo"
|
332
|
+
| InspectionFailure: NoMethodError: .*
|
333
|
+
TestPowerAssert::BasicObjectSubclass
|
334
|
+
END
|
335
|
+
assertion_message { BasicObjectSubclass.new.foo }
|
292
336
|
|
293
337
|
|
294
|
-
|
338
|
+
verbose = $VERBOSE
|
339
|
+
default_external = Encoding.default_external
|
340
|
+
default_internal = Encoding.default_internal
|
341
|
+
begin
|
342
|
+
$VERBOSE = nil
|
343
|
+
Encoding.default_external = 'cp932'
|
344
|
+
Encoding.default_internal = 'utf-8'
|
345
|
+
ary = ["\u3042"]
|
346
|
+
assert_match Regexp.new(<<END.chomp), assertion_message {
|
347
|
+
ary.length
|
348
|
+
| |
|
349
|
+
| 1
|
350
|
+
InspectionFailure: Encoding::CompatibilityError: .*
|
351
|
+
END
|
352
|
+
ary.length
|
353
|
+
}
|
354
|
+
ensure
|
355
|
+
Encoding.default_internal = default_internal
|
356
|
+
Encoding.default_external = default_external
|
357
|
+
$VERBOSE = verbose
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
def test_assertion_message_with_incompatible_encodings
|
362
|
+
if Encoding.default_external == Encoding::UTF_8
|
363
|
+
a = "\u3042"
|
364
|
+
def a.inspect
|
365
|
+
super.encode('utf-16le')
|
366
|
+
end
|
367
|
+
assert_equal <<END.chomp, assertion_message {
|
368
|
+
a + a
|
369
|
+
| | |
|
370
|
+
| | "\u3042"(UTF-16LE)
|
371
|
+
| "\u3042\u3042"
|
372
|
+
"\u3042"(UTF-16LE)
|
373
|
+
END
|
374
|
+
a + a
|
375
|
+
}
|
376
|
+
end
|
377
|
+
|
378
|
+
|
379
|
+
a = "\xFF"
|
380
|
+
def a.inspect
|
381
|
+
"\xFF".force_encoding('ascii-8bit')
|
382
|
+
end
|
383
|
+
assert_equal <<END.chomp.b, assertion_message {
|
384
|
+
a.length
|
385
|
+
| |
|
386
|
+
| 1
|
387
|
+
\xFF
|
388
|
+
END
|
389
|
+
a.length
|
390
|
+
}.b
|
391
|
+
end
|
392
|
+
|
393
|
+
def test_assertion_message_with_string
|
394
|
+
a, = 0, a # suppress "assigned but unused variable" warning
|
295
395
|
@b = 1
|
296
396
|
@@c = 2
|
297
397
|
$d = 3
|
@@ -313,36 +413,4 @@ END
|
|
313
413
|
String(a) + String(@b) + String(@@c) + String($d)
|
314
414
|
END
|
315
415
|
end
|
316
|
-
|
317
|
-
def test_lazy_inspection
|
318
|
-
PowerAssert.configure do |c|
|
319
|
-
assert !c.lazy_inspection
|
320
|
-
end
|
321
|
-
assert_equal <<END.chomp, assertion_message {
|
322
|
-
'a'.sub(/./, 'b').sub!(/./, 'c')
|
323
|
-
| |
|
324
|
-
| "c"
|
325
|
-
"b"
|
326
|
-
END
|
327
|
-
'a'.sub(/./, 'b').sub!(/./, 'c')
|
328
|
-
}
|
329
|
-
|
330
|
-
PowerAssert.configure do |c|
|
331
|
-
c.lazy_inspection = true
|
332
|
-
end
|
333
|
-
begin
|
334
|
-
assert_equal <<END.chomp, assertion_message {
|
335
|
-
'a'.sub(/./, 'b').sub!(/./, 'c')
|
336
|
-
| |
|
337
|
-
| "c"
|
338
|
-
"c"
|
339
|
-
END
|
340
|
-
'a'.sub(/./, 'b').sub!(/./, 'c')
|
341
|
-
}
|
342
|
-
ensure
|
343
|
-
PowerAssert.configure do |c|
|
344
|
-
c.lazy_inspection = false
|
345
|
-
end
|
346
|
-
end
|
347
|
-
end
|
348
416
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: power_assert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuki Tsujimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
requirements: []
|
99
99
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.
|
100
|
+
rubygems_version: 2.2.2
|
101
101
|
signing_key:
|
102
102
|
specification_version: 4
|
103
103
|
summary: Power Assert for Ruby
|