mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Rust: Remove external locations in tests using post-processing
This commit is contained in:
@@ -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) }
|
||||
}
|
||||
@@ -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) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user