Skip to content

Rust: Remove external locations in tests using post-processing #19669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions rust/ql/lib/utils/test/ExternalLocationPostProcessing.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @kind test-postprocess
*/

private import rust
private import codeql.util.test.ExternalLocationPostProcessing
import Make<getSourceLocationPrefix/0>

private string getSourceLocationPrefix() { sourceLocationPrefix(result) }
210 changes: 105 additions & 105 deletions rust/ql/test/library-tests/dataflow/local/DataFlowStep.expected

Large diffs are not rendered by default.

17 changes: 2 additions & 15 deletions rust/ql/test/library-tests/dataflow/local/DataFlowStep.ql
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,14 @@ query predicate localStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
RustDataFlow::simpleLocalFlowStep(nodeFrom, nodeTo, "")
}

class Content extends DataFlow::Content {
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
exists(string file |
this.getLocation().hasLocationInfo(file, startline, startcolumn, endline, endcolumn) and
filepath =
file.regexpReplaceAll("^/.*/tools/builtins/", "/BUILTINS/")
.regexpReplaceAll("^/.*/.rustup/toolchains/[^/]+/", "/RUSTUP_HOME/toolchain/")
)
}
}

class Node extends DataFlow::Node {
Node() { not this instanceof FlowSummaryNode }
}

