rcodetools 0.4.0.0
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/CHANGES +18 -0
- data/README +34 -0
- data/README.emacs +54 -0
- data/README.method_analysis +13 -0
- data/README.vim +84 -0
- data/README.xmpfilter +202 -0
- data/Rakefile +123 -0
- data/Rakefile.method_analysis +30 -0
- data/THANKS +6 -0
- data/bin/rct-complete +37 -0
- data/bin/rct-doc +50 -0
- data/bin/rct-meth-args +392 -0
- data/bin/xmpfilter +75 -0
- data/icicles-rcodetools.el +31 -0
- data/lib/method_analyzer.rb +107 -0
- data/lib/rcodetools/completion.rb +282 -0
- data/lib/rcodetools/doc.rb +176 -0
- data/lib/rcodetools/options.rb +83 -0
- data/lib/rcodetools/xmpfilter.rb +208 -0
- data/lib/rcodetools/xmptestunitfilter.rb +197 -0
- data/rcodetools.el +162 -0
- data/rcodetools.vim +118 -0
- data/setup.rb +1585 -0
- data/test/data/add_markers-input.rb +2 -0
- data/test/data/add_markers-output.rb +2 -0
- data/test/data/bindings-input.rb +26 -0
- data/test/data/bindings-output.rb +31 -0
- data/test/data/completion-input.rb +1 -0
- data/test/data/completion-output.rb +2 -0
- data/test/data/completion_emacs-input.rb +1 -0
- data/test/data/completion_emacs-output.rb +5 -0
- data/test/data/completion_emacs_icicles-input.rb +1 -0
- data/test/data/completion_emacs_icicles-output.rb +5 -0
- data/test/data/doc-input.rb +1 -0
- data/test/data/doc-output.rb +1 -0
- data/test/data/method_analyzer-data.rb +33 -0
- data/test/data/method_args.data.rb +106 -0
- data/test/data/no_warnings-input.rb +3 -0
- data/test/data/no_warnings-output.rb +4 -0
- data/test/data/refe-input.rb +1 -0
- data/test/data/refe-output.rb +1 -0
- data/test/data/ri-input.rb +1 -0
- data/test/data/ri-output.rb +1 -0
- data/test/data/ri_emacs-input.rb +1 -0
- data/test/data/ri_emacs-output.rb +1 -0
- data/test/data/ri_vim-input.rb +1 -0
- data/test/data/ri_vim-output.rb +1 -0
- data/test/data/rspec-input.rb +48 -0
- data/test/data/rspec-output.rb +52 -0
- data/test/data/rspec_poetry-input.rb +48 -0
- data/test/data/rspec_poetry-output.rb +52 -0
- data/test/data/simple_annotation-input.rb +8 -0
- data/test/data/simple_annotation-output.rb +8 -0
- data/test/data/unit_test-input.rb +50 -0
- data/test/data/unit_test-output.rb +52 -0
- data/test/data/unit_test_poetry-input.rb +50 -0
- data/test/data/unit_test_poetry-output.rb +52 -0
- data/test/test_completion.rb +467 -0
- data/test/test_doc.rb +403 -0
- data/test/test_functional.rb +18 -0
- data/test/test_method_analyzer.rb +99 -0
- data/test/test_method_args.rb +134 -0
- data/test/test_run.rb +41 -0
- data/test/test_xmpfilter.rb +36 -0
- data/test/test_xmptestunitfilter.rb +84 -0
- metadata +139 -0
data/test/test_doc.rb
ADDED
@@ -0,0 +1,403 @@
|
|
1
|
+
$: << ".." << "../lib"
|
2
|
+
require 'rcodetools/doc'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TestXMPDocFilter < Test::Unit::TestCase
|
6
|
+
def doit(code, lineno, column=nil, options={})
|
7
|
+
xmp = XMPDocFilter.new options
|
8
|
+
xmp.doc(code, lineno, column)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_instance_method__Array
|
12
|
+
assert_equal("Array#length", doit("[].length", 1))
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_instance_method__Fixnum
|
16
|
+
assert_equal("Fixnum#to_s", doit("1.to_s", 1))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_instance_method__Enumerable
|
20
|
+
assert_equal("Enumerable#each_with_index", doit("[].each_with_index", 1))
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_instance_method__String
|
24
|
+
assert_equal("String#length", doit("'a'.length", 1))
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_class_method__IO_popen
|
28
|
+
assert_equal("IO.popen", doit("IO::popen", 1))
|
29
|
+
assert_equal("IO.popen", doit("IO.popen", 1))
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_class_method__File_popen
|
33
|
+
assert_equal("IO.popen", doit("File::popen", 1))
|
34
|
+
assert_equal("IO.popen", doit("File.popen", 1))
|
35
|
+
|
36
|
+
assert_equal("IO.popen", doit(<<EOC,2))
|
37
|
+
$hoge = File
|
38
|
+
$hoge.popen
|
39
|
+
EOC
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_constant__File
|
43
|
+
assert_equal("File", doit("File", 1))
|
44
|
+
assert_equal("File", doit("::File", 1))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_constant__File_Stat
|
48
|
+
assert_equal("File::Stat", doit("File::Stat", 1))
|
49
|
+
assert_equal("File::Stat", doit("::File::Stat", 1))
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_instance_method__File_Stat
|
53
|
+
assert_equal("File::Stat#atime", doit(<<EOC,2))
|
54
|
+
stat = File::Stat.new "#{__FILE__}"
|
55
|
+
stat.atime
|
56
|
+
EOC
|
57
|
+
assert_equal("File::Stat#atime", doit(<<EOC,2))
|
58
|
+
stat = ::File::Stat.new "#{__FILE__}"
|
59
|
+
stat.atime
|
60
|
+
EOC
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_instance_method__Hoge_File_Stat_1
|
64
|
+
assert_equal("Hoge::File::Stat#atime", doit(<<EOC,11))
|
65
|
+
module Hoge
|
66
|
+
module File
|
67
|
+
class Stat
|
68
|
+
def initialize(file)
|
69
|
+
end
|
70
|
+
def atime
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
stat = File::Stat.new "#{__FILE__}"
|
75
|
+
stat.atime
|
76
|
+
end
|
77
|
+
EOC
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_instance_method__Hoge_File_Stat_2
|
81
|
+
assert_equal("File::Stat#atime", doit(<<EOC,11))
|
82
|
+
module Hoge
|
83
|
+
module File
|
84
|
+
class Stat
|
85
|
+
def initialize(file)
|
86
|
+
end
|
87
|
+
def atime
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
stat = ::File::Stat.new "#{__FILE__}"
|
92
|
+
stat.atime
|
93
|
+
end
|
94
|
+
EOC
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_bare_word__Kernel
|
98
|
+
assert_equal("Kernel#print", doit("print", 1))
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_bare_word__Module
|
102
|
+
assert_equal("Kernel#print", doit(<<EOC, 2))
|
103
|
+
module Foo
|
104
|
+
print
|
105
|
+
end
|
106
|
+
EOC
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_bare_word__class
|
110
|
+
assert_equal("Kernel#print", doit(<<EOC, 2))
|
111
|
+
class Foo
|
112
|
+
print
|
113
|
+
end
|
114
|
+
EOC
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
def test_bare_word__Module_attr
|
119
|
+
assert_equal("Module#attr", doit(<<EOC, 2))
|
120
|
+
module Foo
|
121
|
+
attr
|
122
|
+
end
|
123
|
+
EOC
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_bare_word__Class_superclass
|
127
|
+
assert_equal("Class#superclass", doit(<<EOC, 2))
|
128
|
+
class Foo
|
129
|
+
superclass
|
130
|
+
end
|
131
|
+
EOC
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
def test_bare_word__self
|
136
|
+
assert_equal("Foo#foo", doit(<<EOC, 3))
|
137
|
+
class Foo
|
138
|
+
def initialize
|
139
|
+
foo
|
140
|
+
end
|
141
|
+
attr :foo
|
142
|
+
new
|
143
|
+
end
|
144
|
+
EOC
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_column
|
148
|
+
assert_equal("Array#length", doit("[].length + 10", 1, 9))
|
149
|
+
assert_equal("Array#length", doit("[].length + 10", 1, 5))
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_method_chain__String
|
153
|
+
assert_equal("String#length", doit('"a".upcase.capitalize.length', 1))
|
154
|
+
assert_equal("String#capitalize", doit('"a".upcase.capitalize.length', 1, 21))
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_method_chain__Fixnum
|
158
|
+
assert_equal("String#length", doit('1.to_s.upcase.length', 1))
|
159
|
+
assert_equal("String#upcase", doit('1.to_s.upcase.length', 1, 13))
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_multi_line__do
|
163
|
+
assert_equal("Enumerable#each_with_index", doit(<<EOC, 1, 16))
|
164
|
+
[].each_with_index do |x|
|
165
|
+
end
|
166
|
+
EOC
|
167
|
+
assert_equal("Enumerable#each_with_index", doit(<<EOC, 1, 16))
|
168
|
+
[].each_with_index()do |x|
|
169
|
+
end
|
170
|
+
EOC
|
171
|
+
assert_equal("Enumerable#each_with_index", doit(<<EOC, 1, 16))
|
172
|
+
[].each_with_index do |x,y| end
|
173
|
+
EOC
|
174
|
+
assert_equal("Enumerable#each_with_index", doit(<<EOC, 1, 16))
|
175
|
+
[1].each_with_index do |x,y| [].each do end end
|
176
|
+
EOC
|
177
|
+
assert_equal("Enumerable#each_with_index", doit(<<EOC, 1, 16))
|
178
|
+
[].each_with_index ; do-do
|
179
|
+
EOC
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_multi_line__braces
|
183
|
+
assert_equal("Enumerable#each_with_index", doit(<<EOC, 1, 16))
|
184
|
+
[].each_with_index { |x|
|
185
|
+
}
|
186
|
+
EOC
|
187
|
+
assert_equal("Enumerable#each_with_index", doit(<<EOC, 1, 16))
|
188
|
+
[].each_with_index(){ |x|
|
189
|
+
}
|
190
|
+
EOC
|
191
|
+
assert_equal("Enumerable#each_with_index", doit(<<EOC, 1, 16))
|
192
|
+
[].each_with_index {|x,y| }
|
193
|
+
EOC
|
194
|
+
assert_equal("Enumerable#each_with_index", doit(<<EOC, 1, 16))
|
195
|
+
[1].each_with_index {|x,y| [].each { }}
|
196
|
+
EOC
|
197
|
+
assert_equal("Enumerable#each_with_index", doit(<<EOC, 1, 20))
|
198
|
+
{ [1].each_with_index {|x,y| [].each { }},1}
|
199
|
+
|
200
|
+
EOC
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_multi_line__brackets
|
204
|
+
assert_equal("Enumerable#each_with_index", doit(<<EOC, 1, 20))
|
205
|
+
[ [1].each_with_index {|x,y| [].each { }},
|
206
|
+
1]
|
207
|
+
EOC
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_multi_line__parentheses
|
211
|
+
assert_equal("Enumerable#each_with_index", doit(<<EOC, 1, 23))
|
212
|
+
foo( [1].each_with_index {|x,y| [].each { }},
|
213
|
+
1)
|
214
|
+
EOC
|
215
|
+
=begin FIXME
|
216
|
+
assert_equal("Enumerable#each_with_index", doit(<<EOC, 2, 23))
|
217
|
+
foo( 1,
|
218
|
+
[1].each_with_index {|x,y| [].each { }})
|
219
|
+
EOC
|
220
|
+
=end
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_multi_line__control_structures__if
|
224
|
+
assert_equal("String#length", doit(<<EOC, 1))
|
225
|
+
if "a".length
|
226
|
+
end
|
227
|
+
EOC
|
228
|
+
assert_equal("String#length", doit(<<EOC, 1, 8))
|
229
|
+
"a".length if true
|
230
|
+
EOC
|
231
|
+
assert_equal("String#length", doit(<<EOC, 1, 8))
|
232
|
+
"a".length ; if true
|
233
|
+
1
|
234
|
+
end
|
235
|
+
EOC
|
236
|
+
assert_equal("String#length", doit(<<EOC, 1, 8))
|
237
|
+
"a".length ;if true
|
238
|
+
1
|
239
|
+
end
|
240
|
+
EOC
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_multi_line__control_structures__if_in_string
|
244
|
+
assert_equal("String#length", doit(<<EOC, 1))
|
245
|
+
"if a".length
|
246
|
+
EOC
|
247
|
+
assert_equal("String#length", doit(<<EOC, 1))
|
248
|
+
'if a'.length
|
249
|
+
EOC
|
250
|
+
assert_equal("String#length", doit(<<EOC, 1))
|
251
|
+
`if a`.length
|
252
|
+
EOC
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_multi_line__control_structures__other_keywords
|
256
|
+
assert_equal("String#length", doit(<<EOC, 1))
|
257
|
+
unless "a".length
|
258
|
+
end
|
259
|
+
EOC
|
260
|
+
assert_equal("String#length", doit(<<EOC, 1))
|
261
|
+
while "a".length
|
262
|
+
end
|
263
|
+
EOC
|
264
|
+
assert_equal("String#length", doit(<<EOC, 1))
|
265
|
+
until "a".length
|
266
|
+
end
|
267
|
+
EOC
|
268
|
+
assert_equal("String#split", doit(<<EOC, 1))
|
269
|
+
for a in "a".split
|
270
|
+
end
|
271
|
+
EOC
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_operator
|
275
|
+
# +@ -@ is not supported
|
276
|
+
%w[ | ^ & <=> == === =~ > >= < <= << >>
|
277
|
+
+ - * / % ** ~
|
278
|
+
].each do |op|
|
279
|
+
ancestors_re = Fixnum.ancestors.map{|x|x.to_s}.join('|')
|
280
|
+
assert_match(/^#{ancestors_re}##{Regexp.quote(op)}$/, doit("1 #{op} 2",1,2))
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_aref_aset__Array
|
285
|
+
assert_equal("Array#[]", doit("[0][ 0 ]",1,4))
|
286
|
+
assert_equal("Array#[]=", doit("[0][ 0 ]=10",1,4))
|
287
|
+
assert_equal("Array#[]", doit("[0][0]",1,4))
|
288
|
+
assert_equal("Array#[]=", doit("[0][0]=10",1,4))
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_aref_aset__Object
|
292
|
+
assert_equal("Array#[]", doit("Array.new(3)[ 0 ]",1,13))
|
293
|
+
assert_equal("Array#[]=", doit("Array.new(3)[ 0 ]=10",1,13))
|
294
|
+
assert_equal("Array#[]", doit("Array.new(3)[0]",1,13))
|
295
|
+
assert_equal("Array#[]=", doit("Array.new(3)[0]=10",1,13))
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_aref_aset__Fixnum
|
299
|
+
assert_equal("Fixnum#[]", doit("0[ 0 ]",1,2))
|
300
|
+
assert_equal("Fixnum#[]", doit("0[0]",1,2))
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_aref_aset__String
|
304
|
+
assert_equal("String#[]", doit("'a' + '[0]'[ 0 ]",1,12))
|
305
|
+
assert_equal("String#[]", doit("'[0]'[ 0 ]",1,6))
|
306
|
+
assert_equal("String#[]=", doit("'0'[ 0 ]=10",1,4))
|
307
|
+
assert_equal("String#[]", doit("'[0]'[0]",1,6))
|
308
|
+
assert_equal("String#[]=", doit("'0'[0]=10",1,4))
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_phrase
|
312
|
+
assert_equal("Array#uniq", doit('Array.new(3).uniq',1))
|
313
|
+
assert_equal("Array#uniq", doit('Array.new(3).to_a.uniq',1))
|
314
|
+
assert_equal("Array#uniq", doit('Array.new(3).map{|x| x.to_i}.uniq',1))
|
315
|
+
assert_equal("Array#uniq", doit('[][0,(1+1)].uniq',1))
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_percent__String
|
319
|
+
assert_equal("String#length", doit('%!foo!.length',1))
|
320
|
+
assert_equal("String#length", doit('%q!foo!.length',1))
|
321
|
+
assert_equal("String#length", doit('%Q!foo!.length',1))
|
322
|
+
assert_equal("String#length", doit('%x!foo!.length',1))
|
323
|
+
|
324
|
+
assert_equal("String#length", doit('%{foo}.length',1))
|
325
|
+
assert_equal("String#length", doit('%q{foo}.length',1))
|
326
|
+
assert_equal("String#length", doit('%q!(!.length',1))
|
327
|
+
assert_equal("String#length", doit('%Q!(!.length',1))
|
328
|
+
assert_equal("String#length", doit('%x!(!.length',1))
|
329
|
+
assert_equal("String#length", doit('%x{(}.length',1))
|
330
|
+
|
331
|
+
assert_equal("String#length", doit('%{f(o)o}.length',1))
|
332
|
+
assert_equal("String#length", doit('%{f{o}o}.length',1))
|
333
|
+
assert_equal("String#length", doit('(%{f{o}o}+%!}x!).length',1))
|
334
|
+
end
|
335
|
+
|
336
|
+
def test_percent__Array
|
337
|
+
assert_equal("Array#length", doit('%w!foo!.length',1))
|
338
|
+
assert_equal("Array#length", doit('%W!foo!.length',1))
|
339
|
+
|
340
|
+
assert_equal("Array#length", doit('%w{foo}.length',1))
|
341
|
+
assert_equal("Array#length", doit('%W{foo}.length',1))
|
342
|
+
assert_equal("Array#length", doit('%w!(!.length',1))
|
343
|
+
assert_equal("Array#length", doit('%W!(!.length',1))
|
344
|
+
assert_equal("Array#length", doit('%w{(}.length',1))
|
345
|
+
|
346
|
+
assert_equal("Array#length", doit('%w{f(o)o}.length',1))
|
347
|
+
assert_equal("Array#length", doit('%w{f{o}o}.length',1))
|
348
|
+
assert_equal("Array#length", doit('(%W{f{o}o}+%w!}x!).length',1))
|
349
|
+
end
|
350
|
+
|
351
|
+
def test_percent__Regexp
|
352
|
+
assert_equal("Regexp#kcode", doit('%r!foo!.kcode',1))
|
353
|
+
assert_equal("Regexp#kcode", doit('%r{foo}.kcode',1))
|
354
|
+
assert_equal("Regexp#kcode", doit('%r!(!.kcode',1))
|
355
|
+
assert_equal("Regexp#kcode", doit('%r[(].kcode',1))
|
356
|
+
assert_equal("Regexp#kcode", doit('%r<f(o)o>.kcode',1))
|
357
|
+
end
|
358
|
+
|
359
|
+
def test_percent__Symbol
|
360
|
+
assert_equal("Symbol#id2name", doit('%s!foo!.id2name',1))
|
361
|
+
assert_equal("Symbol#id2name", doit('%s{foo}.id2name',1))
|
362
|
+
assert_equal("Symbol#id2name", doit('%s!(!.id2name',1))
|
363
|
+
assert_equal("Symbol#id2name", doit('%s{(}.id2name',1))
|
364
|
+
assert_equal("Symbol#id2name", doit('%s(f(o)o).id2name',1))
|
365
|
+
end
|
366
|
+
|
367
|
+
def test_bare_word__with_NoMethodError
|
368
|
+
assert_equal("Module#module_function", doit(<<EOC, 3, nil, :ignore_NoMethodError=>true))
|
369
|
+
module X
|
370
|
+
xx # normally NoMethodError
|
371
|
+
module_function
|
372
|
+
end
|
373
|
+
EOC
|
374
|
+
end
|
375
|
+
|
376
|
+
def test__syntax_error
|
377
|
+
assert_raise(ProcessParticularLine::NewCodeError) do
|
378
|
+
doit(<<EOC, 5, nil)
|
379
|
+
end
|
380
|
+
module X
|
381
|
+
def x
|
382
|
+
end
|
383
|
+
module_function
|
384
|
+
end
|
385
|
+
EOC
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
def test__runtime_error
|
390
|
+
assert_raise(ProcessParticularLine::NewCodeError) do
|
391
|
+
doit(<<EOC, 5, nil)
|
392
|
+
__undefined_method__
|
393
|
+
module X
|
394
|
+
def x
|
395
|
+
end
|
396
|
+
module_function
|
397
|
+
end
|
398
|
+
EOC
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
|
403
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
class TestFunctional < Test::Unit::TestCase
|
4
|
+
tests = {:simple_annotation => [], :unit_test => ["-u"], :rspec => ["-s"],
|
5
|
+
:no_warnings => ["--no-warnings"], :bindings => ["--poetry", "-u"],
|
6
|
+
:add_markers => ["-m"]
|
7
|
+
}
|
8
|
+
tests.each_pair do |test, opts|
|
9
|
+
define_method("test_#{test}") do
|
10
|
+
dir = File.expand_path(File.dirname(__FILE__))
|
11
|
+
libdir = File.expand_path(dir + '/../lib')
|
12
|
+
exec = File.expand_path(dir + '/../bin/xmpfilter')
|
13
|
+
output = `ruby -I#{libdir} #{exec} #{opts.join(" ")} #{dir}/data/#{test}-input.rb`
|
14
|
+
outputfile = "#{dir}/data/#{test}-output.rb"
|
15
|
+
assert_equal(File.read(outputfile), output)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
module ScriptConfig
|
4
|
+
DIR = File.join(File.expand_path(File.dirname(__FILE__)))
|
5
|
+
SCRIPT = File.join(DIR, "..", "lib", "method_analyzer.rb")
|
6
|
+
DATAFILE = File.join(DIR, "data", "method_analyzer-data.rb")
|
7
|
+
end
|
8
|
+
|
9
|
+
class MethodAnalyzerTextOutput < Test::Unit::TestCase
|
10
|
+
include ScriptConfig
|
11
|
+
|
12
|
+
# test (find-sh "ruby -r../method_analyzer data/method_analyzer-data.rb")
|
13
|
+
|
14
|
+
# attr_accessor is actually Module#attr_accessor.
|
15
|
+
# But `f?ri Module.attr_accessor' answers correctly.
|
16
|
+
expected = <<XXX
|
17
|
+
method fullnames
|
18
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:8:Fixnum#+
|
19
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:17:String#length
|
20
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:20:Time.now Time#initialize
|
21
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:21:Time#year Time#month Time#day Array#<<
|
22
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:22:Class.new Object#initialize
|
23
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:23:A#a
|
24
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:24:Class.new B#initialize
|
25
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:25:A#a
|
26
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:26:B#b
|
27
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:27:A#a B#b
|
28
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:28:A#a B#b Fixnum#+
|
29
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:29:A.foo
|
30
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:30:A.foo
|
31
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:31:B#bb=
|
32
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:32:B#bb
|
33
|
+
|
34
|
+
method definitions
|
35
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:3:A.foo
|
36
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:7:A#a
|
37
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:12:B#initialize
|
38
|
+
/m/home/rubikitch/src/xmpfilter/test/data/method_analyzer-data.rb:16:B#b
|
39
|
+
XXX
|
40
|
+
|
41
|
+
def self.strip_dir(output)
|
42
|
+
output.gsub(/^.+(method_analyzer-data)/, '\1')
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.split_output(output)
|
46
|
+
strip_dir(output).split(/\n\n/,2)
|
47
|
+
end
|
48
|
+
|
49
|
+
@@fullnames_expected, @@definitions_expected = split_output expected
|
50
|
+
|
51
|
+
actual = strip_dir `ruby -r#{SCRIPT} '#{DATAFILE}'`
|
52
|
+
@@fullnames_actual, @@definitions_actual = split_output actual
|
53
|
+
|
54
|
+
|
55
|
+
def test_plain_fullnames
|
56
|
+
assert_equal @@fullnames_expected, @@fullnames_actual
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_plain_definitions
|
60
|
+
assert_equal @@definitions_expected, @@definitions_actual
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
class MethodAnalyzerMarshalOutput < Test::Unit::TestCase
|
66
|
+
include ScriptConfig
|
67
|
+
|
68
|
+
METHOD_ANALYSIS = File.join(DIR, "method_analysis")
|
69
|
+
at_exit { File.unlink METHOD_ANALYSIS rescue nil}
|
70
|
+
|
71
|
+
def setup
|
72
|
+
ENV['METHOD_ANALYZER_FORMAT'] = 'marshal'
|
73
|
+
@pwd = Dir.pwd
|
74
|
+
Dir.chdir DIR
|
75
|
+
end
|
76
|
+
|
77
|
+
def teardown
|
78
|
+
ENV['METHOD_ANALYZER_FORMAT'] = nil
|
79
|
+
Dir.chdir @pwd
|
80
|
+
end
|
81
|
+
|
82
|
+
def write_temp_file(str, file)
|
83
|
+
file.replace File.expand_path(file)
|
84
|
+
at_exit { File.unlink file }
|
85
|
+
open(file, "w"){ |f| f.write(str) }
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_marshal_merged
|
89
|
+
a = write_temp_file "z=1+2", "mergeA.rb"
|
90
|
+
b = write_temp_file "[].empty?", "mergeB.rb"
|
91
|
+
|
92
|
+
system "ruby -r#{SCRIPT} mergeA.rb"
|
93
|
+
system "ruby -r#{SCRIPT} mergeB.rb"
|
94
|
+
|
95
|
+
method_analysis = Marshal.load(File.read(METHOD_ANALYSIS))
|
96
|
+
assert_equal ["Fixnum#+"], method_analysis[File.join(DIR, "mergeA.rb")][1]
|
97
|
+
assert_equal ["Array#empty?"], method_analysis[File.join(DIR, "mergeB.rb")][1]
|
98
|
+
end
|
99
|
+
end
|