Skip to content

Commit 78b8a92

Browse files
committed
Share the Models as Data inline expect predicates.
1 parent e483948 commit 78b8a92

File tree

2 files changed

+55
-51
lines changed

2 files changed

+55
-51
lines changed

java/ql/test/TestUtilities/InlineMadTest.qll

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,5 @@
1-
import java as J
2-
3-
private signature module InlineMadTestLangSig {
4-
/**
5-
* A base class of callables for modeling.
6-
*/
7-
class Callable;
8-
9-
/**
10-
* Gets a relevant code comment for `c`, if any.
11-
*/
12-
string getComment(Callable c);
13-
}
14-
15-
private module InlineMadTestImpl<InlineMadTestLangSig Lang> {
16-
private class Callable = Lang::Callable;
17-
18-
signature module InlineMadTestConfigSig {
19-
/**
20-
* Gets the kind of a captured model.
21-
*/
22-
string getKind();
23-
24-
/**
25-
* Gets a captured model for `c`, if any.
26-
*/
27-
string getCapturedModel(Callable c);
28-
}
29-
30-
module InlineMadTest<InlineMadTestConfigSig Input> {
31-
private string expects(Callable c) {
32-
Lang::getComment(c).regexpCapture(" *(SPURIOUS-)?" + Input::getKind() + "=(.*)", 2) = result
33-
}
34-
35-
query predicate unexpectedModel(string msg) {
36-
exists(Callable c, string flow |
37-
flow = Input::getCapturedModel(c) and
38-
not flow = expects(c) and
39-
msg = "Unexpected " + Input::getKind() + " found: " + flow
40-
)
41-
}
42-
43-
query predicate expectedModel(string msg) {
44-
exists(Callable c, string e |
45-
e = expects(c) and
46-
not e = Input::getCapturedModel(c) and
47-
msg = "Expected " + Input::getKind() + " missing: " + e
48-
)
49-
}
50-
}
51-
}
1+
private import java as J
2+
private import codeql.mad.test.InlineMadTest
523

534
private module InlineMadTestLang implements InlineMadTestLangSig {
545
class Callable = J::Callable;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Provides some simple predicates for models as data related tests using
3+
* inline expectations (as comments in the source code).
4+
*/
5+
signature module InlineMadTestLangSig {
6+
/**
7+
* A base class of callables for modeling.
8+
*/
9+
class Callable;
10+
11+
/**
12+
* Gets a relevant code comment for `c`, if any.
13+
*/
14+
string getComment(Callable c);
15+
}
16+
17+
module InlineMadTestImpl<InlineMadTestLangSig Lang> {
18+
private class Callable = Lang::Callable;
19+
20+
signature module InlineMadTestConfigSig {
21+
/**
22+
* Gets a captured model for `c`, if any.
23+
*/
24+
string getCapturedModel(Callable c);
25+
26+
/**
27+
* Gets the kind of a captured model.
28+
*/
29+
string getKind();
30+
}
31+
32+
module InlineMadTest<InlineMadTestConfigSig Input> {
33+
private string expects(Callable c) {
34+
Lang::getComment(c).regexpCapture(" *(SPURIOUS-)?" + Input::getKind() + "=(.*)", 2) = result
35+
}
36+
37+
query predicate unexpectedModel(string msg) {
38+
exists(Callable c, string flow |
39+
flow = Input::getCapturedModel(c) and
40+
not flow = expects(c) and
41+
msg = "Unexpected " + Input::getKind() + " found: " + flow
42+
)
43+
}
44+
45+
query predicate expectedModel(string msg) {
46+
exists(Callable c, string e |
47+
e = expects(c) and
48+
not e = Input::getCapturedModel(c) and
49+
msg = "Expected " + Input::getKind() + " missing: " + e
50+
)
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)