query predicate storeStep(Node node1, Content c, Node node2) {
query predicate storeStep(Node node1, DataFlow::Content c, Node node2) {
RustDataFlow::storeContentStep(node1, c, node2)
}

query predicate readStep(Node node1, Content c, Node node2) {
query predicate readStep(Node node1, DataFlow::Content c, Node node2) {
RustDataFlow::readContentStep(node1, c, node2)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
query: DataFlowStep.ql
postprocess: utils/test/ExternalLocationPostProcessing.ql
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
testFailures
mod
| lib.rs:1:1:1:7 | mod my |
| main.rs:1:1:1:7 | mod my |
Expand Down Expand Up @@ -77,7 +76,7 @@ resolvePath
| main.rs:68:5:68:8 | self | main.rs:1:1:653:2 | SourceFile |
| main.rs:68:5:68:11 | ...::i | main.rs:71:1:83:1 | fn i |
| main.rs:74:13:74:15 | Foo | main.rs:48:1:48:13 | struct Foo |
| main.rs:78:16:78:18 | i32 | file:///BUILTINS/types.rs:12:1:12:15 | struct i32 |
| main.rs:78:16:78:18 | i32 | {EXTERNAL LOCATION} | struct i32 |
| main.rs:81:17:81:19 | Foo | main.rs:77:9:79:9 | struct Foo |
| main.rs:85:5:85:7 | my2 | main.rs:7:1:7:8 | mod my2 |
| main.rs:85:5:85:16 | ...::nested2 | my2/mod.rs:1:1:1:16 | mod nested2 |
Expand All @@ -93,8 +92,8 @@ resolvePath
| main.rs:117:13:117:21 | ...::m5 | main.rs:103:1:107:1 | mod m5 |
| main.rs:118:9:118:9 | f | main.rs:104:5:106:5 | fn f |
| main.rs:118:9:118:9 | f | main.rs:110:5:112:5 | fn f |
| main.rs:125:13:125:15 | i32 | file:///BUILTINS/types.rs:12:1:12:15 | struct i32 |
| main.rs:128:16:128:18 | i32 | file:///BUILTINS/types.rs:12:1:12:15 | struct i32 |
| main.rs:125:13:125:15 | i32 | {EXTERNAL LOCATION} | struct i32 |
| main.rs:128:16:128:18 | i32 | {EXTERNAL LOCATION} | struct i32 |
| main.rs:134:19:134:24 | MyEnum | main.rs:123:5:131:5 | enum MyEnum |
| main.rs:137:17:137:22 | MyEnum | main.rs:123:5:131:5 | enum MyEnum |
| main.rs:137:17:137:25 | ...::A | main.rs:124:9:126:9 | A |
Expand Down Expand Up @@ -351,19 +350,20 @@ resolvePath
| my.rs:18:9:18:11 | my4 | my.rs:14:1:16:1 | mod my4 |
| my.rs:18:9:18:16 | ...::my5 | my.rs:15:5:15:16 | mod my5 |
| my.rs:18:9:18:19 | ...::f | my/my4/my5/mod.rs:1:1:3:1 | fn f |
| my.rs:22:5:22:9 | std | file:///RUSTUP_HOME/toolchain/lib/rustlib/src/rust/library/std/src/lib.rs:0:0:0:0 | Crate(std@0.0.0) |
| my.rs:22:5:22:17 | ...::result | file:///RUSTUP_HOME/toolchain/lib/rustlib/src/rust/library/core/src/lib.rs:356:1:356:15 | mod result |
| my.rs:22:5:24:12 | ...::Result::<...> | file:///RUSTUP_HOME/toolchain/lib/rustlib/src/rust/library/core/src/result.rs:520:1:538:1 | enum Result |
| my.rs:22:5:22:9 | std | {EXTERNAL LOCATION} | Crate(std@0.0.0) |
| my.rs:22:5:22:17 | ...::result | {EXTERNAL LOCATION} | mod result |
| my.rs:22:5:24:12 | ...::Result::<...> | {EXTERNAL LOCATION} | enum Result |
| my.rs:23:5:23:5 | T | my.rs:21:5:21:5 | T |
| my.rs:28:8:28:10 | i32 | file:///BUILTINS/types.rs:12:1:12:15 | struct i32 |
| my.rs:29:8:29:10 | i32 | file:///BUILTINS/types.rs:12:1:12:15 | struct i32 |
| my.rs:28:8:28:10 | i32 | {EXTERNAL LOCATION} | struct i32 |
| my.rs:29:8:29:10 | i32 | {EXTERNAL LOCATION} | struct i32 |
| my.rs:30:6:30:16 | Result::<...> | my.rs:18:34:25:1 | type Result<...> |
| my.rs:30:13:30:15 | i32 | file:///BUILTINS/types.rs:12:1:12:15 | struct i32 |
| my.rs:33:16:33:18 | Err | file:///RUSTUP_HOME/toolchain/lib/rustlib/src/rust/library/core/src/result.rs:534:5:537:56 | Err |
| my.rs:35:5:35:6 | Ok | file:///RUSTUP_HOME/toolchain/lib/rustlib/src/rust/library/core/src/result.rs:529:5:532:55 | Ok |
| my.rs:30:13:30:15 | i32 | {EXTERNAL LOCATION} | struct i32 |
| my.rs:33:16:33:18 | Err | {EXTERNAL LOCATION} | Err |
| my.rs:35:5:35:6 | Ok | {EXTERNAL LOCATION} | Ok |
| my/nested.rs:9:13:9:13 | f | my/nested.rs:3:9:5:9 | fn f |
| my/nested.rs:15:9:15:15 | nested2 | my/nested.rs:2:5:11:5 | mod nested2 |
| my/nested.rs:15:9:15:18 | ...::f | my/nested.rs:3:9:5:9 | fn f |
| my/nested.rs:21:5:21:11 | nested1 | my/nested.rs:1:1:17:1 | mod nested1 |
| my/nested.rs:21:5:21:20 | ...::nested2 | my/nested.rs:2:5:11:5 | mod nested2 |
| my/nested.rs:21:5:21:23 | ...::f | my/nested.rs:3:9:5:9 | fn f |
testFailures
17 changes: 1 addition & 16 deletions rust/ql/test/library-tests/path-resolution/path-resolution.ql
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,7 @@ import TestUtils

query predicate mod(Module m) { toBeTested(m) }

final private class ItemNodeFinal = ItemNode;

class ItemNodeLoc extends ItemNodeFinal {
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
exists(string file |
this.getLocation().hasLocationInfo(file, startline, startcolumn, endline, endcolumn) and
filepath =
file.regexpReplaceAll("^/.*/.rustup/toolchains/[^/]+/", "/RUSTUP_HOME/toolchain/")
.regexpReplaceAll("^/.*/tools/builtins/", "/BUILTINS/")
)
}
}

query predicate resolvePath(Path p, ItemNodeLoc i) {
query predicate resolvePath(Path p, ItemNode i) {
toBeTested(p) and
not p.isFromMacroExpansion() and
i = resolvePath(p)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
query: path-resolution.ql
postprocess: utils/test/ExternalLocationPostProcessing.ql
Loading
Loading