public
Rubygem
Description: Pedal to the metal manual profiler
Clone URL: git://github.com/nicksieger/stickshift.git
Prevent instrumenting String or Benchmark
nicksieger (author)
Sat May 31 17:33:44 -0700 2008
commit  d25b334c9d8aee200f558aac83bb74fd01ec3d36
tree    8a8e077edd52ecc3b76d91a13d1b1b7f6d0a1a07
parent  a0a34a04e236960bc8273fa0018e2c860df068e1
...
105
106
107
108
 
 
109
110
111
 
 
 
112
113
114
...
105
106
107
 
108
109
110
111
 
112
113
114
115
116
117
0
@@ -105,10 +105,13 @@ class Module
0
     end
0
   end
0
 
0
- RESTRICTED = %w(inspect __send__ __id__)
0
+ RESTRICTED_CLASSES = [String, (class << Benchmark; self; end), Benchmark]
0
+ RESTRICTED_METHODS = %w(inspect __send__ __id__)
0
 
0
   def instrumented?(meth)
0
- RESTRICTED.include?(meth.to_s) || meth =~ /__instrumented$/ ||
0
+ RESTRICTED_CLASSES.include?(self) ||
0
+ RESTRICTED_METHODS.include?(meth.to_s) ||
0
+ meth =~ /__instrumented$/ ||
0
       instance_methods.include?("#{__stickshift_mangle(meth)}__instrumented")
0
   end
0
 
...
29
30
31
 
 
 
 
 
 
 
32
 
 
33
34
35
...
126
127
128
129
130
131
132
133
134
135
...
145
146
147
 
 
 
 
 
 
 
 
 
148
...
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
...
135
136
137
 
 
 
 
138
139
140
...
150
151
152
153
154
155
156
157
158
159
160
161
162
0
@@ -29,7 +29,16 @@ class Bar
0
   end
0
 end
0
 
0
+module TestHelper
0
+ def instrumented_name(meth)
0
+ Module.__stickshift_mangle(meth) + '__instrumented'
0
+ end
0
+ module_function :instrumented_name
0
+end
0
+
0
 class StickshiftTest < Test::Unit::TestCase
0
+ include TestHelper
0
+
0
   def capture
0
     Stickshift.output = @stdout = StringIO.new
0
     @out = nil
0
@@ -126,10 +135,6 @@ class StickshiftTest < Test::Unit::TestCase
0
     assert @stdout.string =~ /Bar#slow_method.*Foo#slow_method/m
0
   end
0
 
0
- def instrumented_name(meth)
0
- Module.__stickshift_mangle(meth) + '__instrumented'
0
- end
0
-
0
   def test_cannot_instrument_instrumented_methods
0
     Foo.instrument :slow_method
0
     assert Foo.instrumented?(:slow_method)
0
@@ -145,4 +150,13 @@ class StickshiftTest < Test::Unit::TestCase
0
       assert !Foo.instance_methods.include?(instrumented_name(m))
0
     end
0
   end
0
+
0
+ def test_cannot_instrument_string_or_benchmark_methods
0
+ String.instrument :to_s
0
+ assert !String.instance_methods.include?(instrumented_name(:to_s))
0
+ assert ! class << Benchmark;
0
+ instrument :realtime
0
+ self.instance_methods.include?(TestHelper::instrumented_name(:realtime))
0
+ end
0
+ end
0
 end

Comments

    No one has commented yet.