power_assert 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/lib/power_assert.rb +4 -14
- data/lib/power_assert/configuration.rb +24 -0
- data/lib/power_assert/enable_tracepoint_events.rb +56 -52
- data/lib/power_assert/version.rb +1 -1
- data/test/test_power_assert.rb +6 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f750b892c57de72ef8565ce7b74f150d1cb58dd
|
4
|
+
data.tar.gz: 9512911b0c2a348b58015eabfc72c1f2bfd91922
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1e3d4320129a287703f80ffb480a42841adb66146a792f758d14539176b6c6694057efc3ecf24e420c7ed6dda1936806c36eb0a793ffad33761e510025c1de2
|
7
|
+
data.tar.gz: e006193bdbb8abc8f991b35ada079083f3f242effbdef3df2905535b874ac758d93834960d319c87640c9c76d333a77a4d31fc9c02fd8728965dbad4c5298d78
|
data/.travis.yml
CHANGED
data/lib/power_assert.rb
CHANGED
@@ -16,19 +16,12 @@ rescue
|
|
16
16
|
end
|
17
17
|
|
18
18
|
require 'power_assert/version'
|
19
|
+
require 'power_assert/configuration'
|
19
20
|
require 'power_assert/enable_tracepoint_events'
|
20
21
|
require 'ripper'
|
21
22
|
|
22
23
|
module PowerAssert
|
23
24
|
class << self
|
24
|
-
def configuration
|
25
|
-
@configuration ||= Configuration[false, false]
|
26
|
-
end
|
27
|
-
|
28
|
-
def configure
|
29
|
-
yield configuration
|
30
|
-
end
|
31
|
-
|
32
25
|
def start(assertion_proc_or_source, assertion_method: nil, source_binding: TOPLEVEL_BINDING)
|
33
26
|
if respond_to?(:clear_global_method_cache, true)
|
34
27
|
clear_global_method_cache
|
@@ -45,9 +38,6 @@ module PowerAssert
|
|
45
38
|
end
|
46
39
|
end
|
47
40
|
|
48
|
-
Configuration = Struct.new(:lazy_inspection, :_trace_alias_method)
|
49
|
-
private_constant :Configuration
|
50
|
-
|
51
41
|
module Empty
|
52
42
|
end
|
53
43
|
private_constant :Empty
|
@@ -132,9 +122,9 @@ module PowerAssert
|
|
132
122
|
end
|
133
123
|
trace_alias_method = PowerAssert.configuration._trace_alias_method
|
134
124
|
@trace = TracePoint.new(:return, :c_return) do |tp|
|
135
|
-
method_id =
|
136
|
-
|
137
|
-
|
125
|
+
method_id = SUPPORT_ALIAS_METHOD ? tp.callee_id :
|
126
|
+
trace_alias_method && tp.event == :return ? tp.binding.eval('::Kernel.__callee__') :
|
127
|
+
tp.method_id
|
138
128
|
next if method_ids and ! method_ids[method_id]
|
139
129
|
next if tp.event == :c_return and
|
140
130
|
not (lineno == tp.lineno and path == tp.path)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module PowerAssert
|
2
|
+
class << self
|
3
|
+
def configuration
|
4
|
+
@configuration ||= Configuration[false, false, true]
|
5
|
+
end
|
6
|
+
|
7
|
+
def configure
|
8
|
+
yield configuration
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
SUPPORT_ALIAS_METHOD = TracePoint.public_method_defined?(:callee_id)
|
13
|
+
private_constant :SUPPORT_ALIAS_METHOD
|
14
|
+
|
15
|
+
class Configuration < Struct.new(:lazy_inspection, :_trace_alias_method, :redefinition)
|
16
|
+
def _trace_alias_method=(bool)
|
17
|
+
super
|
18
|
+
if SUPPORT_ALIAS_METHOD
|
19
|
+
warn '_trace_alias_method option is obsolete. You no longer have to set it.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
private_constant :Configuration
|
24
|
+
end
|
@@ -1,78 +1,82 @@
|
|
1
|
+
require 'power_assert/configuration'
|
2
|
+
|
1
3
|
if defined? RubyVM
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
if PowerAssert.configuration.redefinition
|
5
|
+
verbose = $VERBOSE
|
6
|
+
begin
|
7
|
+
$VERBOSE = nil
|
8
|
+
module PowerAssert
|
9
|
+
# set redefined flag
|
10
|
+
basic_classes = [
|
11
|
+
Fixnum, Float, String, Array, Hash, Bignum, Symbol, Time, Regexp
|
12
|
+
]
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
basic_operators = [
|
15
|
+
:+, :-, :*, :/, :%, :==, :===, :<, :<=, :<<, :[], :[]=,
|
16
|
+
:length, :size, :empty?, :succ, :>, :>=, :!, :!=, :=~, :freeze
|
17
|
+
]
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
class Bug11182
|
20
|
+
def fixed?
|
21
|
+
true
|
22
|
+
end
|
19
23
|
end
|
20
|
-
|
21
|
-
private_constant :Bug11182
|
24
|
+
private_constant :Bug11182
|
22
25
|
|
23
|
-
|
24
|
-
|
26
|
+
refine Bug11182 do
|
27
|
+
def fixed?
|
28
|
+
end
|
25
29
|
end
|
26
|
-
end
|
27
30
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
class Bug11182Sub < Bug11182
|
32
|
+
alias _fixed? fixed?
|
33
|
+
protected :_fixed?
|
34
|
+
end
|
35
|
+
private_constant :Bug11182Sub
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
if (Bug11182.new.fixed? rescue false)
|
38
|
+
basic_classes.each do |klass|
|
39
|
+
basic_operators.each do |bop|
|
40
|
+
refine(klass) do
|
41
|
+
define_method(bop) {}
|
42
|
+
end
|
39
43
|
end
|
40
44
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
else
|
46
|
+
# workaround for https://bugs.ruby-lang.org/issues/11182
|
47
|
+
basic_classes.each do |klass|
|
48
|
+
basic_operators.each do |bop|
|
49
|
+
if klass.public_method_defined?(bop)
|
50
|
+
klass.ancestors.find {|i| i.instance_methods(false).index(bop) }.module_eval do
|
51
|
+
public bop
|
52
|
+
end
|
49
53
|
end
|
50
54
|
end
|
51
55
|
end
|
52
|
-
end
|
53
56
|
|
54
|
-
|
55
|
-
|
57
|
+
refine Symbol do
|
58
|
+
def ==
|
59
|
+
end
|
56
60
|
end
|
57
61
|
end
|
58
|
-
end
|
59
62
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
63
|
+
# bypass check_cfunc
|
64
|
+
refine BasicObject do
|
65
|
+
def !
|
66
|
+
end
|
64
67
|
|
65
|
-
|
68
|
+
def ==
|
69
|
+
end
|
66
70
|
end
|
67
|
-
end
|
68
71
|
|
69
|
-
|
70
|
-
|
72
|
+
refine Module do
|
73
|
+
def ==
|
74
|
+
end
|
71
75
|
end
|
72
76
|
end
|
77
|
+
ensure
|
78
|
+
$VERBOSE = verbose
|
73
79
|
end
|
74
|
-
ensure
|
75
|
-
$VERBOSE = verbose
|
76
80
|
end
|
77
81
|
|
78
82
|
# disable optimization
|
data/lib/power_assert/version.rb
CHANGED
data/test/test_power_assert.rb
CHANGED
@@ -394,7 +394,7 @@ END
|
|
394
394
|
begin
|
395
395
|
PowerAssert.configure do |c|
|
396
396
|
c._trace_alias_method = true
|
397
|
-
end
|
397
|
+
end unless PowerAssert.const_get(:SUPPORT_ALIAS_METHOD)
|
398
398
|
@o = Class.new do
|
399
399
|
def foo
|
400
400
|
:foo
|
@@ -406,7 +406,7 @@ END
|
|
406
406
|
ensure
|
407
407
|
PowerAssert.configure do |c|
|
408
408
|
c._trace_alias_method = false
|
409
|
-
end
|
409
|
+
end unless PowerAssert.const_get(:SUPPORT_ALIAS_METHOD)
|
410
410
|
end
|
411
411
|
end
|
412
412
|
|
@@ -422,11 +422,13 @@ END
|
|
422
422
|
end
|
423
423
|
|
424
424
|
t do
|
425
|
-
|
425
|
+
unless PowerAssert.const_get(:SUPPORT_ALIAS_METHOD)
|
426
|
+
omit 'alias of cfunc is not supported yet'
|
427
|
+
end
|
426
428
|
assert_match Regexp.new(<<END.chomp.gsub('|', "\\|")),
|
427
429
|
assertion_message { @o.new.alias_of_cfunc }
|
428
430
|
| | |
|
429
|
-
| | #<#<Class:.*>:.*>
|
431
|
+
| | "#<#<Class:.*>:.*>"
|
430
432
|
| #<#<Class:.*>:.*>
|
431
433
|
#<Class:.*>
|
432
434
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuki Tsujimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- benchmarks/bm_yhpg.rb
|
74
74
|
- benchmarks/helper.rb
|
75
75
|
- lib/power_assert.rb
|
76
|
+
- lib/power_assert/configuration.rb
|
76
77
|
- lib/power_assert/enable_tracepoint_events.rb
|
77
78
|
- lib/power_assert/version.rb
|
78
79
|
- power_assert.gemspec
|