Skip to content

Commit 95ddd6e

Browse files
committed
Java: Generalize the inline mad test to allow further re-use.
1 parent 51e7f3b commit 95ddd6e

File tree

5 files changed

+39
-23
lines changed

5 files changed

+39
-23
lines changed
Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,50 @@
1-
signature module InlineMadTestConfigSig {
1+
import java
2+
3+
private signature module InlineMadTestLangSig {
24
/**
35
* Gets a relevant code comment, if any.
46
*/
57
string getComment();
8+
}
9+
10+
signature module InlineMadTestConfigSig {
11+
/**
12+
* Gets the kind of the captured model.
13+
*/
14+
string getKind();
615

716
/**
8-
* Gets an identified summary, if any.
17+
* Gets a captured model, if any.
918
*/
10-
string getCapturedSummary();
19+
string getCapturedModel();
1120
}
1221

13-
module InlineMadTest<InlineMadTestConfigSig Input> {
14-
bindingset[kind]
15-
private string expects(string kind) {
16-
Input::getComment().regexpCapture(" *(SPURIOUS-)?" + kind + "=(.*)", 2) = result
22+
private module InlineMadTestImpl<InlineMadTestLangSig Lang, InlineMadTestConfigSig Input> {
23+
private string expects() {
24+
Lang::getComment().regexpCapture(" *(SPURIOUS-)?" + Input::getKind() + "=(.*)", 2) = result
1725
}
1826

19-
query predicate unexpectedSummary(string msg) {
27+
query predicate unexpectedModel(string msg) {
2028
exists(string flow |
21-
flow = Input::getCapturedSummary() and
22-
not flow = expects("summary") and
23-
msg = "Unexpected summary found: " + flow
29+
flow = Input::getCapturedModel() and
30+
not flow = expects() and
31+
msg = "Unexpected " + Input::getKind() + " found: " + flow
2432
)
2533
}
2634

27-
query predicate expectedSummary(string msg) {
35+
query predicate expectedModel(string msg) {
2836
exists(string e |
29-
e = expects("summary") and
30-
not e = Input::getCapturedSummary() and
31-
msg = "Expected summary missing: " + e
37+
e = expects() and
38+
not e = Input::getCapturedModel() and
39+
msg = "Expected " + Input::getKind() + " missing: " + e
3240
)
3341
}
3442
}
43+
44+
private module InlineMadTestLang implements InlineMadTestLangSig {
45+
string getComment() { result = any(Javadoc doc).getChild(0).toString() }
46+
}
47+
48+
module InlineMadTest<InlineMadTestConfigSig Input> {
49+
import InlineMadTestImpl<InlineMadTestLang, Input>
50+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
unexpectedSummary
2-
expectedSummary
1+
unexpectedModel
2+
expectedModel

java/ql/test/utils/modelgenerator/dataflow/CaptureModels.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import utils.modelgenerator.internal.CaptureSummaryFlowQuery
33
import TestUtilities.InlineMadTest
44

55
module InlineMadTestConfig implements InlineMadTestConfigSig {
6-
string getComment() { result = any(Javadoc doc).getChild(0).toString() }
6+
string getCapturedModel() { result = captureFlow(_) }
77

8-
string getCapturedSummary() { result = captureFlow(_) }
8+
string getKind() { result = "summary" }
99
}
1010

1111
import InlineMadTest<InlineMadTestConfig>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
unexpectedSummary
2-
expectedSummary
1+
unexpectedModel
2+
expectedModel

java/ql/test/utils/modelgenerator/typebasedflow/CaptureTypeBasedSummaryModels.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import TestUtilities.InlineMadTest
33
import utils.modelgenerator.internal.CaptureTypeBasedSummaryModels
44

55
module InlineMadTestConfig implements InlineMadTestConfigSig {
6-
string getComment() { result = any(Javadoc doc).getChild(0).toString() }
6+
string getCapturedModel() { result = captureFlow(_) }
77

8-
string getCapturedSummary() { result = captureFlow(_) }
8+
string getKind() { result = "summary" }
99
}
1010

1111
import InlineMadTest<InlineMadTestConfig>

0 commit comments

Comments
 (0)