@@ -6,20 +6,26 @@ import codeql.ruby.ApiGraphs
66class ApiUseTest extends InlineExpectationsTest {
77 ApiUseTest ( ) { this = "ApiUseTest" }
88
9- override string getARelevantTag ( ) { result = "use" }
9+ override string getARelevantTag ( ) { result = [ "use" , "def" ] }
1010
11- private predicate relevantNode ( API:: Node a , DataFlow:: Node n , Location l ) {
12- n = a .getAUse ( ) and
13- l = n .getLocation ( )
11+ private predicate relevantNode ( API:: Node a , DataFlow:: Node n , Location l , string tag ) {
12+ l = n .getLocation ( ) and
13+ (
14+ tag = "use" and
15+ n = a .getAUse ( )
16+ or
17+ tag = "def" and
18+ n = a .getARhs ( )
19+ )
1420 }
1521
1622 override predicate hasActualResult ( Location location , string element , string tag , string value ) {
17- exists ( API :: Node a , DataFlow :: Node n | relevantNode ( a , n , location ) |
18- tag = "use" and
23+ tag = "use" and // def tags are always optional
24+ exists ( API :: Node a , DataFlow :: Node n | relevantNode ( a , n , location , tag ) |
1925 // Only report the longest path on this line:
2026 value =
2127 max ( API:: Node a2 , Location l2 , DataFlow:: Node n2 |
22- relevantNode ( a2 , n2 , l2 ) and
28+ relevantNode ( a2 , n2 , l2 , tag ) and
2329 l2 .getFile ( ) = location .getFile ( ) and
2430 l2 .getStartLine ( ) = location .getStartLine ( )
2531 |
@@ -34,8 +40,7 @@ class ApiUseTest extends InlineExpectationsTest {
3440 // We also permit optional annotations for any other path on the line.
3541 // This is used to test subclass paths, which typically have a shorter canonical path.
3642 override predicate hasOptionalResult ( Location location , string element , string tag , string value ) {
37- exists ( API:: Node a , DataFlow:: Node n | relevantNode ( a , n , location ) |
38- tag = "use" and
43+ exists ( API:: Node a , DataFlow:: Node n | relevantNode ( a , n , location , tag ) |
3944 element = n .toString ( ) and
4045 value = getAPath ( a , _)
4146 )
0 commit comments