Skip to content

Commit 58b7556

Browse files
committed
Ruby: Add call graph tests for protected methods
1 parent cda05ed commit 58b7556

File tree

6 files changed

+596
-516
lines changed

6 files changed

+596
-516
lines changed

ruby/ql/test/library-tests/modules/ancestors.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ calls.rb:
9797

9898
# 477| ExtendSingletonMethod
9999

100+
# 487| ProtectedMethods
101+
#-----| super -> Object
102+
100103
hello.rb:
101104
# 1| EnglishWords
102105

ruby/ql/test/library-tests/modules/callgraph.expected

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,25 @@ getTarget
172172
| calls.rb:447:1:447:30 | call to new | calls.rb:114:5:114:16 | new |
173173
| calls.rb:448:1:448:30 | call to new | calls.rb:114:5:114:16 | new |
174174
| calls.rb:449:1:449:30 | call to new | calls.rb:114:5:114:16 | new |
175+
| calls.rb:451:27:469:3 | call to new | calls.rb:114:5:114:16 | new |
175176
| calls.rb:454:13:454:22 | call to puts | calls.rb:102:5:102:30 | puts |
176177
| calls.rb:458:5:462:7 | call to new | calls.rb:114:5:114:16 | new |
177178
| calls.rb:458:5:462:11 | call to new | calls.rb:114:5:114:16 | new |
178179
| calls.rb:460:13:460:22 | call to puts | calls.rb:102:5:102:30 | puts |
179180
| calls.rb:466:13:466:27 | call to puts | calls.rb:102:5:102:30 | puts |
181+
| calls.rb:471:1:471:27 | call to new | calls.rb:114:5:114:16 | new |
182+
| calls.rb:472:1:472:27 | call to new | calls.rb:114:5:114:16 | new |
183+
| calls.rb:473:1:473:27 | call to new | calls.rb:114:5:114:16 | new |
184+
| calls.rb:474:1:474:27 | call to new | calls.rb:114:5:114:16 | new |
185+
| calls.rb:475:1:475:27 | call to new | calls.rb:114:5:114:16 | new |
186+
| calls.rb:489:9:489:35 | call to puts | calls.rb:102:5:102:30 | puts |
187+
| calls.rb:493:9:493:11 | call to foo | calls.rb:488:15:490:7 | foo |
188+
| calls.rb:494:9:494:28 | call to new | calls.rb:114:5:114:16 | new |
189+
| calls.rb:494:9:494:32 | call to foo | calls.rb:488:15:490:7 | foo |
190+
| calls.rb:498:1:498:20 | call to new | calls.rb:114:5:114:16 | new |
191+
| calls.rb:498:1:498:24 | call to foo | calls.rb:488:15:490:7 | foo |
192+
| calls.rb:499:1:499:20 | call to new | calls.rb:114:5:114:16 | new |
193+
| calls.rb:499:1:499:24 | call to bar | calls.rb:492:5:495:7 | bar |
180194
| hello.rb:12:5:12:24 | call to include | calls.rb:107:5:107:20 | include |
181195
| hello.rb:14:16:14:20 | call to hello | hello.rb:2:5:4:7 | hello |
182196
| hello.rb:20:16:20:20 | call to super | hello.rb:13:5:15:7 | message |
@@ -265,27 +279,21 @@ unresolvedCall
265279
| calls.rb:447:1:447:33 | call to m3 |
266280
| calls.rb:448:1:448:33 | call to m4 |
267281
| calls.rb:449:1:449:33 | call to m5 |
268-
| calls.rb:450:1:450:4 | call to exit |
269-
| calls.rb:451:27:469:3 | call to new |
270282
| calls.rb:452:5:452:11 | call to [] |
271283
| calls.rb:452:5:456:7 | call to each |
272284
| calls.rb:458:5:462:15 | call to bar |
273285
| calls.rb:464:5:464:11 | call to [] |
274286
| calls.rb:464:5:468:7 | call to each |
275287
| calls.rb:465:9:467:11 | call to define_method |
276-
| calls.rb:471:1:471:27 | call to new |
277288
| calls.rb:471:1:471:31 | call to foo |
278-
| calls.rb:472:1:472:27 | call to new |
279289
| calls.rb:472:1:472:31 | call to bar |
280-
| calls.rb:473:1:473:27 | call to new |
281290
| calls.rb:473:1:473:33 | call to baz_0 |
282-
| calls.rb:474:1:474:27 | call to new |
283291
| calls.rb:474:1:474:33 | call to baz_1 |
284-
| calls.rb:475:1:475:27 | call to new |
285292
| calls.rb:475:1:475:33 | call to baz_2 |
286293
| calls.rb:479:9:479:46 | call to puts |
287294
| calls.rb:482:5:482:15 | call to extend |
288295
| calls.rb:485:1:485:31 | call to singleton |
296+
| calls.rb:488:5:490:7 | call to protected |
289297
| hello.rb:20:16:20:26 | ... + ... |
290298
| hello.rb:20:16:20:34 | ... + ... |
291299
| hello.rb:20:16:20:40 | ... + ... |
@@ -385,6 +393,7 @@ publicMethod
385393
| calls.rb:427:13:429:15 | m4 |
386394
| calls.rb:437:13:439:15 | m5 |
387395
| calls.rb:478:5:480:7 | singleton |
396+
| calls.rb:492:5:495:7 | bar |
388397
| hello.rb:2:5:4:7 | hello |
389398
| hello.rb:5:5:7:7 | world |
390399
| hello.rb:13:5:15:7 | message |
@@ -401,5 +410,6 @@ publicMethod
401410
| private.rb:66:3:67:5 | public |
402411
| private.rb:91:3:93:5 | call_m1 |
403412
protectedMethod
413+
| calls.rb:488:15:490:7 | foo |
404414
| private.rb:32:3:33:5 | protected1 |
405415
| private.rb:35:3:36:5 | protected2 |

