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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e75d0a3ce99d4b13a7a459ae5b82ecb25622ced9
4
- data.tar.gz: 5cf4b3586a8f34c71a784c61f87f978bc3969d04
3
+ metadata.gz: 5f750b892c57de72ef8565ce7b74f150d1cb58dd
4
+ data.tar.gz: 9512911b0c2a348b58015eabfc72c1f2bfd91922
5
5
  SHA512:
6
- metadata.gz: 3d5ddce14b64265f9ff11e301f36d0ba686fca762370acfd9c8002fe1eb5c31de83f7f53b428877a6867ea06f3f55653b2f2cbff41ec42e3c8b71ea9625d8fbd
7
- data.tar.gz: 3ea2c9ed78088200757930e92ef079c8d20aaae02ffaf9ffcb2b940a6eada78811363df8b35a827aa2ded501788805ad02a16c451dfa22bf6732865a2c551e7f
6
+ metadata.gz: d1e3d4320129a287703f80ffb480a42841adb66146a792f758d14539176b6c6694057efc3ecf24e420c7ed6dda1936806c36eb0a793ffad33761e510025c1de2
7
+ data.tar.gz: e006193bdbb8abc8f991b35ada079083f3f242effbdef3df2905535b874ac758d93834960d319c87640c9c76d333a77a4d31fc9c02fd8728965dbad4c5298d78
data/.travis.yml CHANGED
@@ -2,8 +2,8 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0.0-p648
4
4
  - 2.1.10
5
- - 2.2.5
6
- - 2.3.1
5
+ - 2.2.6
6
+ - 2.3.3
7
7
  - ruby-head
8
8
  matrix:
9
9
  allow_failures:
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 = (trace_alias_method &&
136
- tp.event == :return &&
137
- tp.binding.eval('::Kernel.__callee__')) || tp.method_id
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
- verbose = $VERBOSE
3
- begin
4
- $VERBOSE = nil
5
- module PowerAssert
6
- # set redefined flag
7
- basic_classes = [
8
- Fixnum, Float, String, Array, Hash, Bignum, Symbol, Time, Regexp
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
- basic_operators = [
12
- :+, :-, :*, :/, :%, :==, :===, :<, :<=, :<<, :[], :[]=,
13
- :length, :size, :empty?, :succ, :>, :>=, :!, :!=, :=~, :freeze
14
- ]
14
+ basic_operators = [
15
+ :+, :-, :*, :/, :%, :==, :===, :<, :<=, :<<, :[], :[]=,
16
+ :length, :size, :empty?, :succ, :>, :>=, :!, :!=, :=~, :freeze
17
+ ]
15
18
 
16
- class Bug11182
17
- def fixed?
18
- true
19
+ class Bug11182
20
+ def fixed?
21
+ true
22
+ end
19
23
  end
20
- end
21
- private_constant :Bug11182
24
+ private_constant :Bug11182
22
25
 
23
- refine Bug11182 do
24
- def fixed?
26
+ refine Bug11182 do
27
+ def fixed?
28
+ end
25
29
  end
26
- end
27
30
 
28
- class Bug11182Sub < Bug11182
29
- alias _fixed? fixed?
30
- protected :_fixed?
31
- end
32
- private_constant :Bug11182Sub
31
+ class Bug11182Sub < Bug11182
32
+ alias _fixed? fixed?
33
+ protected :_fixed?
34
+ end
35
+ private_constant :Bug11182Sub
33
36
 
34
- if (Bug11182.new.fixed? rescue false)
35
- basic_classes.each do |klass|
36
- basic_operators.each do |bop|
37
- refine(klass) do
38
- define_method(bop) {}
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
- end
42
- else
43
- # workaround for https://bugs.ruby-lang.org/issues/11182
44
- basic_classes.each do |klass|
45
- basic_operators.each do |bop|
46
- if klass.public_method_defined?(bop)
47
- klass.ancestors.find {|i| i.instance_methods(false).index(bop) }.module_eval do
48
- public bop
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
- refine Symbol do
55
- def ==
57
+ refine Symbol do
58
+ def ==
59
+ end
56
60
  end
57
61
  end
58
- end
59
62
 
60
- # bypass check_cfunc
61
- refine BasicObject do
62
- def !
63
- end
63
+ # bypass check_cfunc
64
+ refine BasicObject do
65
+ def !
66
+ end
64
67
 
65
- def ==
68
+ def ==
69
+ end
66
70
  end
67
- end
68
71
 
69
- refine Module do
70
- def ==
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
@@ -1,3 +1,3 @@
1
1
  module PowerAssert
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -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
- omit 'alias of cfunc is not supported yet'
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.3.1
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-09-07 00:00:00.000000000 Z
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