heckle 1.4.3 → 2.0.0.b1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.autotest +4 -2
- data/.gemtest +0 -0
- data/History.txt +16 -0
- data/Manifest.txt +9 -1
- data/README.txt +5 -4
- data/Rakefile +13 -13
- data/bin/heckle +5 -93
- data/lib/heckle.rb +122 -16
- data/lib/heckle_runner.rb +113 -0
- data/lib/minitest_heckler.rb +33 -0
- data/lib/test_unit_heckler.rb +0 -1
- data/test/fixtures/heckle_dummy.rb +200 -0
- data/test/fixtures/heckled.rb +4 -0
- data/test/fixtures/minitest_project/README.txt +57 -0
- data/test/fixtures/minitest_project/Rakefile +17 -0
- data/test/fixtures/minitest_project/lib/doubler.rb +9 -0
- data/test/fixtures/minitest_project/test/test_doubler_with_a_number.rb +12 -0
- data/test/fixtures/minitest_project/test/test_doubler_with_bad_input.rb +16 -0
- data/test/test_heckle.rb +634 -356
- data/test/test_heckle_runner.rb +54 -0
- metadata +117 -42
- metadata.gz.sig +0 -0
- data/sample/lib/heckled.rb +0 -80
@@ -0,0 +1,33 @@
|
|
1
|
+
class MiniTestHeckler < Heckle
|
2
|
+
def initialize(class_or_module, method, options)
|
3
|
+
Dir.glob(options[:test_pattern]).each {|t| load File.expand_path(t) }
|
4
|
+
|
5
|
+
super(class_or_module, method, options[:nodes])
|
6
|
+
end
|
7
|
+
|
8
|
+
def tests_pass?
|
9
|
+
silence do
|
10
|
+
MiniTest::Unit.runner = nil
|
11
|
+
|
12
|
+
MiniTest::Unit.new.run
|
13
|
+
|
14
|
+
runner = MiniTest::Unit.runner
|
15
|
+
|
16
|
+
runner.failures == 0 && runner.errors == 0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# TODO: Windows.
|
21
|
+
def silence
|
22
|
+
return yield if Heckle.debug
|
23
|
+
|
24
|
+
begin
|
25
|
+
original = MiniTest::Unit.output
|
26
|
+
MiniTest::Unit.output = File.open("/dev/null", "w")
|
27
|
+
|
28
|
+
yield
|
29
|
+
ensure
|
30
|
+
MiniTest::Unit.output = original
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/test_unit_heckler.rb
CHANGED
@@ -0,0 +1,200 @@
|
|
1
|
+
class HeckleDummy
|
2
|
+
attr_accessor :names
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@names = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def uses_call
|
9
|
+
some_func + some_other_func
|
10
|
+
end
|
11
|
+
|
12
|
+
def uses_callblock
|
13
|
+
x.y { 1 }
|
14
|
+
end
|
15
|
+
|
16
|
+
def uses_cvasgn
|
17
|
+
@@cvar = 5
|
18
|
+
@@cvar = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def uses_dasgn
|
22
|
+
loop do |dvar|
|
23
|
+
loop do
|
24
|
+
dvar = 5
|
25
|
+
dvar = nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def uses_dasgncurr
|
31
|
+
loop do |dvar|
|
32
|
+
dvar = 5
|
33
|
+
dvar = nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def uses_iasgn
|
38
|
+
@ivar = 5
|
39
|
+
@ivar = nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def uses_gasgn
|
43
|
+
$gvar = 5
|
44
|
+
$gvar = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def uses_lasgn
|
48
|
+
lvar = 5
|
49
|
+
lvar = nil
|
50
|
+
end
|
51
|
+
|
52
|
+
def uses_masgn
|
53
|
+
@a, $b, c = 5, 6, 7
|
54
|
+
end
|
55
|
+
|
56
|
+
def uses_many_things
|
57
|
+
i = 1
|
58
|
+
while i < 10
|
59
|
+
i += 1
|
60
|
+
until some_func
|
61
|
+
some_other_func
|
62
|
+
end
|
63
|
+
return true if "hi there" == "changeling"
|
64
|
+
return false
|
65
|
+
end
|
66
|
+
i
|
67
|
+
end
|
68
|
+
|
69
|
+
def uses_while
|
70
|
+
while some_func
|
71
|
+
some_other_func
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def uses_until
|
76
|
+
until some_func
|
77
|
+
some_other_func
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def uses_numeric_literals
|
82
|
+
i = 1
|
83
|
+
i += 2147483648
|
84
|
+
i -= 3.5
|
85
|
+
end
|
86
|
+
|
87
|
+
def uses_strings
|
88
|
+
@names << "Hello, Robert"
|
89
|
+
@names << "Hello, Jeff"
|
90
|
+
@names << "Hi, Frank"
|
91
|
+
end
|
92
|
+
|
93
|
+
def uses_different_types
|
94
|
+
i = 1
|
95
|
+
b = "Hello, Joe"
|
96
|
+
c = 3.3
|
97
|
+
end
|
98
|
+
|
99
|
+
def uses_literal
|
100
|
+
i = 1
|
101
|
+
end
|
102
|
+
|
103
|
+
def uses_same_literal
|
104
|
+
i = 1
|
105
|
+
i = 1
|
106
|
+
i = 1
|
107
|
+
end
|
108
|
+
|
109
|
+
def uses_if
|
110
|
+
if some_func
|
111
|
+
if some_other_func
|
112
|
+
return
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def uses_boolean
|
118
|
+
a = true
|
119
|
+
b = false
|
120
|
+
end
|
121
|
+
|
122
|
+
def uses_unless
|
123
|
+
unless true
|
124
|
+
if false
|
125
|
+
return
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def uses_symbols
|
131
|
+
i = :blah
|
132
|
+
i = :blah
|
133
|
+
i = :and_blah
|
134
|
+
end
|
135
|
+
|
136
|
+
def uses_regexes
|
137
|
+
i = /a.*/
|
138
|
+
i = /c{2,4}+/
|
139
|
+
i = /123/
|
140
|
+
end
|
141
|
+
|
142
|
+
def uses_ranges
|
143
|
+
i = 6..100
|
144
|
+
i = -1..9
|
145
|
+
i = 1..4
|
146
|
+
end
|
147
|
+
|
148
|
+
def uses_nothing
|
149
|
+
end
|
150
|
+
|
151
|
+
def uses_iter
|
152
|
+
x = [ 1, 2, 3 ]
|
153
|
+
x.each { |y| y }
|
154
|
+
end
|
155
|
+
|
156
|
+
def self.is_a_klass_method?
|
157
|
+
true
|
158
|
+
end
|
159
|
+
|
160
|
+
module OuterNesting
|
161
|
+
def foo
|
162
|
+
-1
|
163
|
+
end
|
164
|
+
|
165
|
+
module InnerNesting
|
166
|
+
def foo
|
167
|
+
-2
|
168
|
+
end
|
169
|
+
|
170
|
+
class InnerClass
|
171
|
+
def bar
|
172
|
+
-1
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
module InnerNesting
|
178
|
+
def foo
|
179
|
+
-3
|
180
|
+
end
|
181
|
+
|
182
|
+
class InnerClass
|
183
|
+
module DecoyNesting
|
184
|
+
def foo
|
185
|
+
-4
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def foo
|
190
|
+
1337
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
private
|
197
|
+
|
198
|
+
def some_func; end
|
199
|
+
def some_other_func; end
|
200
|
+
end
|
data/test/fixtures/heckled.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
= minitest_project
|
2
|
+
|
3
|
+
* FIX (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
FIX (describe your package)
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== DEVELOPERS:
|
26
|
+
|
27
|
+
After checking out the source, run:
|
28
|
+
|
29
|
+
$ rake newb
|
30
|
+
|
31
|
+
This task will install any missing dependencies, run the tests/specs,
|
32
|
+
and generate the RDoc.
|
33
|
+
|
34
|
+
== LICENSE:
|
35
|
+
|
36
|
+
(The MIT License)
|
37
|
+
|
38
|
+
Copyright (c) 2012 FIX
|
39
|
+
|
40
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
41
|
+
a copy of this software and associated documentation files (the
|
42
|
+
'Software'), to deal in the Software without restriction, including
|
43
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
44
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
45
|
+
permit persons to whom the Software is furnished to do so, subject to
|
46
|
+
the following conditions:
|
47
|
+
|
48
|
+
The above copyright notice and this permission notice shall be
|
49
|
+
included in all copies or substantial portions of the Software.
|
50
|
+
|
51
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
52
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
53
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
54
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
55
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
56
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
57
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
Rake::TestTask.new
|
4
|
+
|
5
|
+
namespace :heckle do
|
6
|
+
desc "Run heckle with all tests."
|
7
|
+
task :pass do
|
8
|
+
puts `../../../bin/heckle Doubler double`
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Run heckle with some test."
|
12
|
+
task :fail do
|
13
|
+
puts `../../../bin/heckle Doubler double --tests test/test_doubler_with_a_number.rb`
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
task :default => :test
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "doubler"
|
3
|
+
|
4
|
+
class TestDoublerWithBadInput < MiniTest::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@doubler = Doubler.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_doubler_with_a_string
|
10
|
+
assert_equal "NaN", @doubler.double("2")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_doubler_with_nil
|
14
|
+
assert_equal "NaN", @doubler.double(nil)
|
15
|
+
end
|
16
|
+
end
|
data/test/test_heckle.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require 'test/unit/testcase'
|
5
|
-
require 'test/unit' if $0 == __FILE__
|
6
|
-
require 'test_unit_heckler'
|
7
|
-
require 'heckled'
|
1
|
+
require 'fixtures/heckle_dummy'
|
2
|
+
require 'heckle'
|
8
3
|
|
9
4
|
class TestHeckler < Heckle
|
10
5
|
def rand(*args)
|
@@ -22,60 +17,44 @@ class TestHeckler < Heckle
|
|
22
17
|
def rand_symbol
|
23
18
|
:"l33t h4x0r"
|
24
19
|
end
|
25
|
-
end
|
26
20
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
alias :refute_equal :assert_not_equal
|
21
|
+
# HAX
|
22
|
+
def expand_dirs_to_files(*)
|
23
|
+
super('test/fixtures/heckle_dummy.rb')
|
31
24
|
end
|
25
|
+
end
|
32
26
|
|
27
|
+
class HeckleTestCase < MiniTest::Unit::TestCase
|
33
28
|
def setup
|
29
|
+
@klass ||= "HeckleDummy"
|
34
30
|
@nodes ||= Heckle::MUTATABLE_NODES
|
35
|
-
|
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
|
31
|
+
@method_heckled ||= 'uses_many_things'
|
41
32
|
|
42
|
-
@heckler = TestHeckler.new(
|
33
|
+
@heckler = TestHeckler.new(@klass, @method_heckled, @nodes)
|
43
34
|
end
|
44
35
|
|
45
36
|
def teardown
|
46
37
|
@heckler.reset if defined?(@heckler) && @heckler
|
47
38
|
end
|
48
|
-
end
|
49
|
-
|
50
|
-
class LiteralHeckleTestCase < HeckleTestCase
|
51
|
-
def setup
|
52
|
-
@nodes = s(:lit, :str)
|
53
|
-
super
|
54
|
-
end
|
55
|
-
|
56
|
-
def toggle(value, toggle)
|
57
|
-
toggle ? self.class::TOGGLE_VALUE : value
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_default_structure
|
61
|
-
return if self.class == LiteralHeckleTestCase
|
62
|
-
assert_equal util_expected, @heckler.current_tree
|
63
|
-
end
|
64
39
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
assert_equal util_expected(1), @heckler.current_tree
|
40
|
+
def assert_mutations expected, heckle
|
41
|
+
initial = heckle.current_tree.deep_clone
|
42
|
+
mutations = []
|
69
43
|
|
70
|
-
|
44
|
+
begin
|
45
|
+
heckle.process(heckle.current_tree)
|
46
|
+
mutant = heckle.current_tree
|
47
|
+
mutations << mutant
|
48
|
+
heckle.reset_tree
|
49
|
+
end until initial == mutant
|
71
50
|
|
72
|
-
|
73
|
-
assert_equal util_expected(2), @heckler.current_tree
|
51
|
+
mutations.delete(initial)
|
74
52
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
53
|
+
# HAX: Sorting an array of Sexps blows up in some cases.
|
54
|
+
assert_equal expected.map {|sexp| sexp.to_s }.sort,
|
55
|
+
mutations.map {|sexp| sexp.to_s }.sort,
|
56
|
+
[ "expected(#{expected.size}):", (expected - mutations).map {|m| m.pretty_inspect},
|
57
|
+
"mutations(#{mutations.size}):", (mutations - expected).map {|m| m.pretty_inspect} ].join("\n")
|
79
58
|
end
|
80
59
|
end
|
81
60
|
|
@@ -212,99 +191,306 @@ class TestHeckle < HeckleTestCase
|
|
212
191
|
end
|
213
192
|
|
214
193
|
class TestHeckleNumericLiterals < HeckleTestCase
|
215
|
-
def
|
216
|
-
|
194
|
+
def setup
|
195
|
+
@method_heckled = "uses_numeric_literals"
|
196
|
+
@nodes = s(:lit, :str)
|
197
|
+
super
|
217
198
|
end
|
218
199
|
|
219
|
-
def
|
220
|
-
s(:defn, :uses_numeric_literals,
|
200
|
+
def test_numeric_literals_original_tree
|
201
|
+
expected = s(:defn, :uses_numeric_literals,
|
221
202
|
s(:args),
|
222
203
|
s(:scope,
|
223
204
|
s(:block,
|
224
|
-
s(:lasgn, :i, s(:lit,
|
205
|
+
s(:lasgn, :i, s(:lit, 1)),
|
225
206
|
s(:lasgn, :i, s(:call, s(:lvar, :i), :+,
|
226
|
-
s(:arglist, s(:lit,
|
227
|
-
s(:lasgn, :i, s(:call, s(:lvar, :i), :-, s(:arglist, s(:lit,
|
207
|
+
s(:arglist, s(:lit, 2147483648)))),
|
208
|
+
s(:lasgn, :i, s(:call, s(:lvar, :i), :-, s(:arglist, s(:lit, 3.5)))))))
|
209
|
+
|
210
|
+
assert_equal expected, @heckler.current_tree
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_numeric_literals_mutations
|
214
|
+
expected = [
|
215
|
+
s(:defn, :uses_numeric_literals,
|
216
|
+
s(:args),
|
217
|
+
s(:scope,
|
218
|
+
s(:block,
|
219
|
+
s(:lasgn, :i, s(:lit, 6)),
|
220
|
+
s(:lasgn, :i, s(:call, s(:lvar, :i), :+,
|
221
|
+
s(:arglist, s(:lit, 2147483648)))),
|
222
|
+
s(:lasgn, :i, s(:call, s(:lvar, :i), :-, s(:arglist, s(:lit, 3.5))))))),
|
223
|
+
s(:defn, :uses_numeric_literals,
|
224
|
+
s(:args),
|
225
|
+
s(:scope,
|
226
|
+
s(:block,
|
227
|
+
s(:lasgn, :i, s(:lit, 1)),
|
228
|
+
s(:lasgn, :i, s(:call, s(:lvar, :i), :+,
|
229
|
+
s(:arglist, s(:lit, 2147483653)))),
|
230
|
+
s(:lasgn, :i, s(:call, s(:lvar, :i), :-, s(:arglist, s(:lit, 3.5))))))),
|
231
|
+
s(:defn, :uses_numeric_literals,
|
232
|
+
s(:args),
|
233
|
+
s(:scope,
|
234
|
+
s(:block,
|
235
|
+
s(:lasgn, :i, s(:lit, 1)),
|
236
|
+
s(:lasgn, :i, s(:call, s(:lvar, :i), :+,
|
237
|
+
s(:arglist, s(:lit, 2147483648)))),
|
238
|
+
s(:lasgn, :i, s(:call, s(:lvar, :i), :-, s(:arglist, s(:lit, 8.5))))))),
|
239
|
+
]
|
240
|
+
|
241
|
+
assert_mutations expected, @heckler
|
228
242
|
end
|
229
243
|
end
|
230
244
|
|
231
|
-
class TestHeckleSymbols <
|
232
|
-
|
245
|
+
class TestHeckleSymbols < HeckleTestCase
|
246
|
+
def setup
|
247
|
+
@method_heckled = "uses_symbols"
|
248
|
+
@nodes = s(:lit, :str)
|
249
|
+
super
|
250
|
+
end
|
233
251
|
|
234
|
-
def
|
235
|
-
s(:defn, :uses_symbols,
|
252
|
+
def test_symbols_original_tree
|
253
|
+
expected = s(:defn, :uses_symbols,
|
236
254
|
s(:args),
|
237
255
|
s(:scope,
|
238
256
|
s(:block,
|
239
|
-
s(:lasgn, :i, s(:lit,
|
240
|
-
s(:lasgn, :i, s(:lit,
|
241
|
-
s(:lasgn, :i, s(:lit,
|
257
|
+
s(:lasgn, :i, s(:lit, :blah)),
|
258
|
+
s(:lasgn, :i, s(:lit, :blah)),
|
259
|
+
s(:lasgn, :i, s(:lit, :and_blah)))))
|
260
|
+
|
261
|
+
assert_equal expected, @heckler.current_tree
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_symbols_mutations
|
265
|
+
expected = [
|
266
|
+
s(:defn, :uses_symbols,
|
267
|
+
s(:args),
|
268
|
+
s(:scope,
|
269
|
+
s(:block,
|
270
|
+
s(:lasgn, :i, s(:lit, :"l33t h4x0r")),
|
271
|
+
s(:lasgn, :i, s(:lit, :blah)),
|
272
|
+
s(:lasgn, :i, s(:lit, :and_blah))))),
|
273
|
+
s(:defn, :uses_symbols,
|
274
|
+
s(:args),
|
275
|
+
s(:scope,
|
276
|
+
s(:block,
|
277
|
+
s(:lasgn, :i, s(:lit, :blah)),
|
278
|
+
s(:lasgn, :i, s(:lit, :"l33t h4x0r")),
|
279
|
+
s(:lasgn, :i, s(:lit, :and_blah))))),
|
280
|
+
s(:defn, :uses_symbols,
|
281
|
+
s(:args),
|
282
|
+
s(:scope,
|
283
|
+
s(:block,
|
284
|
+
s(:lasgn, :i, s(:lit, :blah)),
|
285
|
+
s(:lasgn, :i, s(:lit, :blah)),
|
286
|
+
s(:lasgn, :i, s(:lit, :"l33t h4x0r"))))),
|
287
|
+
]
|
288
|
+
|
289
|
+
assert_mutations expected, @heckler
|
242
290
|
end
|
243
291
|
end
|
244
292
|
|
245
|
-
class TestHeckleRegexes <
|
246
|
-
|
293
|
+
class TestHeckleRegexes < HeckleTestCase
|
294
|
+
def setup
|
295
|
+
@method_heckled = "uses_regexes"
|
296
|
+
@nodes = s(:lit, :str)
|
297
|
+
super
|
298
|
+
end
|
247
299
|
|
248
|
-
def
|
249
|
-
s(:defn, :uses_regexes,
|
300
|
+
def test_regexes_original_tree
|
301
|
+
expected = s(:defn, :uses_regexes,
|
250
302
|
s(:args),
|
251
303
|
s(:scope,
|
252
304
|
s(:block,
|
253
|
-
s(:lasgn, :i, s(:lit,
|
254
|
-
s(:lasgn, :i, s(:lit,
|
255
|
-
s(:lasgn, :i, s(:lit,
|
305
|
+
s(:lasgn, :i, s(:lit, /a.*/)),
|
306
|
+
s(:lasgn, :i, s(:lit, /c{2,4}+/)),
|
307
|
+
s(:lasgn, :i, s(:lit, /123/)))))
|
308
|
+
|
309
|
+
assert_equal expected, @heckler.original_tree
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_regexes_mutuations
|
313
|
+
expected = [
|
314
|
+
s(:defn, :uses_regexes,
|
315
|
+
s(:args),
|
316
|
+
s(:scope,
|
317
|
+
s(:block,
|
318
|
+
s(:lasgn, :i, s(:lit, /l33t\ h4x0r/)),
|
319
|
+
s(:lasgn, :i, s(:lit, /c{2,4}+/)),
|
320
|
+
s(:lasgn, :i, s(:lit, /123/))))),
|
321
|
+
s(:defn, :uses_regexes,
|
322
|
+
s(:args),
|
323
|
+
s(:scope,
|
324
|
+
s(:block,
|
325
|
+
s(:lasgn, :i, s(:lit, /a.*/)),
|
326
|
+
s(:lasgn, :i, s(:lit, /l33t\ h4x0r/)),
|
327
|
+
s(:lasgn, :i, s(:lit, /123/))))),
|
328
|
+
s(:defn, :uses_regexes,
|
329
|
+
s(:args),
|
330
|
+
s(:scope,
|
331
|
+
s(:block,
|
332
|
+
s(:lasgn, :i, s(:lit, /a.*/)),
|
333
|
+
s(:lasgn, :i, s(:lit, /c{2,4}+/)),
|
334
|
+
s(:lasgn, :i, s(:lit, /l33t\ h4x0r/))))),
|
335
|
+
]
|
336
|
+
|
337
|
+
assert_mutations expected, @heckler
|
256
338
|
end
|
257
339
|
end
|
258
340
|
|
259
|
-
class TestHeckleRanges <
|
260
|
-
|
341
|
+
class TestHeckleRanges < HeckleTestCase
|
342
|
+
def setup
|
343
|
+
@method_heckled = "uses_ranges"
|
344
|
+
@nodes = s(:lit, :str)
|
345
|
+
super
|
346
|
+
end
|
261
347
|
|
262
|
-
def
|
263
|
-
s(:defn, :uses_ranges,
|
348
|
+
def test_ranges_original_tree
|
349
|
+
expected = s(:defn, :uses_ranges,
|
264
350
|
s(:args),
|
265
351
|
s(:scope,
|
266
352
|
s(:block,
|
267
|
-
s(:lasgn, :i, s(:lit,
|
268
|
-
s(:lasgn, :i, s(:lit,
|
269
|
-
s(:lasgn, :i, s(:lit,
|
353
|
+
s(:lasgn, :i, s(:lit, 6..100)),
|
354
|
+
s(:lasgn, :i, s(:lit, -1..9)),
|
355
|
+
s(:lasgn, :i, s(:lit, 1..4)))))
|
356
|
+
|
357
|
+
assert_equal expected, @heckler.current_tree
|
358
|
+
end
|
359
|
+
|
360
|
+
def test_ranges_mutations
|
361
|
+
expected = [
|
362
|
+
s(:defn, :uses_ranges,
|
363
|
+
s(:args),
|
364
|
+
s(:scope,
|
365
|
+
s(:block,
|
366
|
+
s(:lasgn, :i, s(:lit, 5..10)),
|
367
|
+
s(:lasgn, :i, s(:lit, -1..9)),
|
368
|
+
s(:lasgn, :i, s(:lit, 1..4))))),
|
369
|
+
s(:defn, :uses_ranges,
|
370
|
+
s(:args),
|
371
|
+
s(:scope,
|
372
|
+
s(:block,
|
373
|
+
s(:lasgn, :i, s(:lit, 6..100)),
|
374
|
+
s(:lasgn, :i, s(:lit, 5..10)),
|
375
|
+
s(:lasgn, :i, s(:lit, 1..4))))),
|
376
|
+
s(:defn, :uses_ranges,
|
377
|
+
s(:args),
|
378
|
+
s(:scope,
|
379
|
+
s(:block,
|
380
|
+
s(:lasgn, :i, s(:lit, 6..100)),
|
381
|
+
s(:lasgn, :i, s(:lit, -1..9)),
|
382
|
+
s(:lasgn, :i, s(:lit, 5..10))))),
|
383
|
+
]
|
384
|
+
|
385
|
+
assert_mutations expected, @heckler
|
386
|
+
|
270
387
|
end
|
271
388
|
end
|
272
389
|
|
273
|
-
class TestHeckleSameLiteral <
|
274
|
-
|
390
|
+
class TestHeckleSameLiteral < HeckleTestCase
|
391
|
+
def setup
|
392
|
+
@method_heckled = "uses_same_literal"
|
393
|
+
@nodes = s(:lit, :str)
|
394
|
+
super
|
395
|
+
end
|
275
396
|
|
276
|
-
def
|
277
|
-
s(:defn, :uses_same_literal,
|
397
|
+
def test_same_literal_original_tree
|
398
|
+
expected = s(:defn, :uses_same_literal,
|
278
399
|
s(:args),
|
279
400
|
s(:scope,
|
280
401
|
s(:block,
|
281
|
-
s(:lasgn, :i, s(:lit,
|
282
|
-
s(:lasgn, :i, s(:lit,
|
283
|
-
s(:lasgn, :i, s(:lit,
|
402
|
+
s(:lasgn, :i, s(:lit, 1)),
|
403
|
+
s(:lasgn, :i, s(:lit, 1)),
|
404
|
+
s(:lasgn, :i, s(:lit, 1)))))
|
405
|
+
|
406
|
+
assert_equal expected, @heckler.current_tree
|
407
|
+
end
|
408
|
+
|
409
|
+
def test_same_literal_mutations
|
410
|
+
expected = [
|
411
|
+
s(:defn, :uses_same_literal,
|
412
|
+
s(:args),
|
413
|
+
s(:scope,
|
414
|
+
s(:block,
|
415
|
+
s(:lasgn, :i, s(:lit, 6)),
|
416
|
+
s(:lasgn, :i, s(:lit, 1)),
|
417
|
+
s(:lasgn, :i, s(:lit, 1))))),
|
418
|
+
s(:defn, :uses_same_literal,
|
419
|
+
s(:args),
|
420
|
+
s(:scope,
|
421
|
+
s(:block,
|
422
|
+
s(:lasgn, :i, s(:lit, 1)),
|
423
|
+
s(:lasgn, :i, s(:lit, 6)),
|
424
|
+
s(:lasgn, :i, s(:lit, 1))))),
|
425
|
+
s(:defn, :uses_same_literal,
|
426
|
+
s(:args),
|
427
|
+
s(:scope,
|
428
|
+
s(:block,
|
429
|
+
s(:lasgn, :i, s(:lit, 1)),
|
430
|
+
s(:lasgn, :i, s(:lit, 1)),
|
431
|
+
s(:lasgn, :i, s(:lit, 6))))),
|
432
|
+
]
|
433
|
+
|
434
|
+
assert_mutations expected, @heckler
|
284
435
|
end
|
285
436
|
end
|
286
437
|
|
287
|
-
class TestHeckleStrings <
|
288
|
-
|
438
|
+
class TestHeckleStrings < HeckleTestCase
|
439
|
+
def setup
|
440
|
+
@method_heckled = "uses_strings"
|
441
|
+
@nodes = s(:lit, :str)
|
442
|
+
super
|
443
|
+
end
|
289
444
|
|
290
|
-
def
|
291
|
-
s(:defn, :uses_strings,
|
445
|
+
def test_strings_original_tree
|
446
|
+
expected = s(:defn, :uses_strings,
|
292
447
|
s(:args),
|
293
448
|
s(:scope,
|
294
449
|
s(:block,
|
295
|
-
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str,
|
296
|
-
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str,
|
297
|
-
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str,
|
450
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, "Hello, Robert"))),
|
451
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, "Hello, Jeff"))),
|
452
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, "Hi, Frank"))))))
|
453
|
+
|
454
|
+
assert_equal expected, @heckler.current_tree
|
455
|
+
end
|
456
|
+
|
457
|
+
def test_strings_mutations
|
458
|
+
expected = [
|
459
|
+
s(:defn, :uses_strings,
|
460
|
+
s(:args),
|
461
|
+
s(:scope,
|
462
|
+
s(:block,
|
463
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, "l33t h4x0r"))),
|
464
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, "Hello, Jeff"))),
|
465
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, "Hi, Frank")))))),
|
466
|
+
s(:defn, :uses_strings,
|
467
|
+
s(:args),
|
468
|
+
s(:scope,
|
469
|
+
s(:block,
|
470
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, "Hello, Robert"))),
|
471
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, "l33t h4x0r"))),
|
472
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, "Hi, Frank")))))),
|
473
|
+
s(:defn, :uses_strings,
|
474
|
+
s(:args),
|
475
|
+
s(:scope,
|
476
|
+
s(:block,
|
477
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, "Hello, Robert"))),
|
478
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, "Hello, Jeff"))),
|
479
|
+
s(:call, s(:ivar, :@names), :<<, s(:arglist, s(:str, "l33t h4x0r")))))),
|
480
|
+
]
|
481
|
+
|
482
|
+
assert_mutations expected, @heckler
|
298
483
|
end
|
299
484
|
end
|
300
485
|
|
301
486
|
class TestHeckleIf < HeckleTestCase
|
302
487
|
def setup
|
488
|
+
@method_heckled = "uses_if"
|
303
489
|
@nodes = s(:if)
|
304
490
|
super
|
305
491
|
end
|
306
492
|
|
307
|
-
def
|
493
|
+
def test_if_original_tree
|
308
494
|
expected = s(:defn, :uses_if,
|
309
495
|
s(:args),
|
310
496
|
s(:scope,
|
@@ -317,421 +503,513 @@ class TestHeckleIf < HeckleTestCase
|
|
317
503
|
assert_equal expected, @heckler.current_tree
|
318
504
|
end
|
319
505
|
|
320
|
-
def
|
321
|
-
expected =
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
@heckler.process(@heckler.current_tree)
|
345
|
-
assert_equal expected, @heckler.current_tree
|
506
|
+
def test_if_mutations
|
507
|
+
expected = [
|
508
|
+
s(:defn,
|
509
|
+
:uses_if,
|
510
|
+
s(:args),
|
511
|
+
s(:scope,
|
512
|
+
s(:block,
|
513
|
+
s(:if,
|
514
|
+
s(:call, nil, :some_func, s(:arglist)),
|
515
|
+
nil,
|
516
|
+
s(:if, s(:call, nil, :some_other_func, s(:arglist)), s(:return), nil))))),
|
517
|
+
s(:defn,
|
518
|
+
:uses_if,
|
519
|
+
s(:args),
|
520
|
+
s(:scope,
|
521
|
+
s(:block,
|
522
|
+
s(:if,
|
523
|
+
s(:call, nil, :some_func, s(:arglist)),
|
524
|
+
s(:if, s(:call, nil, :some_other_func, s(:arglist)), nil, s(:return)),
|
525
|
+
nil))))
|
526
|
+
]
|
527
|
+
|
528
|
+
assert_mutations expected, @heckler
|
346
529
|
end
|
347
530
|
end
|
348
531
|
|
349
532
|
class TestHeckleBoolean < HeckleTestCase
|
350
|
-
|
351
533
|
def setup
|
534
|
+
@method_heckled = "uses_boolean"
|
352
535
|
@nodes = s(:true, :false)
|
353
536
|
super
|
354
537
|
end
|
355
538
|
|
356
|
-
def
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
s(:scope,
|
364
|
-
s(:block,
|
365
|
-
s(:lasgn, :a, s(toggle(true, n == 1))),
|
366
|
-
s(:lasgn, :b, s(toggle(false, n == 2))))))
|
367
|
-
end
|
539
|
+
def test_boolean_original_tree
|
540
|
+
expected = s(:defn, :uses_boolean,
|
541
|
+
s(:args),
|
542
|
+
s(:scope,
|
543
|
+
s(:block,
|
544
|
+
s(:lasgn, :a, s(:true)),
|
545
|
+
s(:lasgn, :b, s(:false)))))
|
368
546
|
|
369
|
-
|
370
|
-
assert_equal util_expected, @heckler.current_tree
|
547
|
+
assert_equal expected, @heckler.current_tree
|
371
548
|
end
|
372
549
|
|
373
|
-
def
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
550
|
+
def test_boolean_mutations
|
551
|
+
expected = [
|
552
|
+
s(:defn, :uses_boolean,
|
553
|
+
s(:args),
|
554
|
+
s(:scope,
|
555
|
+
s(:block,
|
556
|
+
s(:lasgn, :a, s(:false)),
|
557
|
+
s(:lasgn, :b, s(:false))))),
|
558
|
+
s(:defn, :uses_boolean,
|
559
|
+
s(:args),
|
560
|
+
s(:scope,
|
561
|
+
s(:block,
|
562
|
+
s(:lasgn, :a, s(:true)),
|
563
|
+
s(:lasgn, :b, s(:true))))),
|
564
|
+
]
|
565
|
+
|
566
|
+
assert_mutations expected, @heckler
|
381
567
|
end
|
382
568
|
end
|
383
569
|
|
384
570
|
class TestHeckleWhile < HeckleTestCase
|
385
571
|
def setup
|
572
|
+
@method_heckled = "uses_while"
|
386
573
|
@nodes = s(:while)
|
387
574
|
super
|
388
575
|
end
|
389
576
|
|
390
|
-
def
|
391
|
-
expected =
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
577
|
+
def test_while_original_tree
|
578
|
+
expected = s(:defn, :uses_while,
|
579
|
+
s(:args),
|
580
|
+
s(:scope,
|
581
|
+
s(:block,
|
582
|
+
s(:while, s(:call, nil, :some_func, s(:arglist)),
|
583
|
+
s(:call, nil, :some_other_func, s(:arglist)), true))))
|
584
|
+
|
397
585
|
assert_equal expected, @heckler.current_tree
|
398
586
|
end
|
399
587
|
|
400
|
-
def
|
401
|
-
expected =
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
588
|
+
def test_while_mutations
|
589
|
+
expected = [
|
590
|
+
s(:defn, :uses_while,
|
591
|
+
s(:args),
|
592
|
+
s(:scope,
|
593
|
+
s(:block,
|
594
|
+
s(:until, s(:call, nil, :some_func, s(:arglist)),
|
595
|
+
s(:call, nil, :some_other_func, s(:arglist)), true))))]
|
596
|
+
|
597
|
+
assert_mutations expected, @heckler
|
409
598
|
end
|
410
599
|
end
|
411
600
|
|
412
601
|
class TestHeckleUntil < HeckleTestCase
|
413
602
|
def setup
|
603
|
+
@method_heckled = "uses_until"
|
414
604
|
@nodes = s(:until)
|
415
605
|
super
|
416
606
|
end
|
417
607
|
|
418
|
-
def
|
419
|
-
expected =
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
608
|
+
def test_until_original_tree
|
609
|
+
expected = s(:defn, :uses_until,
|
610
|
+
s(:args),
|
611
|
+
s(:scope,
|
612
|
+
s(:block,
|
613
|
+
s(:until, s(:call, nil, :some_func, s(:arglist)),
|
614
|
+
s(:call, nil, :some_other_func, s(:arglist)), true))))
|
615
|
+
|
425
616
|
assert_equal expected, @heckler.current_tree
|
426
617
|
end
|
427
618
|
|
428
|
-
def
|
429
|
-
expected =
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
619
|
+
def test_until_mutations
|
620
|
+
expected = [
|
621
|
+
s(:defn, :uses_until,
|
622
|
+
s(:args),
|
623
|
+
s(:scope,
|
624
|
+
s(:block,
|
625
|
+
s(:while, s(:call, nil, :some_func, s(:arglist)),
|
626
|
+
s(:call, nil, :some_other_func, s(:arglist)), true))))]
|
627
|
+
|
628
|
+
assert_mutations expected, @heckler
|
437
629
|
end
|
438
630
|
end
|
439
631
|
|
440
632
|
class TestHeckleCall < HeckleTestCase
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
s(:args),
|
445
|
-
s(:scope,
|
446
|
-
s(:block,
|
447
|
-
s(:nil))))
|
448
|
-
|
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) # +
|
454
|
-
assert_equal expected, @heckler.current_tree
|
633
|
+
def setup
|
634
|
+
@method_heckled = "uses_call"
|
635
|
+
super
|
455
636
|
end
|
456
637
|
|
457
|
-
def
|
458
|
-
expected =
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
638
|
+
def test_call_original_tree
|
639
|
+
expected = s(:defn, :uses_call,
|
640
|
+
s(:args),
|
641
|
+
s(:scope,
|
642
|
+
s(:block,
|
643
|
+
s(:call,
|
644
|
+
s(:call, nil, :some_func, s(:arglist)),
|
645
|
+
:+,
|
646
|
+
s(:arglist, s(:call, nil, :some_other_func, s(:arglist)))))))
|
466
647
|
|
467
648
|
assert_equal expected, @heckler.current_tree
|
468
649
|
end
|
469
650
|
|
651
|
+
def test_call_mutations
|
652
|
+
expected = [
|
653
|
+
s(:defn, :uses_call,
|
654
|
+
s(:args),
|
655
|
+
s(:scope,
|
656
|
+
s(:block,
|
657
|
+
s(:call,
|
658
|
+
s(:call, nil, :some_func, s(:arglist)),
|
659
|
+
:+,
|
660
|
+
s(:arglist, s(:nil)))))),
|
661
|
+
s(:defn, :uses_call,
|
662
|
+
s(:args),
|
663
|
+
s(:scope,
|
664
|
+
s(:block,
|
665
|
+
s(:call,
|
666
|
+
s(:nil),
|
667
|
+
:+,
|
668
|
+
s(:arglist, s(:call, nil, :some_other_func, s(:arglist))))))),
|
669
|
+
s(:defn, :uses_call,
|
670
|
+
s(:args),
|
671
|
+
s(:scope,
|
672
|
+
s(:block,
|
673
|
+
s(:nil)))),
|
674
|
+
]
|
675
|
+
|
676
|
+
assert_mutations expected, @heckler
|
677
|
+
end
|
470
678
|
end
|
471
679
|
|
472
680
|
class TestHeckleCallblock < HeckleTestCase
|
473
|
-
|
474
681
|
def setup
|
682
|
+
@method_heckled = "uses_callblock"
|
475
683
|
@nodes = s(:call)
|
476
684
|
super
|
477
685
|
end
|
478
686
|
|
479
|
-
def
|
480
|
-
expected =
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
687
|
+
def test_callblock_original_tree
|
688
|
+
expected = s(:defn, :uses_callblock,
|
689
|
+
s(:args),
|
690
|
+
s(:scope,
|
691
|
+
s(:block,
|
692
|
+
s(:iter,
|
693
|
+
s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist)),
|
694
|
+
nil,
|
695
|
+
s(:lit, 1)))))
|
488
696
|
|
489
697
|
assert_equal expected, @heckler.current_tree
|
490
698
|
end
|
491
|
-
def
|
492
|
-
expected =
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
699
|
+
def test_callblock_mutations
|
700
|
+
expected = [
|
701
|
+
s(:defn, :uses_callblock,
|
702
|
+
s(:args),
|
703
|
+
s(:scope,
|
704
|
+
s(:block,
|
705
|
+
s(:iter,
|
706
|
+
s(:call, s(:nil), :y, s(:arglist)),
|
707
|
+
nil,
|
708
|
+
s(:lit, 1)))))
|
709
|
+
]
|
500
710
|
|
501
|
-
@heckler
|
502
|
-
assert_equal expected, @heckler.current_tree
|
711
|
+
assert_mutations expected, @heckler
|
503
712
|
end
|
504
713
|
end
|
505
714
|
|
506
715
|
class TestHeckleClassMethod < HeckleTestCase
|
507
716
|
def setup
|
508
|
-
@
|
717
|
+
@method_heckled = "self.is_a_klass_method?"
|
509
718
|
@nodes = s(:true)
|
510
719
|
super
|
511
720
|
end
|
512
721
|
|
513
|
-
def
|
514
|
-
expected =
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
722
|
+
def test_class_method_original_tree
|
723
|
+
expected = s(:defs, s(:self), :is_a_klass_method?,
|
724
|
+
s(:args),
|
725
|
+
s(:scope,
|
726
|
+
s(:block,
|
727
|
+
s(:true))))
|
728
|
+
|
519
729
|
assert_equal expected, @heckler.current_tree
|
520
730
|
end
|
521
731
|
|
522
|
-
def
|
523
|
-
expected =
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
732
|
+
def test_class_methods_mutations
|
733
|
+
expected = [
|
734
|
+
s(:defs, s(:self), :is_a_klass_method?,
|
735
|
+
s(:args),
|
736
|
+
s(:scope,
|
737
|
+
s(:block,
|
738
|
+
s(:false))))
|
739
|
+
]
|
740
|
+
|
741
|
+
assert_mutations expected, @heckler
|
530
742
|
end
|
531
743
|
end
|
532
744
|
|
533
745
|
class TestHeckleCvasgn < HeckleTestCase
|
534
|
-
|
535
746
|
def setup
|
747
|
+
@method_heckled = "uses_cvasgn"
|
536
748
|
@nodes = s(:cvasgn)
|
537
749
|
super
|
538
750
|
end
|
539
751
|
|
540
|
-
def
|
541
|
-
expected =
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
752
|
+
def test_cvasgn_original_tree
|
753
|
+
expected = s(:defn, :uses_cvasgn,
|
754
|
+
s(:args),
|
755
|
+
s(:scope,
|
756
|
+
s(:block,
|
757
|
+
s(:cvasgn, :@@cvar, s(:lit, 5)),
|
758
|
+
s(:cvasgn, :@@cvar, s(:nil)))))
|
547
759
|
|
548
|
-
@heckler.process(@heckler.current_tree)
|
549
760
|
assert_equal expected, @heckler.current_tree
|
550
761
|
end
|
551
762
|
|
552
|
-
def
|
553
|
-
expected =
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
763
|
+
def test_cvasgn_mutations
|
764
|
+
expected = [
|
765
|
+
s(:defn, :uses_cvasgn,
|
766
|
+
s(:args),
|
767
|
+
s(:scope,
|
768
|
+
s(:block,
|
769
|
+
s(:cvasgn, :@@cvar, s(:lit, 5)),
|
770
|
+
s(:cvasgn, :@@cvar, s(:lit, 42))))),
|
771
|
+
s(:defn, :uses_cvasgn,
|
772
|
+
s(:args),
|
773
|
+
s(:scope,
|
774
|
+
s(:block,
|
775
|
+
s(:cvasgn, :@@cvar, s(:nil)),
|
776
|
+
s(:cvasgn, :@@cvar, s(:nil))))),
|
777
|
+
]
|
778
|
+
|
779
|
+
assert_mutations expected, @heckler
|
564
780
|
end
|
565
|
-
|
566
781
|
end
|
567
782
|
|
568
783
|
class TestHeckleIasgn < HeckleTestCase
|
569
|
-
|
570
784
|
def setup
|
785
|
+
@method_heckled = "uses_iasgn"
|
571
786
|
@nodes = s(:iasgn)
|
572
787
|
super
|
573
788
|
end
|
574
789
|
|
575
|
-
def
|
576
|
-
expected =
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
790
|
+
def test_iasgn_original_tree
|
791
|
+
expected = s(:defn, :uses_iasgn,
|
792
|
+
s(:args),
|
793
|
+
s(:scope,
|
794
|
+
s(:block,
|
795
|
+
s(:iasgn, :@ivar, s(:lit, 5)),
|
796
|
+
s(:iasgn, :@ivar, s(:nil)))))
|
582
797
|
|
583
|
-
@heckler.process(@heckler.current_tree)
|
584
798
|
assert_equal expected, @heckler.current_tree
|
585
799
|
end
|
586
800
|
|
587
|
-
def
|
588
|
-
expected =
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
801
|
+
def test_iasgn_mutations
|
802
|
+
expected = [
|
803
|
+
s(:defn, :uses_iasgn,
|
804
|
+
s(:args),
|
805
|
+
s(:scope,
|
806
|
+
s(:block,
|
807
|
+
s(:iasgn, :@ivar, s(:lit, 5)),
|
808
|
+
s(:iasgn, :@ivar, s(:lit, 42))))),
|
809
|
+
s(:defn, :uses_iasgn,
|
810
|
+
s(:args),
|
811
|
+
s(:scope,
|
812
|
+
s(:block,
|
813
|
+
s(:iasgn, :@ivar, s(:nil)),
|
814
|
+
s(:iasgn, :@ivar, s(:nil))))),
|
815
|
+
]
|
594
816
|
|
595
|
-
@heckler
|
596
|
-
@heckler.reset_tree
|
597
|
-
@heckler.process(@heckler.current_tree)
|
598
|
-
assert_equal expected, @heckler.current_tree
|
817
|
+
assert_mutations expected, @heckler
|
599
818
|
end
|
600
819
|
|
601
820
|
end
|
602
821
|
|
603
822
|
class TestHeckleGasgn < HeckleTestCase
|
604
|
-
|
605
823
|
def setup
|
824
|
+
@method_heckled = "uses_gasgn"
|
825
|
+
s(:defn, :uses_cvasgn,
|
826
|
+
s(:args),
|
827
|
+
s(:scope,
|
828
|
+
s(:block,
|
829
|
+
s(:cvasgn, :@@cvar, s(:lit, 5)),
|
830
|
+
s(:cvasgn, :@@cvar, s(:lit, 42)))))
|
606
831
|
@nodes = s(:gasgn)
|
607
832
|
super
|
608
833
|
end
|
609
834
|
|
610
|
-
def
|
611
|
-
expected =
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
835
|
+
def test_gasgn_original_tree
|
836
|
+
expected = s(:defn, :uses_gasgn,
|
837
|
+
s(:args),
|
838
|
+
s(:scope,
|
839
|
+
s(:block,
|
840
|
+
s(:gasgn, :$gvar, s(:lit, 5)),
|
841
|
+
s(:gasgn, :$gvar, s(:nil)))))
|
617
842
|
|
618
|
-
@heckler.process(@heckler.current_tree)
|
619
843
|
assert_equal expected, @heckler.current_tree
|
620
844
|
end
|
621
845
|
|
622
|
-
def
|
623
|
-
expected =
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
846
|
+
def test_gasgn_mutations
|
847
|
+
expected = [
|
848
|
+
s(:defn, :uses_gasgn,
|
849
|
+
s(:args),
|
850
|
+
s(:scope,
|
851
|
+
s(:block,
|
852
|
+
s(:gasgn, :$gvar, s(:lit, 5)),
|
853
|
+
s(:gasgn, :$gvar, s(:lit, 42))))),
|
854
|
+
s(:defn, :uses_gasgn,
|
855
|
+
s(:args),
|
856
|
+
s(:scope,
|
857
|
+
s(:block,
|
858
|
+
s(:gasgn, :$gvar, s(:nil)),
|
859
|
+
s(:gasgn, :$gvar, s(:nil))))),
|
860
|
+
]
|
629
861
|
|
630
|
-
@heckler
|
631
|
-
@heckler.reset_tree
|
632
|
-
@heckler.process(@heckler.current_tree)
|
633
|
-
assert_equal expected, @heckler.current_tree
|
862
|
+
assert_mutations expected, @heckler
|
634
863
|
end
|
635
864
|
|
636
865
|
end
|
637
866
|
|
638
867
|
class TestHeckleLasgn < HeckleTestCase
|
639
|
-
|
640
868
|
def setup
|
869
|
+
@method_heckled = "uses_lasgn"
|
641
870
|
@nodes = s(:lasgn)
|
642
871
|
super
|
643
872
|
end
|
644
873
|
|
645
|
-
def
|
646
|
-
expected =
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
874
|
+
def test_lasgn_original_tree
|
875
|
+
expected = s(:defn, :uses_lasgn,
|
876
|
+
s(:args),
|
877
|
+
s(:scope,
|
878
|
+
s(:block,
|
879
|
+
s(:lasgn, :lvar, s(:lit, 5)),
|
880
|
+
s(:lasgn, :lvar, s(:nil)))))
|
652
881
|
|
653
|
-
@heckler.process(@heckler.current_tree)
|
654
882
|
assert_equal expected, @heckler.current_tree
|
655
883
|
end
|
656
884
|
|
657
|
-
def
|
658
|
-
expected =
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
885
|
+
def test_lasgn_mutations
|
886
|
+
expected = [
|
887
|
+
s(:defn, :uses_lasgn,
|
888
|
+
s(:args),
|
889
|
+
s(:scope,
|
890
|
+
s(:block,
|
891
|
+
s(:lasgn, :lvar, s(:nil)),
|
892
|
+
s(:lasgn, :lvar, s(:nil))))),
|
893
|
+
s(:defn, :uses_lasgn,
|
894
|
+
s(:args),
|
895
|
+
s(:scope,
|
896
|
+
s(:block,
|
897
|
+
s(:lasgn, :lvar, s(:lit, 5)),
|
898
|
+
s(:lasgn, :lvar, s(:lit, 42))))),
|
899
|
+
]
|
900
|
+
|
901
|
+
assert_mutations expected, @heckler
|
669
902
|
end
|
670
|
-
|
671
903
|
end
|
672
904
|
|
673
905
|
class TestHeckleMasgn < HeckleTestCase
|
674
|
-
|
675
906
|
def setup
|
907
|
+
@method_heckled = "uses_masgn"
|
676
908
|
@nodes = s(:dasgn, :dasgn_curr, :iasgn, :gasgn, :lasgn)
|
677
909
|
super
|
678
910
|
end
|
679
911
|
|
680
|
-
def
|
681
|
-
expected =
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
s(:gasgn, :$b),
|
689
|
-
s(:lasgn, :c)),
|
690
|
-
s(:array, s(:lit, 5), s(:lit, 6), s(:lit, 7))))))
|
912
|
+
def test_masgn_original_tree
|
913
|
+
expected = s(:defn, :uses_masgn,
|
914
|
+
s(:args),
|
915
|
+
s(:scope,
|
916
|
+
s(:block,
|
917
|
+
s(:masgn,
|
918
|
+
s(:array, s(:iasgn, :@a), s(:gasgn, :$b), s(:lasgn, :c)),
|
919
|
+
s(:array, s(:lit, 5), s(:lit, 6), s(:lit, 7))))))
|
691
920
|
|
692
|
-
@heckler.process(@heckler.current_tree)
|
693
921
|
assert_equal expected, @heckler.current_tree
|
694
922
|
end
|
695
923
|
|
924
|
+
def test_masgn_mutations
|
925
|
+
expected = [
|
926
|
+
s(:defn, :uses_masgn,
|
927
|
+
s(:args),
|
928
|
+
s(:scope,
|
929
|
+
s(:block,
|
930
|
+
s(:masgn,
|
931
|
+
s(:array, s(:iasgn, :_heckle_dummy), s(:gasgn, :$b), s(:lasgn, :c)),
|
932
|
+
s(:array, s(:lit, 5), s(:lit, 6), s(:lit, 7)))))),
|
933
|
+
s(:defn, :uses_masgn,
|
934
|
+
s(:args),
|
935
|
+
s(:scope,
|
936
|
+
s(:block,
|
937
|
+
s(:masgn,
|
938
|
+
s(:array, s(:iasgn, :@a), s(:gasgn, :_heckle_dummy), s(:lasgn, :c)),
|
939
|
+
s(:array, s(:lit, 5), s(:lit, 6), s(:lit, 7)))))),
|
940
|
+
s(:defn, :uses_masgn,
|
941
|
+
s(:args),
|
942
|
+
s(:scope,
|
943
|
+
s(:block,
|
944
|
+
s(:masgn,
|
945
|
+
s(:array,s(:iasgn, :@a), s(:gasgn, :$b), s(:lasgn, :_heckle_dummy)),
|
946
|
+
s(:array, s(:lit, 5), s(:lit, 6), s(:lit, 7)))))),
|
947
|
+
]
|
948
|
+
|
949
|
+
assert_mutations expected, @heckler
|
950
|
+
end
|
951
|
+
|
696
952
|
end
|
697
953
|
|
698
954
|
class TestHeckleIter < HeckleTestCase
|
699
955
|
def setup
|
956
|
+
@method_heckled = "uses_iter"
|
700
957
|
@nodes = [ :call, :lasgn ]
|
701
958
|
super
|
702
959
|
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
960
|
|
720
|
-
|
721
|
-
|
961
|
+
def test_iter_original_tree
|
962
|
+
expected = s(:defn, :uses_iter,
|
963
|
+
s(:args),
|
964
|
+
s(:scope,
|
965
|
+
s(:block,
|
966
|
+
s(:lasgn, :x, s(:array, s(:lit, 1), s(:lit, 2), s(:lit, 3))),
|
967
|
+
s(:iter,
|
968
|
+
s(:call, s(:lvar, :x), :each, s(:arglist)),
|
969
|
+
s(:lasgn, :y), s(:lvar, :y)))))
|
722
970
|
|
723
|
-
@heckler.
|
724
|
-
|
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))))))
|
971
|
+
assert_equal expected, @heckler.current_tree
|
972
|
+
end
|
733
973
|
|
734
|
-
|
735
|
-
|
974
|
+
def test_iter_mutations
|
975
|
+
expected = [
|
976
|
+
s(:defn, :uses_iter,
|
977
|
+
s(:args),
|
978
|
+
s(:scope,
|
979
|
+
s(:block,
|
980
|
+
s(:lasgn, :x, s(:nil)),
|
981
|
+
s(:iter,
|
982
|
+
s(:call, s(:lvar, :x), :each, s(:arglist)),
|
983
|
+
s(:lasgn, :y), s(:lvar, :y))))),
|
984
|
+
s(:defn, :uses_iter,
|
985
|
+
s(:args),
|
986
|
+
s(:scope,
|
987
|
+
s(:block,
|
988
|
+
s(:lasgn, :x, s(:array, s(:lit, 1), s(:lit, 2), s(:lit, 3))),
|
989
|
+
s(:iter,
|
990
|
+
s(:call, s(:lvar, :x), :each, s(:arglist)),
|
991
|
+
s(:lasgn, :_heckle_dummy), s(:lvar, :y))))),
|
992
|
+
]
|
993
|
+
|
994
|
+
|
995
|
+
assert_mutations expected, @heckler
|
996
|
+
end
|
997
|
+
end
|
998
|
+
|
999
|
+
|
1000
|
+
class TestHeckleFindsNestedClassAndModule < HeckleTestCase
|
1001
|
+
def setup
|
1002
|
+
@klass = "HeckleDummy::OuterNesting::InnerNesting::InnerClass"
|
1003
|
+
@method_heckled = "foo"
|
1004
|
+
@nodes = []
|
1005
|
+
super
|
1006
|
+
end
|
1007
|
+
|
1008
|
+
def test_nested_class_and_module_original_tree
|
1009
|
+
expected = s(:defn, :foo, s(:args), s(:scope,
|
1010
|
+
s(:block,
|
1011
|
+
s(:lit, 1337))))
|
1012
|
+
|
1013
|
+
assert_equal expected, @heckler.current_tree
|
736
1014
|
end
|
737
1015
|
end
|