Skip to content

Commit 257bcef

Browse files
authored
Merge pull request #10548 from hvitved/ruby/call-graph-tests
Ruby: Add call graph tests for unsupported constructs
2 parents f9ba190 + fa6da78 commit 257bcef

File tree

6 files changed

+776
-422
lines changed

6 files changed

+776
-422
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#-----| BasicObject
2-
31
#-----| Class
42
#-----| super -> Module
53

4+
#-----| BasicObject
5+
66
#-----| Complex
77
#-----| super -> Numeric
88

@@ -92,6 +92,11 @@ calls.rb:
9292
# 399| SingletonOverride2
9393
#-----| super -> SingletonOverride1
9494

95+
# 414| ConditionalInstanceMethods
96+
#-----| super -> Object
97+
98+
# 477| ExtendSingletonMethod
99+
95100
hello.rb:
96101
# 1| EnglishWords
97102

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,26 @@ getTarget
157157
| calls.rb:397:1:397:34 | call to call_singleton2 | calls.rb:389:5:391:7 | call_singleton2 |
158158
| calls.rb:402:13:402:48 | call to puts | calls.rb:102:5:102:30 | puts |
159159
| calls.rb:407:9:407:44 | call to puts | calls.rb:102:5:102:30 | puts |
160+
| calls.rb:417:13:417:48 | call to puts | calls.rb:102:5:102:30 | puts |
161+
| calls.rb:422:9:422:44 | call to puts | calls.rb:102:5:102:30 | puts |
162+
| calls.rb:425:13:425:48 | call to puts | calls.rb:102:5:102:30 | puts |
163+
| calls.rb:428:17:428:52 | call to puts | calls.rb:102:5:102:30 | puts |
164+
| calls.rb:436:9:440:11 | call to new | calls.rb:114:5:114:16 | new |
165+
| calls.rb:436:9:440:15 | call to new | calls.rb:114:5:114:16 | new |
166+
| calls.rb:438:17:438:40 | call to puts | calls.rb:102:5:102:30 | puts |
167+
| calls.rb:444:1:444:30 | call to new | calls.rb:114:5:114:16 | new |
168+
| calls.rb:444:1:444:33 | call to m1 | calls.rb:416:9:418:11 | m1 |
169+
| calls.rb:445:1:445:30 | call to new | calls.rb:114:5:114:16 | new |
170+
| calls.rb:446:1:446:30 | call to new | calls.rb:114:5:114:16 | new |
171+
| calls.rb:446:1:446:33 | call to m2 | calls.rb:421:5:433:7 | m2 |
172+
| calls.rb:447:1:447:30 | call to new | calls.rb:114:5:114:16 | new |
173+
| calls.rb:448:1:448:30 | call to new | calls.rb:114:5:114:16 | new |
174+
| calls.rb:449:1:449:30 | call to new | calls.rb:114:5:114:16 | new |
175+
| calls.rb:454:13:454:22 | call to puts | calls.rb:102:5:102:30 | puts |
176+
| calls.rb:458:5:462:7 | call to new | calls.rb:114:5:114:16 | new |
177+
| calls.rb:458:5:462:11 | call to new | calls.rb:114:5:114:16 | new |
178+
| calls.rb:460:13:460:22 | call to puts | calls.rb:102:5:102:30 | puts |
179+
| calls.rb:466:13:466:27 | call to puts | calls.rb:102:5:102:30 | puts |
160180
| hello.rb:12:5:12:24 | call to include | calls.rb:107:5:107:20 | include |
161181
| hello.rb:14:16:14:20 | call to hello | hello.rb:2:5:4:7 | hello |
162182
| hello.rb:20:16:20:20 | call to super | hello.rb:13:5:15:7 | message |
@@ -233,6 +253,37 @@ unresolvedCall
233253
| calls.rb:310:9:310:20 | call to instance |
234254
| calls.rb:411:1:411:34 | call to call_singleton1 |
235255
| calls.rb:412:1:412:34 | call to call_singleton2 |
256+
| calls.rb:415:8:415:13 | call to rand |
257+
| calls.rb:415:8:415:17 | ... > ... |
258+
| calls.rb:432:9:432:10 | call to m3 |
259+
| calls.rb:435:8:435:13 | call to rand |
260+
| calls.rb:435:8:435:17 | ... > ... |
261+
| calls.rb:436:9:440:18 | call to m5 |
262+
| calls.rb:445:1:445:33 | call to m3 |
263+
| calls.rb:447:1:447:33 | call to m3 |
264+
| calls.rb:448:1:448:33 | call to m4 |
265+
| calls.rb:449:1:449:33 | call to m5 |
266+
| calls.rb:450:1:450:4 | call to exit |
267+
| calls.rb:451:27:469:3 | call to new |
268+
| calls.rb:452:5:452:11 | call to [] |
269+
| calls.rb:452:5:456:7 | call to each |
270+
| calls.rb:458:5:462:15 | call to bar |
271+
| calls.rb:464:5:464:11 | call to [] |
272+
| calls.rb:464:5:468:7 | call to each |
273+
| calls.rb:465:9:467:11 | call to define_method |
274+
| calls.rb:471:1:471:27 | call to new |
275+
| calls.rb:471:1:471:31 | call to foo |
276+
| calls.rb:472:1:472:27 | call to new |
277+
| calls.rb:472:1:472:31 | call to bar |
278+
| calls.rb:473:1:473:27 | call to new |
279+
| calls.rb:473:1:473:33 | call to baz_0 |
280+
| calls.rb:474:1:474:27 | call to new |
281+
| calls.rb:474:1:474:33 | call to baz_1 |
282+
| calls.rb:475:1:475:27 | call to new |
283+
| calls.rb:475:1:475:33 | call to baz_2 |
284+
| calls.rb:479:9:479:46 | call to puts |
285+
| calls.rb:482:5:482:15 | call to extend |
286+
| calls.rb:485:1:485:31 | call to singleton |
236287
| hello.rb:20:16:20:26 | ... + ... |
237288
| hello.rb:20:16:20:34 | ... + ... |
238289
| hello.rb:20:16:20:40 | ... + ... |
@@ -257,6 +308,8 @@ privateMethod
257308
| calls.rb:275:1:283:3 | create |
258309
| calls.rb:340:1:356:3 | pattern_dispatch |
259310
| calls.rb:364:1:368:3 | add_singleton |
311+
| calls.rb:453:9:455:11 | foo |
312+
| calls.rb:459:9:461:11 | bar |
260313
| private.rb:2:11:3:5 | private1 |
261314
| private.rb:8:3:9:5 | private2 |
262315
| private.rb:14:3:15:5 | private3 |

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,3 +410,76 @@ def self.singleton2
410410

