Skip to content

Commit bd1bd8c

Browse files
committed
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
1 parent f386888 commit bd1bd8c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

java/ql/src/utils/GenerateFlowTestCase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def qualifiedOuterNameFromSsvRow(row):
112112
with open(os.path.join(queryDir, "qlpack.yml"), "w") as f:
113113
f.write("name: test-generation-query\nversion: 0.0.0\nlibraryPathDependencies: codeql-java")
114114
with open(qlFile, "w") as f:
115-
f.write("import java\nimport utils.GenerateFlowTestCase\n\nclass GenRow extends CsvRow {\n\n\tGenRow() {\n\t\tthis = [\n")
115+
f.write("import java\nimport utils.GenerateFlowTestCase\n\nclass GenRow extends TargetSummaryModelCsv {\n\n\toverride predicate row(string r) {\n\t\tr = [\n")
116116
f.write(",\n".join('\t\t\t"%s"' % spec.strip() for spec in specs))
117117
f.write("\n\t\t]\n\t}\n}\n")
118118

java/ql/src/utils/GenerateFlowTestCase.qll

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,26 @@ import semmle.code.java.dataflow.internal.FlowSummaryImpl
88
* A CSV row to generate tests for. Users should extend this to define which
99
* tests to generate. Rows specified here should also satisfy `SummaryModelCsv.row`.
1010
*/
11-
bindingset[this]
12-
abstract class TargetSummaryModelCsv extends string {
13-
predicate modelRowExists() { any(SummaryModelCsv smc).row(this) }
11+
class TargetSummaryModelCsv extends Unit {
12+
abstract predicate row(string r);
1413
}
1514

1615
/**
1716
* Gets a CSV row for which a test has been requested, but `SummaryModelCsv.row` does not hold of it.
1817
*/
19-
query TargetSummaryModelCsv missingSummaryModelCsv() { not result.modelRowExists() }
18+
query string missingSummaryModelCsv() {
19+
any(TargetSummaryModelCsv target).row(result) and
20+
not any(SummaryModelCsv model).row(result)
21+
}
2022

2123
/**
2224
* Gets a CSV row for which a test has been requested, and `SummaryModelCsv.row` does hold, but
2325
* nonetheless we can't generate a test case for it, indicating we cannot resolve either the callable
2426
* spec or an input or output spec.
2527
*/
26-
query TargetSummaryModelCsv getAParseFailure(string reason) {
27-
result.modelRowExists() and
28+
query string getAParseFailure(string reason) {
29+
any(TargetSummaryModelCsv target).row(result) and
30+
any(SummaryModelCsv model).row(result) and
2831
(
2932
exists(
3033
string namespace, string type, boolean subtypes, string name, string signature, string ext

0 commit comments

Comments
 (0)