Skip to content

Commit 65655db

Browse files
committed
java inline expectations prototype with tests
1 parent 3ae4cb2 commit 65655db

File tree

44 files changed

+318
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+318
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import java
2+
3+
external predicate queryResults(string relation, int row, int column, string data);
4+
5+
string actualLines() {
6+
exists(int i |
7+
queryResults("#select", i, _, _) and
8+
result =
9+
" | " +
10+
concat(int j, string cell | queryResults("#select", i, j, cell) | cell, " | " order by j) +
11+
" | "
12+
)
13+
}
14+
15+
predicate parsedExpectedResults(string filename, int line, string content) {
16+
exists(Javadoc doc |
17+
isEolComment(doc) and
18+
filename = doc.getLocation().getFile().getBaseName() and
19+
line = doc.getLocation().getStartLine() and
20+
line = doc.getLocation().getEndLine() and
21+
content = doc.getChild(0).getText().trim()
22+
)
23+
}
24+
25+
predicate expectError(string filename, int line) {
26+
exists(string content |
27+
parsedExpectedResults(filename, line, content) and content.indexOf("NOT OK") = 0
28+
)
29+
}
30+
31+
predicate expectPass(string filename, int line) {
32+
exists(string content |
33+
parsedExpectedResults(filename, line, content) and content.indexOf("OK") = 0
34+
)
35+
}
36+
37+
predicate parsedActualResults(string filename, int line, int colStart, int colEnd, string content) {
38+
exists(string s, string posString, string lineString |
39+
s = actualLines() and
40+
posString = s.substring(s.indexOf("|", 0, 0) + 1, s.indexOf("|", 1, 0)).trim() and
41+
filename = posString.substring(0, posString.indexOf(":", 0, 0)) and
42+
lineString = posString.substring(posString.indexOf(":", 0, 0) + 1, posString.indexOf(":", 1, 0)) and
43+
lineString = posString.substring(posString.indexOf(":", 2, 0) + 1, posString.indexOf(":", 3, 0)) and
44+
colStart =
45+
posString.substring(posString.indexOf(":", 1, 0) + 1, posString.indexOf(":", 2, 0)).toInt() and
46+
colEnd = posString.substring(posString.indexOf(":", 3, 0) + 1, posString.length()).toInt() and
47+
line = lineString.toInt() and
48+
content = s.substring(s.indexOf("|", 2, 0) + 1, s.indexOf("|", 3, 0)).trim()
49+
)
50+
}
51+
52+
predicate actualExpectedDiff(string type, string position, string error) {
53+
exists(string filename, int line, int colStart, int colEnd |
54+
parsedActualResults(filename, line, colStart, colEnd, error) and
55+
expectPass(filename, line) and
56+
type = "unexpected alert" and
57+
position = filename + ":" + line + ":" + colStart + ":" + line + ":" + colEnd
58+
)
59+
or
60+
exists(string filename, int line |
61+
expectError(filename, line) and
62+
not parsedActualResults(filename, line, _, _, _) and
63+
type = "expected alert" and
64+
position = filename + ":" + line and
65+
parsedExpectedResults(filename, line, error)
66+
)
67+
or
68+
exists(string filename, int line, string content |
69+
parsedExpectedResults(filename, line, content) and
70+
not expectPass(filename, line) and
71+
not expectError(filename, line) and
72+
type = "invalid inline expectation" and
73+
position = filename + ":" + line and
74+
error = content
75+
)
76+
}
77+
78+
from int line, string position, int column, string content
79+
where
80+
position = rank[line](string p | actualExpectedDiff(_, p, _) | p) and
81+
(
82+
column = 0 and content = position
83+
or
84+
column = 1 and actualExpectedDiff(content, position, _)
85+
or
86+
column = 2 and actualExpectedDiff(_, position, content)
87+
)
88+
select "#select", line, column, content
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
query predicate resultRelations(string name) { name = "#select" }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
query predicate learnEdits(string name) { none() }
2+
3+
select "#select", 1, 1, "foo"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
query predicate extraQuery(string name) { none() }
2+
3+
select "#select", 1, 1, "foo"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
query predicate resultRelations(string name, int arity) { name = "#select" and arity = 5 }
2+
3+
select "#select", 1, 1, "foo"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
select "#select", "1", 1, "foo"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
select "#select", 1, 1, ["foo", "bar"]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from int i, int j
2+
where
3+
i in [1, 2] and
4+
j in [1, 2] and
5+
not (i = 2 and j = 2)
6+
select "#select", i, j, "foo"

java/ql/test/query-tests/Postprocessing/failing/OverlyLargeRangeQuery.expected

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: Security/CWE/CWE-020/OverlyLargeRange.ql
2+
postprocess: TestUtilities/JavaInlineExpectations.ql

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy