Rust: Remove external locations in tests using post-processing

This commit is contained in:
Tom Hvitved
2025-06-04 11:30:35 +02:00
parent 0ef17ba231
commit aa0fc05df8
12 changed files with 684 additions and 682 deletions

View File

@@ -0,0 +1,30 @@
/**
* Provides logic for creating a `@kind test-postprocess` query that converts
* external locations to a special `{EXTERNAL LOCATION}` string.
*
* This is useful for writing tests that use real locations when executed in
* VS Code, but prevents the "Location is outside of test directory" warning
* when executed through `codeql test run`.
*/
module;
external private predicate queryResults(string relation, int row, int column, string data);
external private predicate queryRelations(string relation);
private signature string getSourceLocationPrefixSig();
module Make<getSourceLocationPrefixSig/0 getSourceLocationPrefix> {
query predicate results(string relation, int row, int column, string data) {
exists(string s | queryResults(relation, row, column, s) |
if
not s = "file://" + any(string suffix) or
s = "file://:0:0:0:0" or
s = getSourceLocationPrefix() + any(string suffix)
then data = s
else data = "{EXTERNAL LOCATION}"
)
}
query predicate resultRelations(string relation) { queryRelations(relation) }
}

View File

@@ -627,11 +627,11 @@ private string mainResultSet() { result = ["#select", "problems"] }
* to be matched.
*/
module TestPostProcessing {
external predicate queryResults(string relation, int row, int column, string data);
external private predicate queryResults(string relation, int row, int column, string data);
external predicate queryRelations(string relation);
external private predicate queryRelations(string relation);
external predicate queryMetadata(string key, string value);
external private predicate queryMetadata(string key, string value);
private string getQueryId() { queryMetadata("id", result) }