411411
SingletonOverride2.call_singleton1
412412
SingletonOverride2.call_singleton2
413+
414+
class ConditionalInstanceMethods
415+
if rand() > 0 then
416+
def m1
417+
puts "ConditionalInstanceMethods#m1"
418+
end
419+
end
420+
421+
def m2
422+
puts "ConditionalInstanceMethods#m2"
423+
424+
def m3
425+
puts "ConditionalInstanceMethods#m3"
426+
427+
def m4
428+
puts "ConditionalInstanceMethods#m4"
429+
end
430+
end
431+
432+
m3
433+
end
434+
435+
if rand() > 0 then
436+
Class.new do
437+
def m5
438+
puts "AnonymousClass#m5"
439+
end
440+
end.new.m5
441+
end
442+
end
443+
444+
ConditionalInstanceMethods.new.m1
445+
ConditionalInstanceMethods.new.m3 # NoMethodError
446+
ConditionalInstanceMethods.new.m2
447+
ConditionalInstanceMethods.new.m3 # currently unable to resolve
448+
ConditionalInstanceMethods.new.m4 # currently unable to resolve
449+
ConditionalInstanceMethods.new.m5 # NoMethodError
450+
exit
451+
EsotericInstanceMethods = Class.new do
452+
[0,1,2].each do
453+
def foo
454+
puts "foo"
455+
end
456+
end
457+
458+
Class.new do
459+
def bar
460+
puts "bar"
461+
end
462+
end.new.bar
463+
464+
[0,1,2].each do |i|
465+
define_method("baz_#{i}") do
466+
puts "baz_#{i}"
467+
end
468+
end
469+
end
470+
471+
EsotericInstanceMethods.new.foo # currently unable to resolve
472+
EsotericInstanceMethods.new.bar # NoMethodError
473+
EsotericInstanceMethods.new.baz_0 # currently unable to resolve
474+
EsotericInstanceMethods.new.baz_1 # currently unable to resolve
475+
EsotericInstanceMethods.new.baz_2 # currently unable to resolve
476+
477+
module ExtendSingletonMethod
478+
def singleton
479+
puts "ExtendSingletonMethod#singleton"
480+
end
481+
482+
extend self
483+
end
484+
485+
ExtendSingletonMethod.singleton # currently unable to resolve

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ getMethod
3636
| calls.rb:322:1:326:3 | C1 | instance | calls.rb:323:5:325:7 | instance |
3737
| calls.rb:328:1:332:3 | C2 | instance | calls.rb:329:5:331:7 | instance |
3838
| calls.rb:334:1:338:3 | C3 | instance | calls.rb:335:5:337:7 | instance |
39+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | m1 | calls.rb:416:9:418:11 | m1 |
40+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | m2 | calls.rb:421:5:433:7 | m2 |
41+
| calls.rb:477:1:483:3 | ExtendSingletonMethod | singleton | calls.rb:478:5:480:7 | singleton |
3942
| hello.rb:1:1:8:3 | EnglishWords | hello | hello.rb:2:5:4:7 | hello |
4043
| hello.rb:1:1:8:3 | EnglishWords | world | hello.rb:5:5:7:7 | world |
4144
| hello.rb:11:1:16:3 | Greeting | message | hello.rb:13:5:15:7 | message |
@@ -329,6 +332,23 @@ lookupMethod
329332
| calls.rb:399:1:409:3 | SingletonOverride2 | private_on_main | calls.rb:182:1:183:3 | private_on_main |
330333
| calls.rb:399:1:409:3 | SingletonOverride2 | puts | calls.rb:102:5:102:30 | puts |
331334
| calls.rb:399:1:409:3 | SingletonOverride2 | to_s | calls.rb:169:5:170:7 | to_s |
335+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | add_singleton | calls.rb:364:1:368:3 | add_singleton |
336+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | call_block | calls.rb:81:1:83:3 | call_block |
337+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | call_instance_m | calls.rb:39:1:41:3 | call_instance_m |
338+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | create | calls.rb:275:1:283:3 | create |
339+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | foo | calls.rb:1:1:3:3 | foo |
340+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | foo | calls.rb:85:1:89:3 | foo |
341+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | funny | calls.rb:137:1:139:3 | funny |
342+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | indirect | calls.rb:155:1:157:3 | indirect |
343+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | m1 | calls.rb:416:9:418:11 | m1 |
344+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | m2 | calls.rb:421:5:433:7 | m2 |
345+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | new | calls.rb:114:5:114:16 | new |
346+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | optional_arg | calls.rb:76:1:79:3 | optional_arg |
347+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | pattern_dispatch | calls.rb:340:1:356:3 | pattern_dispatch |
348+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | private_on_main | calls.rb:182:1:183:3 | private_on_main |
349+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | puts | calls.rb:102:5:102:30 | puts |
350+
| calls.rb:414:1:442:3 | ConditionalInstanceMethods | to_s | calls.rb:169:5:170:7 | to_s |
351+
| calls.rb:477:1:483:3 | ExtendSingletonMethod | singleton | calls.rb:478:5:480:7 | singleton |
332352
| file://:0:0:0:0 | Class | include | calls.rb:107:5:107:20 | include |
333353
| file://:0:0:0:0 | Class | module_eval | calls.rb:106:5:106:24 | module_eval |
334354
| file://:0:0:0:0 | Class | new | calls.rb:114:5:114:16 | new |
@@ -705,6 +725,42 @@ enclosingMethod
705725
| calls.rb:407:9:407:44 | self | calls.rb:406:5:408:7 | singleton2 |
706726
| calls.rb:407:14:407:44 | "SingletonOverride2#singleton2" | calls.rb:406:5:408:7 | singleton2 |
707727
| calls.rb:407:15:407:43 | SingletonOverride2#singleton2 | calls.rb:406:5:408:7 | singleton2 |
728+
| calls.rb:417:13:417:48 | call to puts | calls.rb:416:9:418:11 | m1 |
729+
| calls.rb:417:13:417:48 | self | calls.rb:416:9:418:11 | m1 |
730+
| calls.rb:417:18:417:48 | "ConditionalInstanceMethods#m1" | calls.rb:416:9:418:11 | m1 |
731+
| calls.rb:417:19:417:47 | ConditionalInstanceMethods#m1 | calls.rb:416:9:418:11 | m1 |
732+
| calls.rb:422:9:422:44 | call to puts | calls.rb:421:5:433:7 | m2 |
733+
| calls.rb:422:9:422:44 | self | calls.rb:421:5:433:7 | m2 |
734+
| calls.rb:422:14:422:44 | "ConditionalInstanceMethods#m2" | calls.rb:421:5:433:7 | m2 |
735+
| calls.rb:422:15:422:43 | ConditionalInstanceMethods#m2 | calls.rb:421:5:433:7 | m2 |
736+
| calls.rb:424:9:430:11 | m3 | calls.rb:421:5:433:7 | m2 |
737+
| calls.rb:425:13:425:48 | call to puts | calls.rb:424:9:430:11 | m3 |
738+
| calls.rb:425:13:425:48 | self | calls.rb:424:9:430:11 | m3 |
739+
| calls.rb:425:18:425:48 | "ConditionalInstanceMethods#m3" | calls.rb:424:9:430:11 | m3 |
740+
| calls.rb:425:19:425:47 | ConditionalInstanceMethods#m3 | calls.rb:424:9:430:11 | m3 |
741+
| calls.rb:427:13:429:15 | m4 | calls.rb:424:9:430:11 | m3 |
742+
| calls.rb:428:17:428:52 | call to puts | calls.rb:427:13:429:15 | m4 |
743+
| calls.rb:428:17:428:52 | self | calls.rb:427:13:429:15 | m4 |
744+
| calls.rb:428:22:428:52 | "ConditionalInstanceMethods#m4" | calls.rb:427:13:429:15 | m4 |
745+
| calls.rb:428:23:428:51 | ConditionalInstanceMethods#m4 | calls.rb:427:13:429:15 | m4 |
746+
| calls.rb:432:9:432:10 | call to m3 | calls.rb:421:5:433:7 | m2 |
747+
| calls.rb:432:9:432:10 | self | calls.rb:421:5:433:7 | m2 |
748+
| calls.rb:438:17:438:40 | call to puts | calls.rb:437:13:439:15 | m5 |
749+
| calls.rb:438:17:438:40 | self | calls.rb:437:13:439:15 | m5 |
750+
| calls.rb:438:22:438:40 | "AnonymousClass#m5" | calls.rb:437:13:439:15 | m5 |
751+
| calls.rb:438:23:438:39 | AnonymousClass#m5 | calls.rb:437:13:439:15 | m5 |
752+
| calls.rb:454:13:454:22 | call to puts | calls.rb:453:9:455:11 | foo |
753+
| calls.rb:454:13:454:22 | self | calls.rb:453:9:455:11 | foo |
754+
| calls.rb:454:18:454:22 | "foo" | calls.rb:453:9:455:11 | foo |
755+
| calls.rb:454:19:454:21 | foo | calls.rb:453:9:455:11 | foo |
756+
| calls.rb:460:13:460:22 | call to puts | calls.rb:459:9:461:11 | bar |
757+
| calls.rb:460:13:460:22 | self | calls.rb:459:9:461:11 | bar |
758+
| calls.rb:460:18:460:22 | "bar" | calls.rb:459:9:461:11 | bar |
759+
| calls.rb:460:19:460:21 | bar | calls.rb:459:9:461:11 | bar |
760+
| calls.rb:479:9:479:46 | call to puts | calls.rb:478:5:480:7 | singleton |
761+
| calls.rb:479:9:479:46 | self | calls.rb:478:5:480:7 | singleton |
762+
| calls.rb:479:14:479:46 | "ExtendSingletonMethod#singleton" | calls.rb:478:5:480:7 | singleton |
763+
| calls.rb:479:15:479:45 | ExtendSingletonMethod#singleton | calls.rb:478:5:480:7 | singleton |
708764
| hello.rb:3:9:3:22 | return | hello.rb:2:5:4:7 | hello |
709765
| hello.rb:3:16:3:22 | "hello" | hello.rb:2:5:4:7 | hello |
710766
| hello.rb:3:17:3:21 | hello | hello.rb:2:5:4:7 | hello |

0 commit comments

Comments
 (0)