Skip to content

Commit c5403f4

Browse files
authored
Merge pull request github#16431 from michaelnebel/java/madinlinetest
Java: Models as Data inline like test.
2 parents 871fd9a + 5fe3ab7 commit c5403f4

34 files changed

+998
-925
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
}
52+
53+
private module InlineMadTestLang implements InlineMadTestLangSig {
54+
class Callable = J::Callable;
55+
56+
string getComment(Callable c) {
57+
exists(J::Javadoc doc |
58+
hasJavadoc(c, doc) and
59+
isNormalComment(doc) and
60+
result = doc.getChild(0).toString()
61+
)
62+
}
63+
}
64+
65+
import InlineMadTestImpl<InlineMadTestLang>
Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,2 @@
1-
| p;Factory;getIntValue;();summary;df-generated |
2-
| p;FinalClass;returnsConstant;();summary;df-generated |
3-
| p;FluentAPI$Inner;notThis;(String);summary;df-generated |
4-
| p;ImmutablePojo;getX;();summary;df-generated |
5-
| p;Joiner;length;();summary;df-generated |
6-
| p;ParamFlow;ignorePrimitiveReturnValue;(String);summary;df-generated |
7-
| p;ParamFlow;mapType;(Class);summary;df-generated |
8-
| p;Pojo;doNotSetValue;(String);summary;df-generated |
9-
| p;Pojo;getBigDecimal;();summary;df-generated |
10-
| p;Pojo;getBigInt;();summary;df-generated |
11-
| p;Pojo;getBoxedArray;();summary;df-generated |
12-
| p;Pojo;getBoxedCollection;();summary;df-generated |
13-
| p;Pojo;getBoxedValue;();summary;df-generated |
14-
| p;Pojo;getFloatArray;();summary;df-generated |
15-
| p;Pojo;getIntValue;();summary;df-generated |
16-
| p;Pojo;getPrimitiveArray;();summary;df-generated |
17-
| p;PrivateFlowViaPublicInterface$SPI;openStreamNone;();summary;df-generated |
18-
| p;PrivateFlowViaPublicInterface;createAnSPIWithoutTrackingFile;(File);summary;df-generated |
19-
| p;Sinks;copyFileToDirectory;(Path,Path,CopyOption[]);summary;df-generated |
20-
| p;Sinks;propagate;(String);summary;df-generated |
21-
| p;Sinks;readUrl;(URL,Charset);summary;df-generated |
22-
| p;Sources;readUrl;(URL);summary;df-generated |
23-
| p;Sources;socketStream;();summary;df-generated |
24-
| p;Sources;sourceToParameter;(InputStream[],List);summary;df-generated |
25-
| p;Sources;wrappedSocketStream;();summary;df-generated |
1+
unexpectedModel
2+
expectedModel
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import java
2+
import utils.modelgenerator.internal.CaptureSummaryFlowQuery
3+
import TestUtilities.InlineMadTest
4+
5+
module InlineMadTestConfig implements InlineMadTestConfigSig {
6+
string getCapturedModel(Callable c) { result = captureNoFlow(c) }
7+
8+
string getKind() { result = "neutral" }
9+
}
10+
11+
import InlineMadTest<InlineMadTestConfig>

java/ql/test/utils/modelgenerator/dataflow/CaptureNeutralModels.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
| p;PrivateFlowViaPublicInterface$SPI;true;openStream;();;Argument[this];path-injection;df-generated |
2-
| p;Sinks;true;copyFileToDirectory;(Path,Path,CopyOption[]);;Argument[0];path-injection;df-generated |
3-
| p;Sinks;true;copyFileToDirectory;(Path,Path,CopyOption[]);;Argument[1];path-injection;df-generated |
4-
| p;Sinks;true;readUrl;(URL,Charset);;Argument[0];request-forgery;df-generated |
5-
| p;Sources;true;readUrl;(URL);;Argument[0];request-forgery;df-generated |
1+
unexpectedModel
2+
expectedModel
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import java
2+
import utils.modelgenerator.internal.CaptureModels
3+
import TestUtilities.InlineMadTest
4+
5+
module InlineMadTestConfig implements InlineMadTestConfigSig {
6+
string getCapturedModel(Callable c) { result = captureSink(c) }
7+
8+
string getKind() { result = "sink" }
9+
}
10+
11+
import InlineMadTest<InlineMadTestConfig>

java/ql/test/utils/modelgenerator/dataflow/CaptureSinkModels.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
| p;Sources;true;readUrl;(URL);;ReturnValue;remote;df-generated |
2-
| p;Sources;true;socketStream;();;ReturnValue;remote;df-generated |
3-
| p;Sources;true;sourceToParameter;(InputStream[],List);;Argument[0].ArrayElement;remote;df-generated |
4-
| p;Sources;true;sourceToParameter;(InputStream[],List);;Argument[1].Element;remote;df-generated |
5-
| p;Sources;true;wrappedSocketStream;();;ReturnValue;remote;df-generated |
1+
unexpectedModel
2+
expectedModel
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import java
2+
import utils.modelgenerator.internal.CaptureModels
3+
import TestUtilities.InlineMadTest
4+
5+
module InlineMadTestConfig implements InlineMadTestConfigSig {
6+
string getCapturedModel(Callable c) { result = captureSource(c) }
7+
8+
string getKind() { result = "source" }
9+
}
10+
11+
import InlineMadTest<InlineMadTestConfig>

java/ql/test/utils/modelgenerator/dataflow/CaptureSourceModels.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)