mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Rust: Add cross-crate path resolution test
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use lib::a_module::hello;
|
||||
use lib::a_module::hello; // $ MISSING: item=HELLO
|
||||
|
||||
mod a_module;
|
||||
|
||||
fn main() {
|
||||
hello();
|
||||
hello(); // $ MISSING: item=HELLO
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
pub fn hello() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
} // HELLO
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
import utils.test.PathResolutionInlineExpectationsTest
|
||||
@@ -2,14 +2,23 @@
|
||||
"sysroot_src": "filled by the rust_project fixture",
|
||||
"crates": [
|
||||
{
|
||||
"display_name": "exe",
|
||||
"version": "0.1.0",
|
||||
"root_module": "exe/src/main.rs",
|
||||
"edition": "2021",
|
||||
"deps": [{"crate": 1, "name": "lib"}]
|
||||
"deps": [
|
||||
{
|
||||
"crate": 1,
|
||||
"name": "lib"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"display_name": "lib",
|
||||
"version": "0.1.0",
|
||||
"root_module": "lib/src/lib.rs",
|
||||
"edition": "2021",
|
||||
"deps": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
| Elements extracted | 87 |
|
||||
| Elements extracted | 90 |
|
||||
| Elements unextracted | 0 |
|
||||
| Extraction errors | 0 |
|
||||
| Extraction warnings | 0 |
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
| Elements extracted | 87 |
|
||||
| Elements extracted | 90 |
|
||||
| Elements unextracted | 0 |
|
||||
| Extraction errors | 0 |
|
||||
| Extraction warnings | 0 |
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Provides an inline expectations test for path resolution.
|
||||
*/
|
||||
|
||||
private import rust
|
||||
private import codeql.rust.internal.PathResolution
|
||||
private import codeql.rust.internal.TypeInference
|
||||
private import utils.test.InlineExpectationsTest
|
||||
|
||||
private module ResolveTest implements TestSig {
|
||||
string getARelevantTag() { result = "item" }
|
||||
|
||||
private predicate itemAt(ItemNode i, string filepath, int line, boolean inMacro) {
|
||||
i.getLocation().hasLocationInfo(filepath, _, _, line, _) and
|
||||
if i.(AstNode).isInMacroExpansion() then inMacro = true else inMacro = false
|
||||
}
|
||||
|
||||
private predicate commmentAt(string text, string filepath, int line) {
|
||||
exists(Comment c |
|
||||
c.getLocation().hasLocationInfo(filepath, line, _, _, _) and
|
||||
c.getCommentText() = text
|
||||
)
|
||||
}
|
||||
|
||||
private predicate item(ItemNode i, string value) {
|
||||
exists(string filepath, int line, boolean inMacro | itemAt(i, filepath, line, inMacro) |
|
||||
commmentAt(value, filepath, line) and inMacro = false
|
||||
or
|
||||
not (commmentAt(_, filepath, line) and inMacro = false) and
|
||||
value = i.getName()
|
||||
)
|
||||
}
|
||||
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(AstNode n |
|
||||
not n = any(Path parent).getQualifier() and
|
||||
location = n.getLocation() and
|
||||
element = n.toString() and
|
||||
tag = "item"
|
||||
|
|
||||
item(resolvePath(n), value)
|
||||
or
|
||||
item(n.(MethodCallExpr).getStaticTarget(), value)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<ResolveTest>
|
||||
@@ -1,49 +1,8 @@
|
||||
import rust
|
||||
import codeql.rust.internal.PathResolution
|
||||
import codeql.rust.internal.TypeInference
|
||||
import utils.test.InlineExpectationsTest
|
||||
import utils.test.PathResolutionInlineExpectationsTest
|
||||
import TestUtils
|
||||
|
||||
query predicate mod(Module m) { toBeTested(m) }
|
||||
|
||||
query predicate resolvePath(Path p, ItemNode i) { toBeTested(p) and i = resolvePath(p) }
|
||||
|
||||
module ResolveTest implements TestSig {
|
||||
string getARelevantTag() { result = "item" }
|
||||
|
||||
private predicate itemAt(ItemNode i, string filepath, int line, boolean inMacro) {
|
||||
i.getLocation().hasLocationInfo(filepath, _, _, line, _) and
|
||||
if i.isInMacroExpansion() then inMacro = true else inMacro = false
|
||||
}
|
||||
|
||||
private predicate commmentAt(string text, string filepath, int line) {
|
||||
exists(Comment c |
|
||||
c.getLocation().hasLocationInfo(filepath, line, _, _, _) and
|
||||
c.getCommentText() = text
|
||||
)
|
||||
}
|
||||
|
||||
private predicate item(ItemNode i, string value) {
|
||||
exists(string filepath, int line, boolean inMacro | itemAt(i, filepath, line, inMacro) |
|
||||
commmentAt(value, filepath, line) and inMacro = false
|
||||
or
|
||||
not (commmentAt(_, filepath, line) and inMacro = false) and
|
||||
value = i.getName()
|
||||
)
|
||||
}
|
||||
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(AstNode n |
|
||||
not n = any(Path parent).getQualifier() and
|
||||
location = n.getLocation() and
|
||||
element = n.toString() and
|
||||
tag = "item"
|
||||
|
|
||||
item(resolvePath(n), value)
|
||||
or
|
||||
item(n.(MethodCallExpr).getStaticTarget(), value)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<ResolveTest>
|
||||
|
||||
Reference in New Issue
Block a user