Skip to content

Commit e58a833

Browse files
committed
C++: Add test for asDefinition.
1 parent 949fc37 commit e58a833

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
struct S {
2+
int x;
3+
};
4+
5+
void use(int);
6+
7+
void test() {
8+
int y = 43; // $ asDefinition=43
9+
use(y);
10+
y = 44; // $ asDefinition="... = ..."
11+
use(y);
12+
13+
int x = 43; // $ MISSING: asDefinition=43
14+
x = 44; // $ MISSING: asDefinition="... = ..."
15+
16+
S s;
17+
s.x = 42; // $ MISSING: asDefinition="... = ..."
18+
}

cpp/ql/test/library-tests/dataflow/asDefinition/test.expected

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import cpp
2+
import utils.test.InlineExpectationsTest
3+
import semmle.code.cpp.dataflow.new.DataFlow::DataFlow
4+
5+
bindingset[s]
6+
string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s }
7+
8+
module AsDefinitionTest implements TestSig {
9+
string getARelevantTag() { result = "asDefinition" }
10+
11+
predicate hasActualResult(Location location, string element, string tag, string value) {
12+
exists(Node n, Expr e |
13+
e = n.asDefinition() and
14+
location = e.getLocation() and
15+
element = n.toString() and
16+
tag = "asDefinition" and
17+
value = quote(e.toString())
18+
)
19+
}
20+
}
21+
22+
import MakeTest<AsDefinitionTest>

0 commit comments

Comments
 (0)