mirror of
https://github.com/github/codeql.git
synced 2026-02-11 20:51:06 +01:00
C++: Add test for asDefinition.
This commit is contained in:
18
cpp/ql/test/library-tests/dataflow/asDefinition/test.cpp
Normal file
18
cpp/ql/test/library-tests/dataflow/asDefinition/test.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
struct S {
|
||||
int x;
|
||||
};
|
||||
|
||||
void use(int);
|
||||
|
||||
void test() {
|
||||
int y = 43; // $ asDefinition=43
|
||||
use(y);
|
||||
y = 44; // $ asDefinition="... = ..."
|
||||
use(y);
|
||||
|
||||
int x = 43; // $ MISSING: asDefinition=43
|
||||
x = 44; // $ MISSING: asDefinition="... = ..."
|
||||
|
||||
S s;
|
||||
s.x = 42; // $ MISSING: asDefinition="... = ..."
|
||||
}
|
||||
22
cpp/ql/test/library-tests/dataflow/asDefinition/test.ql
Normal file
22
cpp/ql/test/library-tests/dataflow/asDefinition/test.ql
Normal file
@@ -0,0 +1,22 @@
|
||||
import cpp
|
||||
import utils.test.InlineExpectationsTest
|
||||
import semmle.code.cpp.dataflow.new.DataFlow::DataFlow
|
||||
|
||||
bindingset[s]
|
||||
string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s }
|
||||
|
||||
module AsDefinitionTest implements TestSig {
|
||||
string getARelevantTag() { result = "asDefinition" }
|
||||
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(Node n, Expr e |
|
||||
e = n.asDefinition() and
|
||||
location = e.getLocation() and
|
||||
element = n.toString() and
|
||||
tag = "asDefinition" and
|
||||
value = quote(e.toString())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<AsDefinitionTest>
|
||||
Reference in New Issue
Block a user