heckle 1.4.1 → 1.4.2
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.
- data/.autotest +16 -0
- data/History.txt +26 -0
- data/Manifest.txt +1 -0
- data/README.txt +9 -8
- data/Rakefile +20 -11
- data/bin/heckle +20 -13
- data/lib/heckle.rb +152 -90
- data/lib/test_unit_heckler.rb +24 -9
- data/test/fixtures/heckled.rb +6 -2
- data/test/test_heckle.rb +352 -364
- metadata +83 -57
data/lib/test_unit_heckler.rb
CHANGED
@@ -1,12 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'test/unit/autorunner'
|
4
|
+
require 'test/unit/testcase'
|
4
5
|
require 'heckle'
|
5
6
|
require 'zentest_mapping'
|
6
7
|
|
7
8
|
$: << 'lib' << 'test'
|
8
9
|
|
10
|
+
# Make sure test/unit doesn't swallow our timeout
|
11
|
+
begin
|
12
|
+
Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS << Heckle::Timeout
|
13
|
+
rescue NameError
|
14
|
+
# ignore
|
15
|
+
end
|
16
|
+
|
9
17
|
class TestUnitHeckler < Heckle
|
18
|
+
|
10
19
|
@@test_pattern = 'test/test_*.rb'
|
11
20
|
@@tests_loaded = false
|
12
21
|
@@focus = false
|
@@ -25,7 +34,7 @@ class TestUnitHeckler < Heckle
|
|
25
34
|
end
|
26
35
|
|
27
36
|
def self.validate(klass_name, method_name = nil,
|
28
|
-
nodes = Heckle::MUTATABLE_NODES)
|
37
|
+
nodes = Heckle::MUTATABLE_NODES, force = false)
|
29
38
|
load_test_files
|
30
39
|
klass = klass_name.to_class
|
31
40
|
|
@@ -41,21 +50,27 @@ class TestUnitHeckler < Heckle
|
|
41
50
|
|
42
51
|
initial_time = Time.now
|
43
52
|
|
44
|
-
|
53
|
+
heckle = self.new(klass_name)
|
54
|
+
|
55
|
+
passed = heckle.tests_pass?
|
56
|
+
|
57
|
+
unless force or passed then
|
45
58
|
abort "Initial run of tests failed... fix and run heckle again"
|
46
59
|
end
|
47
60
|
|
48
|
-
if self.guess_timeout?
|
49
|
-
running_time =
|
50
|
-
adjusted_timeout = (running_time * 2 < 5) ? 5 : (running_time * 2)
|
61
|
+
if self.guess_timeout? then
|
62
|
+
running_time = Time.now - initial_time
|
63
|
+
adjusted_timeout = (running_time * 2 < 5) ? 5 : (running_time * 2).ceil
|
51
64
|
self.timeout = adjusted_timeout
|
52
|
-
puts "Setting timeout at #{adjusted_timeout} seconds." if @@debug
|
53
|
-
|
54
65
|
end
|
55
66
|
|
56
|
-
|
67
|
+
puts "Timeout set to #{adjusted_timeout} seconds."
|
57
68
|
|
58
|
-
|
69
|
+
if passed then
|
70
|
+
puts "Initial tests pass. Let's rumble."
|
71
|
+
else
|
72
|
+
puts "Initial tests failed but you forced things. Let's rumble."
|
73
|
+
end
|
59
74
|
puts
|
60
75
|
|
61
76
|
methods = method_name ? Array(method_name) : klass.instance_methods(false) + klass_methods
|
data/test/fixtures/heckled.rb
CHANGED
data/test/test_heckle.rb
CHANGED
@@ -25,22 +25,31 @@ class TestHeckler < Heckle
|
|
25
25
|
end
|
26
26
|
|
27
27
|
class HeckleTestCase < Test::Unit::TestCase
|
28
|
-
|
28
|
+
unless defined? Mini then
|
29
|
+
undef_method :default_test
|
30
|
+
alias :refute_equal :assert_not_equal
|
31
|
+
end
|
32
|
+
|
29
33
|
def setup
|
30
34
|
@nodes ||= Heckle::MUTATABLE_NODES
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
unless defined? @hecklee then
|
36
|
+
data = self.class.name.sub(/HeckleTestCase/, '').sub(/TestHeckle/, '')
|
37
|
+
data = data.gsub(/([A-Z])/, '_\1').downcase
|
38
|
+
data = "_many_things" if data.empty?
|
39
|
+
@hecklee = "uses#{data}"
|
40
|
+
end
|
41
|
+
|
42
|
+
@heckler = TestHeckler.new("Heckled", @hecklee, @nodes) rescue nil
|
34
43
|
end
|
35
44
|
|
36
45
|
def teardown
|
37
|
-
@heckler.reset
|
46
|
+
@heckler.reset if defined?(@heckler) && @heckler
|
38
47
|
end
|
39
48
|
end
|
40
49
|
|
41
50
|
class LiteralHeckleTestCase < HeckleTestCase
|
42
51
|
def setup
|
43
|
-
@nodes =
|
52
|
+
@nodes = s(:lit, :str)
|
44
53
|
super
|
45
54
|
end
|
46
55
|
|
@@ -72,26 +81,25 @@ end
|
|
72
81
|
|
73
82
|
class TestHeckle < HeckleTestCase
|
74
83
|
def test_should_set_original_tree
|
75
|
-
expected =
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
[:lvar, :i]]]]]
|
84
|
+
expected = s(:defn, :uses_many_things,
|
85
|
+
s(:args),
|
86
|
+
s(:scope,
|
87
|
+
s(:block,
|
88
|
+
s(:lasgn, :i, s(:lit, 1)),
|
89
|
+
s(:while,
|
90
|
+
s(:call, s(:lvar, :i), :<, s(:arglist, s(:lit, 10))),
|
91
|
+
s(:block,
|
92
|
+
s(:lasgn, :i, s(:call, s(:lvar, :i), :+, s(:arglist, s(:lit, 1)))),
|
93
|
+
s(:until, s(:call, nil, :some_func, s(:arglist)),
|
94
|
+
s(:call, nil, :some_other_func, s(:arglist)), true),
|
95
|
+
s(:if,
|
96
|
+
s(:call, s(:str, "hi there"), :==,
|
97
|
+
s(:arglist, s(:str, "changeling"))),
|
98
|
+
s(:return, s(:true)),
|
99
|
+
nil),
|
100
|
+
s(:return, s(:false))),
|
101
|
+
true),
|
102
|
+
s(:lvar, :i))))
|
95
103
|
|
96
104
|
assert_equal expected, @heckler.original_tree
|
97
105
|
end
|
@@ -99,46 +107,52 @@ class TestHeckle < HeckleTestCase
|
|
99
107
|
def test_should_grab_mutatees_from_method
|
100
108
|
# expected is from tree of uses_while
|
101
109
|
expected = {
|
102
|
-
:call => [
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
110
|
+
:call => [s(:call, s(:lvar, :i), :<, s(:arglist, s(:lit, 10))),
|
111
|
+
s(:call, s(:lvar, :i), :+, s(:arglist, s(:lit, 1))),
|
112
|
+
s(:call, nil, :some_func, s(:arglist)), # FIX: why added?
|
113
|
+
s(:call, nil, :some_other_func, s(:arglist)), # FIX: why added?
|
114
|
+
s(:call, s(:str, "hi there"), :==,
|
115
|
+
s(:arglist, s(:str, "changeling")))],
|
116
|
+
:cvasgn => [], # no cvasgns here
|
117
|
+
:dasgn => [], # no dasgns here
|
108
118
|
:dasgn_curr => [], # no dasgn_currs here
|
109
|
-
:iasgn => [],
|
110
|
-
:
|
111
|
-
:
|
112
|
-
|
113
|
-
|
114
|
-
:
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
:
|
120
|
-
:
|
121
|
-
:
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
119
|
+
:iasgn => [], # no iasgns here
|
120
|
+
:iter => [],
|
121
|
+
:gasgn => [], # no gasgns here
|
122
|
+
:lasgn => [s(:lasgn, :i, s(:lit, 1)),
|
123
|
+
s(:lasgn, :i, s(:call, s(:lvar, :i), :+, s(:arglist, s(:lit, 1))))],
|
124
|
+
:lit => [s(:lit, 1), s(:lit, 10), s(:lit, 1)],
|
125
|
+
:if => [s(:if,
|
126
|
+
s(:call, s(:str, "hi there"), :==, s(:arglist, s(:str, "changeling"))),
|
127
|
+
s(:return, s(:true)),
|
128
|
+
nil)],
|
129
|
+
:str => [s(:str, "hi there"), s(:str, "changeling")],
|
130
|
+
:true => [s(:true)],
|
131
|
+
:false => [s(:false)],
|
132
|
+
:while => [s(:while,
|
133
|
+
s(:call, s(:lvar, :i), :<, s(:arglist, s(:lit, 10))),
|
134
|
+
s(:block,
|
135
|
+
s(:lasgn, :i, s(:call, s(:lvar, :i), :+, s(:arglist, s(:lit, 1)))),
|
136
|
+
s(:until, s(:call, nil, :some_func, s(:arglist)),
|
137
|
+
s(:call, nil, :some_other_func, s(:arglist)), true),
|
138
|
+
s(:if,
|
139
|
+
s(:call, s(:str, "hi there"), :==,
|
140
|
+
s(:arglist, s(:str, "changeling"))),
|
141
|
+
s(:return, s(:true)),
|
142
|
+
nil),
|
143
|
+
s(:return, s(:false))),
|
144
|
+
true)],
|
145
|
+
:until => [s(:until,
|
146
|
+
s(:call, nil, :some_func, s(:arglist)),
|
147
|
+
s(:call, nil, :some_other_func, s(:arglist)),
|
148
|
+
true)],
|
135
149
|
}
|
136
150
|
|
137
151
|
assert_equal expected, @heckler.mutatees
|
138
152
|
end
|
139
153
|
|
140
154
|
def test_should_count_mutatees_left
|
141
|
-
assert_equal
|
155
|
+
assert_equal 17, @heckler.mutations_left # FIX WHY?!?
|
142
156
|
end
|
143
157
|
|
144
158
|
def test_reset
|
@@ -147,11 +161,11 @@ class TestHeckle < HeckleTestCase
|
|
147
161
|
|
148
162
|
3.times { @heckler.process(@heckler.current_tree) }
|
149
163
|
|
150
|
-
|
151
|
-
|
164
|
+
refute_equal original_tree, @heckler.current_tree
|
165
|
+
refute_equal original_mutatees, @heckler.mutatees
|
152
166
|
|
153
167
|
@heckler.reset
|
154
|
-
assert_equal original_tree[2], @heckler.current_tree[2]
|
168
|
+
assert_equal original_tree[2], @heckler.current_tree[2]
|
155
169
|
assert_equal original_mutatees, @heckler.mutatees
|
156
170
|
end
|
157
171
|
|
@@ -159,7 +173,7 @@ class TestHeckle < HeckleTestCase
|
|
159
173
|
original_tree = @heckler.current_tree.deep_clone
|
160
174
|
|
161
175
|
@heckler.process(@heckler.current_tree)
|
162
|
-
|
176
|
+
refute_equal original_tree, @heckler.current_tree
|
163
177
|
|
164
178
|
@heckler.reset_tree
|
165
179
|
assert_equal original_tree, @heckler.current_tree
|
@@ -170,16 +184,16 @@ class TestHeckle < HeckleTestCase
|
|
170
184
|
original_mutatees = @heckler.mutatees.deep_clone
|
171
185
|
|
172
186
|
@heckler.process(@heckler.current_tree)
|
173
|
-
|
174
|
-
|
187
|
+
refute_equal original_tree, @heckler.current_tree
|
188
|
+
refute_equal original_mutatees, @heckler.mutatees
|
175
189
|
|
176
190
|
@heckler.reset
|
177
191
|
assert_equal original_tree, @heckler.current_tree
|
178
192
|
assert_equal original_mutatees, @heckler.mutatees
|
179
193
|
|
180
194
|
3.times { @heckler.process(@heckler.current_tree) }
|
181
|
-
|
182
|
-
|
195
|
+
refute_equal original_tree, @heckler.current_tree
|
196
|
+
refute_equal original_mutatees, @heckler.mutatees
|
183
197
|
|
184
198
|
@heckler.reset
|
185
199
|
assert_equal original_tree, @heckler.current_tree
|
@@ -190,7 +204,7 @@ class TestHeckle < HeckleTestCase
|
|
190
204
|
original_mutatees = @heckler.mutatees.deep_clone
|
191
205
|
|
192
206
|
@heckler.process(@heckler.current_tree)
|
193
|
-
|
207
|
+
refute_equal original_mutatees, @heckler.mutatees
|
194
208
|
|
195
209
|
@heckler.reset_mutatees
|
196
210
|
assert_equal original_mutatees, @heckler.mutatees
|
@@ -203,14 +217,14 @@ class TestHeckleNumericLiterals < HeckleTestCase
|
|
203
217
|
end
|
204
218
|
|
205
219
|
def util_expected(n)
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
220
|
+
s(:defn, :uses_numeric_literals,
|
221
|
+
s(:args),
|
222
|
+
s(:scope,
|
223
|
+
s(:block,
|
224
|
+
s(:lasgn, :i, s(:lit, toggle(1, 1 == n))),
|
225
|
+
s(:lasgn, :i, s(:call, s(:lvar, :i), :+,
|
226
|
+
s(:arglist, s(:lit, toggle(2147483648, 2 == n))))),
|
227
|
+
s(:lasgn, :i, s(:call, s(:lvar, :i), :-, s(:arglist, s(:lit, toggle(3.5, 3 == n))))))))
|
214
228
|
end
|
215
229
|
end
|
216
230
|
|
@@ -218,13 +232,13 @@ class TestHeckleSymbols < LiteralHeckleTestCase
|
|
218
232
|
TOGGLE_VALUE = :"l33t h4x0r"
|
219
233
|
|
220
234
|
def util_expected(n = nil)
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
235
|
+
s(:defn, :uses_symbols,
|
236
|
+
s(:args),
|
237
|
+
s(:scope,
|
238
|
+
s(:block,
|
239
|
+
s(:lasgn, :i, s(:lit, toggle(:blah, n == 1))),
|
240
|
+
s(:lasgn, :i, s(:lit, toggle(:blah, n == 2))),
|
241
|
+
s(:lasgn, :i, s(:lit, toggle(:and_blah, n == 3))))))
|
228
242
|
end
|
229
243
|
end
|
230
244
|
|
@@ -232,13 +246,13 @@ class TestHeckleRegexes < LiteralHeckleTestCase
|
|
232
246
|
TOGGLE_VALUE = /l33t\ h4x0r/
|
233
247
|
|
234
248
|
def util_expected(n = nil)
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
249
|
+
s(:defn, :uses_regexes,
|
250
|
+
s(:args),
|
251
|
+
s(:scope,
|
252
|
+
s(:block,
|
253
|
+
s(:lasgn, :i, s(:lit, toggle(/a.*/, n == 1))),
|
254
|
+
s(:lasgn, :i, s(:lit, toggle(/c{2,4}+/, n == 2))),
|
255
|
+
s(:lasgn, :i, s(:lit, toggle(/123/, n == 3))))))
|
242
256
|
end
|
243
257
|
end
|
244
258
|
|
@@ -246,13 +260,13 @@ class TestHeckleRanges < LiteralHeckleTestCase
|
|
246
260
|
TOGGLE_VALUE = 5..10
|
247
261
|
|
248
262
|
def util_expected(n = nil)
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
263
|
+
s(:defn, :uses_ranges,
|
264
|
+
s(:args),
|
265
|
+
s(:scope,
|
266
|
+
s(:block,
|
267
|
+
s(:lasgn, :i, s(:lit, toggle(6..100, n == 1))),
|
268
|
+
s(:lasgn, :i, s(:lit, toggle(-1..9, n == 2))),
|
269
|
+
s(:lasgn, :i, s(:lit, toggle(1..4, n == 3))))))
|
256
270
|
end
|
257
271
|
end
|
258
272
|
|
@@ -260,13 +274,13 @@ class TestHeckleSameLiteral < LiteralHeckleTestCase
|
|
260
274
|
TOGGLE_VALUE = 6
|
261
275
|
|
262
276
|
def util_expected(n = nil)
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
277
|
+
s(:defn, :uses_same_literal,
|
278
|
+
s(:args),
|
279
|
+
s(:scope,
|
280
|
+
s(:block,
|
281
|
+
s(:lasgn, :i, s(:lit, toggle(1, n == 1))),
|
282
|
+
s(:lasgn, :i, s(:lit, toggle(1, n == 2))),
|
283
|
+
s(:lasgn, :i, s(:lit, toggle(1, n == 3))))))
|
270
284
|
end
|
271
285
|
end
|
272
286
|
|
@@ -274,53 +288,58 @@ class TestHeckleStrings < LiteralHeckleTestCase
|
|
274
288
|
TOGGLE_VALUE = "l33t h4x0r"
|
275
289
|
|
276
290
|
def util_expected(n = nil)
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
291
|
+
s(:defn, :uses_strings,
|
292
|
+
s(:args),
|
293
|
+
s(:scope,
|
294
|
+
s(:block,
|
295
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, toggle("Hello, Robert", n == 1)))),
|
296
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, toggle("Hello, Jeff", n == 2)))),
|
297
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, toggle("Hi, Frank", n == 3)))))))
|
284
298
|
end
|
285
299
|
end
|
286
300
|
|
287
301
|
class TestHeckleIf < HeckleTestCase
|
302
|
+
def setup
|
303
|
+
@nodes = s(:if)
|
304
|
+
super
|
305
|
+
end
|
306
|
+
|
288
307
|
def test_default_structure
|
289
|
-
expected =
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
308
|
+
expected = s(:defn, :uses_if,
|
309
|
+
s(:args),
|
310
|
+
s(:scope,
|
311
|
+
s(:block,
|
312
|
+
s(:if,
|
313
|
+
s(:call, nil, :some_func, s(:arglist)),
|
314
|
+
s(:if, s(:call, nil, :some_other_func, s(:arglist)), s(:return), nil),
|
315
|
+
nil))))
|
297
316
|
|
298
317
|
assert_equal expected, @heckler.current_tree
|
299
318
|
end
|
300
319
|
|
301
320
|
def test_should_flip_if_to_unless
|
302
|
-
expected =
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
321
|
+
expected = s(:defn, :uses_if,
|
322
|
+
s(:args),
|
323
|
+
s(:scope,
|
324
|
+
s(:block,
|
325
|
+
s(:if,
|
326
|
+
s(:call, nil, :some_func, s(:arglist)),
|
327
|
+
s(:if, s(:call, nil, :some_other_func, s(:arglist)), nil, s(:return)),
|
328
|
+
nil))))
|
310
329
|
|
311
330
|
@heckler.process(@heckler.current_tree)
|
312
331
|
assert_equal expected, @heckler.current_tree
|
313
332
|
|
314
333
|
@heckler.reset_tree
|
315
334
|
|
316
|
-
expected =
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
335
|
+
expected = s(:defn, :uses_if,
|
336
|
+
s(:args),
|
337
|
+
s(:scope,
|
338
|
+
s(:block,
|
339
|
+
s(:if,
|
340
|
+
s(:call, nil, :some_func, s(:arglist)),
|
341
|
+
nil,
|
342
|
+
s(:if, s(:call, nil, :some_other_func, s(:arglist)), s(:return), nil)))))
|
324
343
|
|
325
344
|
@heckler.process(@heckler.current_tree)
|
326
345
|
assert_equal expected, @heckler.current_tree
|
@@ -330,7 +349,7 @@ end
|
|
330
349
|
class TestHeckleBoolean < HeckleTestCase
|
331
350
|
|
332
351
|
def setup
|
333
|
-
@nodes =
|
352
|
+
@nodes = s(:true, :false)
|
334
353
|
super
|
335
354
|
end
|
336
355
|
|
@@ -339,12 +358,12 @@ class TestHeckleBoolean < HeckleTestCase
|
|
339
358
|
end
|
340
359
|
|
341
360
|
def util_expected(n = nil)
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
361
|
+
s(:defn, :uses_boolean,
|
362
|
+
s(:args),
|
363
|
+
s(:scope,
|
364
|
+
s(:block,
|
365
|
+
s(:lasgn, :a, s(toggle(true, n == 1))),
|
366
|
+
s(:lasgn, :b, s(toggle(false, n == 2))))))
|
348
367
|
end
|
349
368
|
|
350
369
|
def test_default_structure
|
@@ -363,46 +382,56 @@ class TestHeckleBoolean < HeckleTestCase
|
|
363
382
|
end
|
364
383
|
|
365
384
|
class TestHeckleWhile < HeckleTestCase
|
385
|
+
def setup
|
386
|
+
@nodes = s(:while)
|
387
|
+
super
|
388
|
+
end
|
389
|
+
|
366
390
|
def test_default_structure
|
367
|
-
expected =
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
391
|
+
expected = s(:defn, :uses_while,
|
392
|
+
s(:args),
|
393
|
+
s(:scope,
|
394
|
+
s(:block,
|
395
|
+
s(:while, s(:call, nil, :some_func, s(:arglist)),
|
396
|
+
s(:call, nil, :some_other_func, s(:arglist)), true))))
|
373
397
|
assert_equal expected, @heckler.current_tree
|
374
398
|
end
|
375
399
|
|
376
400
|
def test_flips_while_to_until
|
377
|
-
expected =
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
401
|
+
expected = s(:defn, :uses_while,
|
402
|
+
s(:args),
|
403
|
+
s(:scope,
|
404
|
+
s(:block,
|
405
|
+
s(:until, s(:call, nil, :some_func, s(:arglist)),
|
406
|
+
s(:call, nil, :some_other_func, s(:arglist)), true))))
|
383
407
|
@heckler.process(@heckler.current_tree)
|
384
408
|
assert_equal expected, @heckler.current_tree
|
385
409
|
end
|
386
410
|
end
|
387
411
|
|
388
412
|
class TestHeckleUntil < HeckleTestCase
|
413
|
+
def setup
|
414
|
+
@nodes = s(:until)
|
415
|
+
super
|
416
|
+
end
|
417
|
+
|
389
418
|
def test_default_structure
|
390
|
-
expected =
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
419
|
+
expected = s(:defn, :uses_until,
|
420
|
+
s(:args),
|
421
|
+
s(:scope,
|
422
|
+
s(:block,
|
423
|
+
s(:until, s(:call, nil, :some_func, s(:arglist)),
|
424
|
+
s(:call, nil, :some_other_func, s(:arglist)), true))))
|
396
425
|
assert_equal expected, @heckler.current_tree
|
397
426
|
end
|
398
427
|
|
399
428
|
def test_flips_until_to_while
|
400
|
-
expected =
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
429
|
+
expected = s(:defn, :uses_until,
|
430
|
+
s(:args),
|
431
|
+
s(:scope,
|
432
|
+
s(:block,
|
433
|
+
s(:while, s(:call, nil, :some_func, s(:arglist)),
|
434
|
+
s(:call, nil, :some_other_func, s(:arglist)), true))))
|
406
435
|
@heckler.process(@heckler.current_tree)
|
407
436
|
assert_equal expected, @heckler.current_tree
|
408
437
|
end
|
@@ -411,26 +440,29 @@ end
|
|
411
440
|
class TestHeckleCall < HeckleTestCase
|
412
441
|
|
413
442
|
def test_call_deleted
|
414
|
-
expected =
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
443
|
+
expected = s(:defn, :uses_call,
|
444
|
+
s(:args),
|
445
|
+
s(:scope,
|
446
|
+
s(:block,
|
447
|
+
s(:nil))))
|
419
448
|
|
420
|
-
@heckler.process(@heckler.current_tree)
|
449
|
+
@heckler.process(@heckler.current_tree) # some_func
|
450
|
+
@heckler.reset_tree
|
451
|
+
@heckler.process(@heckler.current_tree) # some_other_func
|
452
|
+
@heckler.reset_tree
|
453
|
+
@heckler.process(@heckler.current_tree) # +
|
421
454
|
assert_equal expected, @heckler.current_tree
|
422
455
|
end
|
423
456
|
|
424
457
|
def test_default_structure
|
425
|
-
expected =
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
[:array, [:vcall, :some_other_func]]]]]]]
|
458
|
+
expected = s(:defn, :uses_call,
|
459
|
+
s(:args),
|
460
|
+
s(:scope,
|
461
|
+
s(:block,
|
462
|
+
s(:call,
|
463
|
+
s(:call, nil, :some_func, s(:arglist)),
|
464
|
+
:+,
|
465
|
+
s(:arglist, s(:call, nil, :some_other_func, s(:arglist)))))))
|
434
466
|
|
435
467
|
assert_equal expected, @heckler.current_tree
|
436
468
|
end
|
@@ -440,175 +472,91 @@ end
|
|
440
472
|
class TestHeckleCallblock < HeckleTestCase
|
441
473
|
|
442
474
|
def setup
|
443
|
-
@nodes =
|
475
|
+
@nodes = s(:call)
|
444
476
|
super
|
445
477
|
end
|
446
478
|
|
447
|
-
def test_callblock_deleted
|
448
|
-
expected = [:defn, :uses_callblock,
|
449
|
-
[:scope,
|
450
|
-
[:block,
|
451
|
-
[:args],
|
452
|
-
[:iter, [:call, [:vcall, :x], :y], nil, [:lit, 1]]]]]
|
453
|
-
|
454
|
-
@heckler.process(@heckler.current_tree)
|
455
|
-
assert_equal expected, @heckler.current_tree
|
456
|
-
end
|
457
|
-
|
458
|
-
end
|
459
|
-
|
460
|
-
class TestHeckleClassMethod < Test::Unit::TestCase
|
461
|
-
def setup
|
462
|
-
@heckler = TestHeckler.new("Heckled", "self.is_a_klass_method?")
|
463
|
-
end
|
464
|
-
|
465
|
-
def teardown
|
466
|
-
@heckler.reset
|
467
|
-
end
|
468
|
-
|
469
479
|
def test_default_structure
|
470
|
-
expected =
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
def test_heckle_class_methods
|
479
|
-
expected = [:defn, :"self.is_a_klass_method?",
|
480
|
-
[:scope,
|
481
|
-
[:block,
|
482
|
-
[:args],
|
483
|
-
[:false]]]]
|
484
|
-
@heckler.process(@heckler.current_tree)
|
485
|
-
assert_equal expected, @heckler.current_tree
|
486
|
-
end
|
487
|
-
end
|
480
|
+
expected = s(:defn, :uses_callblock,
|
481
|
+
s(:args),
|
482
|
+
s(:scope,
|
483
|
+
s(:block,
|
484
|
+
s(:iter,
|
485
|
+
s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist)),
|
486
|
+
nil,
|
487
|
+
s(:lit, 1)))))
|
488
488
|
|
489
|
-
class TestHeckleCvasgn < HeckleTestCase
|
490
|
-
|
491
|
-
def setup
|
492
|
-
@nodes = [:cvasgn]
|
493
|
-
super
|
494
|
-
end
|
495
|
-
|
496
|
-
def test_cvasgn_val
|
497
|
-
expected = [:defn, :uses_cvasgn,
|
498
|
-
[:scope,
|
499
|
-
[:block,
|
500
|
-
[:args],
|
501
|
-
[:cvasgn, :@@cvar, [:nil]],
|
502
|
-
[:cvasgn, :@@cvar, [:nil]]]]]
|
503
|
-
|
504
|
-
@heckler.process(@heckler.current_tree)
|
505
489
|
assert_equal expected, @heckler.current_tree
|
506
490
|
end
|
491
|
+
def test_callblock_deleted
|
492
|
+
expected = s(:defn, :uses_callblock,
|
493
|
+
s(:args),
|
494
|
+
s(:scope,
|
495
|
+
s(:block,
|
496
|
+
s(:iter,
|
497
|
+
s(:call, s(:nil), :y, s(:arglist)),
|
498
|
+
nil,
|
499
|
+
s(:lit, 1)))))
|
507
500
|
|
508
|
-
def test_cvasgn_nil
|
509
|
-
expected = [:defn, :uses_cvasgn,
|
510
|
-
[:scope,
|
511
|
-
[:block,
|
512
|
-
[:args],
|
513
|
-
[:cvasgn, :@@cvar, [:lit, 5]],
|
514
|
-
[:cvasgn, :@@cvar, [:lit, 42]]]]]
|
515
|
-
|
516
|
-
@heckler.process(@heckler.current_tree)
|
517
|
-
@heckler.reset_tree
|
518
501
|
@heckler.process(@heckler.current_tree)
|
519
502
|
assert_equal expected, @heckler.current_tree
|
520
503
|
end
|
521
|
-
|
522
504
|
end
|
523
505
|
|
524
|
-
class
|
525
|
-
|
506
|
+
class TestHeckleClassMethod < HeckleTestCase
|
526
507
|
def setup
|
527
|
-
@
|
508
|
+
@hecklee = "self.is_a_klass_method?"
|
509
|
+
@nodes = s(:true)
|
528
510
|
super
|
529
511
|
end
|
530
512
|
|
531
|
-
def
|
532
|
-
expected =
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
[:fcall, :loop],
|
538
|
-
[:dasgn_curr, :dvar],
|
539
|
-
[:iter,
|
540
|
-
[:fcall, :loop],
|
541
|
-
nil,
|
542
|
-
[:block,
|
543
|
-
[:dasgn, :dvar, [:nil]],
|
544
|
-
[:dasgn, :dvar, [:nil]]]]]]]]
|
545
|
-
|
546
|
-
@heckler.process(@heckler.current_tree)
|
513
|
+
def test_default_structure
|
514
|
+
expected = s(:defs, s(:self), :is_a_klass_method?,
|
515
|
+
s(:args),
|
516
|
+
s(:scope,
|
517
|
+
s(:block,
|
518
|
+
s(:true))))
|
547
519
|
assert_equal expected, @heckler.current_tree
|
548
520
|
end
|
549
521
|
|
550
|
-
def
|
551
|
-
expected =
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
[:fcall, :loop],
|
557
|
-
[:dasgn_curr, :dvar],
|
558
|
-
[:iter,
|
559
|
-
[:fcall, :loop],
|
560
|
-
nil,
|
561
|
-
[:block,
|
562
|
-
[:dasgn, :dvar, [:lit, 5]],
|
563
|
-
[:dasgn, :dvar, [:lit, 42]]]]]]]]
|
564
|
-
|
565
|
-
@heckler.process(@heckler.current_tree)
|
566
|
-
@heckler.reset_tree
|
522
|
+
def test_heckle_class_methods
|
523
|
+
expected = s(:defs, s(:self), :is_a_klass_method?,
|
524
|
+
s(:args),
|
525
|
+
s(:scope,
|
526
|
+
s(:block,
|
527
|
+
s(:false))))
|
567
528
|
@heckler.process(@heckler.current_tree)
|
568
529
|
assert_equal expected, @heckler.current_tree
|
569
530
|
end
|
570
|
-
|
571
531
|
end
|
572
532
|
|
573
|
-
class
|
533
|
+
class TestHeckleCvasgn < HeckleTestCase
|
574
534
|
|
575
535
|
def setup
|
576
|
-
@nodes =
|
536
|
+
@nodes = s(:cvasgn)
|
577
537
|
super
|
578
538
|
end
|
579
539
|
|
580
|
-
def
|
581
|
-
expected =
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
[:dasgn_curr, :dvar],
|
588
|
-
[:block,
|
589
|
-
[:dasgn_curr, :dvar, [:nil]],
|
590
|
-
[:dasgn_curr, :dvar, [:nil]]]]]]]
|
540
|
+
def test_cvasgn_val
|
541
|
+
expected = s(:defn, :uses_cvasgn,
|
542
|
+
s(:args),
|
543
|
+
s(:scope,
|
544
|
+
s(:block,
|
545
|
+
s(:cvasgn, :@@cvar, s(:nil)),
|
546
|
+
s(:cvasgn, :@@cvar, s(:nil)))))
|
591
547
|
|
592
|
-
@heckler.process(@heckler.current_tree)
|
593
|
-
@heckler.reset_tree
|
594
548
|
@heckler.process(@heckler.current_tree)
|
595
549
|
assert_equal expected, @heckler.current_tree
|
596
550
|
end
|
597
551
|
|
598
|
-
def
|
599
|
-
expected =
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
[:dasgn_curr, :dvar],
|
606
|
-
[:block,
|
607
|
-
[:dasgn_curr, :dvar, [:lit, 5]],
|
608
|
-
[:dasgn_curr, :dvar, [:lit, 42]]]]]]]
|
552
|
+
def test_cvasgn_nil
|
553
|
+
expected = s(:defn, :uses_cvasgn,
|
554
|
+
s(:args),
|
555
|
+
s(:scope,
|
556
|
+
s(:block,
|
557
|
+
s(:cvasgn, :@@cvar, s(:lit, 5)),
|
558
|
+
s(:cvasgn, :@@cvar, s(:lit, 42)))))
|
609
559
|
|
610
|
-
@heckler.process(@heckler.current_tree)
|
611
|
-
@heckler.reset_tree
|
612
560
|
@heckler.process(@heckler.current_tree)
|
613
561
|
@heckler.reset_tree
|
614
562
|
@heckler.process(@heckler.current_tree)
|
@@ -620,29 +568,29 @@ end
|
|
620
568
|
class TestHeckleIasgn < HeckleTestCase
|
621
569
|
|
622
570
|
def setup
|
623
|
-
@nodes =
|
571
|
+
@nodes = s(:iasgn)
|
624
572
|
super
|
625
573
|
end
|
626
574
|
|
627
575
|
def test_iasgn_val
|
628
|
-
expected =
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
576
|
+
expected = s(:defn, :uses_iasgn,
|
577
|
+
s(:args),
|
578
|
+
s(:scope,
|
579
|
+
s(:block,
|
580
|
+
s(:iasgn, :@ivar, s(:nil)),
|
581
|
+
s(:iasgn, :@ivar, s(:nil)))))
|
634
582
|
|
635
583
|
@heckler.process(@heckler.current_tree)
|
636
584
|
assert_equal expected, @heckler.current_tree
|
637
585
|
end
|
638
586
|
|
639
587
|
def test_iasgn_nil
|
640
|
-
expected =
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
588
|
+
expected = s(:defn, :uses_iasgn,
|
589
|
+
s(:args),
|
590
|
+
s(:scope,
|
591
|
+
s(:block,
|
592
|
+
s(:iasgn, :@ivar, s(:lit, 5)),
|
593
|
+
s(:iasgn, :@ivar, s(:lit, 42)))))
|
646
594
|
|
647
595
|
@heckler.process(@heckler.current_tree)
|
648
596
|
@heckler.reset_tree
|
@@ -655,29 +603,29 @@ end
|
|
655
603
|
class TestHeckleGasgn < HeckleTestCase
|
656
604
|
|
657
605
|
def setup
|
658
|
-
@nodes =
|
606
|
+
@nodes = s(:gasgn)
|
659
607
|
super
|
660
608
|
end
|
661
609
|
|
662
610
|
def test_gasgn_val
|
663
|
-
expected =
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
611
|
+
expected = s(:defn, :uses_gasgn,
|
612
|
+
s(:args),
|
613
|
+
s(:scope,
|
614
|
+
s(:block,
|
615
|
+
s(:gasgn, :$gvar, s(:nil)),
|
616
|
+
s(:gasgn, :$gvar, s(:nil)))))
|
669
617
|
|
670
618
|
@heckler.process(@heckler.current_tree)
|
671
619
|
assert_equal expected, @heckler.current_tree
|
672
620
|
end
|
673
621
|
|
674
622
|
def test_gasgn_nil
|
675
|
-
expected =
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
623
|
+
expected = s(:defn, :uses_gasgn,
|
624
|
+
s(:args),
|
625
|
+
s(:scope,
|
626
|
+
s(:block,
|
627
|
+
s(:gasgn, :$gvar, s(:lit, 5)),
|
628
|
+
s(:gasgn, :$gvar, s(:lit, 42)))))
|
681
629
|
|
682
630
|
@heckler.process(@heckler.current_tree)
|
683
631
|
@heckler.reset_tree
|
@@ -690,29 +638,29 @@ end
|
|
690
638
|
class TestHeckleLasgn < HeckleTestCase
|
691
639
|
|
692
640
|
def setup
|
693
|
-
@nodes =
|
641
|
+
@nodes = s(:lasgn)
|
694
642
|
super
|
695
643
|
end
|
696
644
|
|
697
645
|
def test_lasgn_val
|
698
|
-
expected =
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
646
|
+
expected = s(:defn, :uses_lasgn,
|
647
|
+
s(:args),
|
648
|
+
s(:scope,
|
649
|
+
s(:block,
|
650
|
+
s(:lasgn, :lvar, s(:nil)),
|
651
|
+
s(:lasgn, :lvar, s(:nil)))))
|
704
652
|
|
705
653
|
@heckler.process(@heckler.current_tree)
|
706
654
|
assert_equal expected, @heckler.current_tree
|
707
655
|
end
|
708
656
|
|
709
657
|
def test_lasgn_nil
|
710
|
-
expected =
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
658
|
+
expected = s(:defn, :uses_lasgn,
|
659
|
+
s(:args),
|
660
|
+
s(:scope,
|
661
|
+
s(:block,
|
662
|
+
s(:lasgn, :lvar, s(:lit, 5)),
|
663
|
+
s(:lasgn, :lvar, s(:lit, 42)))))
|
716
664
|
|
717
665
|
@heckler.process(@heckler.current_tree)
|
718
666
|
@heckler.reset_tree
|
@@ -725,21 +673,21 @@ end
|
|
725
673
|
class TestHeckleMasgn < HeckleTestCase
|
726
674
|
|
727
675
|
def setup
|
728
|
-
@nodes =
|
676
|
+
@nodes = s(:dasgn, :dasgn_curr, :iasgn, :gasgn, :lasgn)
|
729
677
|
super
|
730
678
|
end
|
731
679
|
|
732
680
|
def test_masgn
|
733
|
-
expected =
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
681
|
+
expected = s(:defn, :uses_masgn,
|
682
|
+
s(:args),
|
683
|
+
s(:scope,
|
684
|
+
s(:block,
|
685
|
+
s(:masgn,
|
686
|
+
s(:array,
|
687
|
+
s(:lasgn, :_heckle_dummy),
|
688
|
+
s(:gasgn, :$b),
|
689
|
+
s(:lasgn, :c)),
|
690
|
+
s(:array, s(:lit, 5), s(:lit, 6), s(:lit, 7))))))
|
743
691
|
|
744
692
|
@heckler.process(@heckler.current_tree)
|
745
693
|
assert_equal expected, @heckler.current_tree
|
@@ -747,3 +695,43 @@ class TestHeckleMasgn < HeckleTestCase
|
|
747
695
|
|
748
696
|
end
|
749
697
|
|
698
|
+
class TestHeckleIter < HeckleTestCase
|
699
|
+
def setup
|
700
|
+
@nodes = [ :call, :lasgn ]
|
701
|
+
super
|
702
|
+
end
|
703
|
+
|
704
|
+
def test_iter
|
705
|
+
expected = s(:defn, :uses_iter,
|
706
|
+
s(:args),
|
707
|
+
s(:scope,
|
708
|
+
s(:block,
|
709
|
+
s(:lasgn, :x, s(:nil)),
|
710
|
+
s(:iter,
|
711
|
+
s(:call, s(:lvar, :x), :each, s(:arglist)),
|
712
|
+
s(:lasgn, :y),
|
713
|
+
s(:lvar, :y)))))
|
714
|
+
|
715
|
+
# This call causes the replacement of [:lasgn, :x...] above to
|
716
|
+
# become [:lasgn, :nil]. We then reset the tree to ensure that
|
717
|
+
# the original method is maintained. We are really trying to test
|
718
|
+
# the reset_tree method here, not the actual changes.
|
719
|
+
|
720
|
+
@heckler.process(@heckler.current_tree)
|
721
|
+
assert_equal(expected, @heckler.current_tree)
|
722
|
+
|
723
|
+
@heckler.reset_tree
|
724
|
+
expected = s(:defn, :uses_iter,
|
725
|
+
s(:args),
|
726
|
+
s(:scope,
|
727
|
+
s(:block,
|
728
|
+
s(:lasgn, :x, s(:array, s(:lit, 1), s(:lit, 2), s(:lit, 3))),
|
729
|
+
s(:iter,
|
730
|
+
s(:call, s(:lvar, :x), :each, s(:arglist)),
|
731
|
+
s(:lasgn, :_heckle_dummy),
|
732
|
+
s(:call, nil, :y, s(:arglist))))))
|
733
|
+
|
734
|
+
@heckler.process(@heckler.current_tree)
|
735
|
+
assert_equal(expected, @heckler.current_tree)
|
736
|
+
end
|
737
|
+
end
|