diff --git a/cpp/ql/test/library-tests/dataflow/asDefinition/test.cpp b/cpp/ql/test/library-tests/dataflow/asDefinition/test.cpp new file mode 100644 index 00000000000..6af97c18b15 --- /dev/null +++ b/cpp/ql/test/library-tests/dataflow/asDefinition/test.cpp @@ -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="... = ..." +} \ No newline at end of file diff --git a/cpp/ql/test/library-tests/dataflow/asDefinition/test.expected b/cpp/ql/test/library-tests/dataflow/asDefinition/test.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/cpp/ql/test/library-tests/dataflow/asDefinition/test.ql b/cpp/ql/test/library-tests/dataflow/asDefinition/test.ql new file mode 100644 index 00000000000..b996f47fb49 --- /dev/null +++ b/cpp/ql/test/library-tests/dataflow/asDefinition/test.ql @@ -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