Switch to an abstract unit / predicate approach to specifying rows to generate tests for

This enables moving this code into the qll file, rather than having to specify a query predicate in the .ql
This commit is contained in:
Chris Smowton
2021-06-21 20:07:34 +01:00
parent f3868887b8
commit bd1bd8cf08
2 changed files with 10 additions and 7 deletions

View File

@@ -112,7 +112,7 @@ qlFile = os.path.join(queryDir, "gen.ql")
with open(os.path.join(queryDir, "qlpack.yml"), "w") as f:
f.write("name: test-generation-query\nversion: 0.0.0\nlibraryPathDependencies: codeql-java")
with open(qlFile, "w") as f:
f.write("import java\nimport utils.GenerateFlowTestCase\n\nclass GenRow extends CsvRow {\n\n\tGenRow() {\n\t\tthis = [\n")
f.write("import java\nimport utils.GenerateFlowTestCase\n\nclass GenRow extends TargetSummaryModelCsv {\n\n\toverride predicate row(string r) {\n\t\tr = [\n")
f.write(",\n".join('\t\t\t"%s"' % spec.strip() for spec in specs))
f.write("\n\t\t]\n\t}\n}\n")

View File

@@ -8,23 +8,26 @@ import semmle.code.java.dataflow.internal.FlowSummaryImpl
* A CSV row to generate tests for. Users should extend this to define which
* tests to generate. Rows specified here should also satisfy `SummaryModelCsv.row`.
*/
bindingset[this]
abstract class TargetSummaryModelCsv extends string {
predicate modelRowExists() { any(SummaryModelCsv smc).row(this) }
class TargetSummaryModelCsv extends Unit {
abstract predicate row(string r);
}
/**
* Gets a CSV row for which a test has been requested, but `SummaryModelCsv.row` does not hold of it.
*/
query TargetSummaryModelCsv missingSummaryModelCsv() { not result.modelRowExists() }
query string missingSummaryModelCsv() {
any(TargetSummaryModelCsv target).row(result) and
not any(SummaryModelCsv model).row(result)
}
/**
* Gets a CSV row for which a test has been requested, and `SummaryModelCsv.row` does hold, but
* nonetheless we can't generate a test case for it, indicating we cannot resolve either the callable
* spec or an input or output spec.
*/
query TargetSummaryModelCsv getAParseFailure(string reason) {
result.modelRowExists() and
query string getAParseFailure(string reason) {
any(TargetSummaryModelCsv target).row(result) and
any(SummaryModelCsv model).row(result) and
(
exists(
string namespace, string type, boolean subtypes, string name, string signature, string ext