ruby/ql/test/library-tests/modules/calls.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def m5
447447
ConditionalInstanceMethods.new.m3 # currently unable to resolve
448448
ConditionalInstanceMethods.new.m4 # currently unable to resolve
449449
ConditionalInstanceMethods.new.m5 # NoMethodError
450-
exit
450+
451451
EsotericInstanceMethods = Class.new do
452452
[0,1,2].each do
453453
def foo
@@ -483,3 +483,17 @@ def singleton
483483
end
484484

485485
ExtendSingletonMethod.singleton # currently unable to resolve
486+
487+
class ProtectedMethods
488+
protected def foo
489+
puts "ProtectedMethods#foo"
490+
end
491+
492+
def bar
493+
foo
494+
ProtectedMethods.new.foo
495+
end
496+
end
497+
498+
ProtectedMethods.new.foo # NoMethodError
499+
ProtectedMethods.new.bar

ruby/ql/test/library-tests/modules/methods.expected

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ getMethod
3939
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | m1 | calls.rb:416:9:418:11 | m1 |
4040
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | m2 | calls.rb:421:5:433:7 | m2 |
4141
| calls.rb:477:1:483:3 | ExtendSingletonMethod | singleton | calls.rb:478:5:480:7 | singleton |
42+
| calls.rb:487:1:496:3 | ProtectedMethods | bar | calls.rb:492:5:495:7 | bar |
43+
| calls.rb:487:1:496:3 | ProtectedMethods | foo | calls.rb:488:15:490:7 | foo |
4244
| hello.rb:1:1:8:3 | EnglishWords | hello | hello.rb:2:5:4:7 | hello |
4345
| hello.rb:1:1:8:3 | EnglishWords | world | hello.rb:5:5:7:7 | world |
4446
| hello.rb:11:1:16:3 | Greeting | message | hello.rb:13:5:15:7 | message |
@@ -353,6 +355,20 @@ lookupMethod
353355
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | puts | calls.rb:102:5:102:30 | puts |
354356
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | to_s | calls.rb:169:5:170:7 | to_s |
355357
| calls.rb:477:1:483:3 | ExtendSingletonMethod | singleton | calls.rb:478:5:480:7 | singleton |
358+
| calls.rb:487:1:496:3 | ProtectedMethods | add_singleton | calls.rb:364:1:368:3 | add_singleton |
359+
| calls.rb:487:1:496:3 | ProtectedMethods | bar | calls.rb:492:5:495:7 | bar |
360+
| calls.rb:487:1:496:3 | ProtectedMethods | call_block | calls.rb:81:1:83:3 | call_block |
361+
| calls.rb:487:1:496:3 | ProtectedMethods | call_instance_m | calls.rb:39:1:41:3 | call_instance_m |
362+
| calls.rb:487:1:496:3 | ProtectedMethods | create | calls.rb:275:1:283:3 | create |
363+
| calls.rb:487:1:496:3 | ProtectedMethods | foo | calls.rb:488:15:490:7 | foo |
364+
| calls.rb:487:1:496:3 | ProtectedMethods | funny | calls.rb:137:1:139:3 | funny |
365+
| calls.rb:487:1:496:3 | ProtectedMethods | indirect | calls.rb:155:1:157:3 | indirect |
366+
| calls.rb:487:1:496:3 | ProtectedMethods | new | calls.rb:114:5:114:16 | new |
367+
| calls.rb:487:1:496:3 | ProtectedMethods | optional_arg | calls.rb:76:1:79:3 | optional_arg |
368+
| calls.rb:487:1:496:3 | ProtectedMethods | pattern_dispatch | calls.rb:340:1:356:3 | pattern_dispatch |
369+
| calls.rb:487:1:496:3 | ProtectedMethods | private_on_main | calls.rb:182:1:183:3 | private_on_main |
370+
| calls.rb:487:1:496:3 | ProtectedMethods | puts | calls.rb:102:5:102:30 | puts |
371+
| calls.rb:487:1:496:3 | ProtectedMethods | to_s | calls.rb:169:5:170:7 | to_s |
356372
| file://:0:0:0:0 | Class | include | calls.rb:107:5:107:20 | include |
357373
| file://:0:0:0:0 | Class | module_eval | calls.rb:106:5:106:24 | module_eval |
358374
| file://:0:0:0:0 | Class | new | calls.rb:114:5:114:16 | new |
@@ -769,6 +785,15 @@ enclosingMethod
769785
| calls.rb:479:9:479:46 | self | calls.rb:478:5:480:7 | singleton |
770786
| calls.rb:479:14:479:46 | "ExtendSingletonMethod#singleton" | calls.rb:478:5:480:7 | singleton |
771787
| calls.rb:479:15:479:45 | ExtendSingletonMethod#singleton | calls.rb:478:5:480:7 | singleton |
788+
| calls.rb:489:9:489:35 | call to puts | calls.rb:488:15:490:7 | foo |
789+
| calls.rb:489:9:489:35 | self | calls.rb:488:15:490:7 | foo |
790+
| calls.rb:489:14:489:35 | "ProtectedMethods#foo" | calls.rb:488:15:490:7 | foo |
791+
| calls.rb:489:15:489:34 | ProtectedMethods#foo | calls.rb:488:15:490:7 | foo |
792+
| calls.rb:493:9:493:11 | call to foo | calls.rb:492:5:495:7 | bar |
793+
| calls.rb:493:9:493:11 | self | calls.rb:492:5:495:7 | bar |
794+
| calls.rb:494:9:494:24 | ProtectedMethods | calls.rb:492:5:495:7 | bar |
795+
| calls.rb:494:9:494:28 | call to new | calls.rb:492:5:495:7 | bar |
796+
| calls.rb:494:9:494:32 | call to foo | calls.rb:492:5:495:7 | bar |
772797
| hello.rb:3:9:3:22 | return | hello.rb:2:5:4:7 | hello |
773798
| hello.rb:3:16:3:22 | "hello" | hello.rb:2:5:4:7 | hello |
774799
| hello.rb:3:17:3:21 | hello | hello.rb:2:5:4:7 | hello |

0 commit comments

Comments
 (0)