From 7ca955a0e6ca6e4903b76f8eb2fcd7cf15de6dca Mon Sep 17 00:00:00 2001 From: Tony Torralba Date: Wed, 27 Jul 2022 17:23:10 +0200 Subject: [PATCH 1/3] Add support for XML InlineExpectationsTest --- .../InlineExpectationsTestPrivate.qll | 12 ++++++++++++ java/ql/test/library-tests/xml/Test.java | 3 +++ java/ql/test/library-tests/xml/XMLTest.expected | 0 java/ql/test/library-tests/xml/XMLTest.ql | 17 +++++++++++++++++ java/ql/test/library-tests/xml/test.xml | 4 ++++ 5 files changed, 36 insertions(+) create mode 100644 java/ql/test/library-tests/xml/Test.java create mode 100644 java/ql/test/library-tests/xml/XMLTest.expected create mode 100644 java/ql/test/library-tests/xml/XMLTest.ql create mode 100644 java/ql/test/library-tests/xml/test.xml diff --git a/java/ql/test/TestUtilities/InlineExpectationsTestPrivate.qll b/java/ql/test/TestUtilities/InlineExpectationsTestPrivate.qll index 5233f92f406b..7e4a1b65f4cc 100644 --- a/java/ql/test/TestUtilities/InlineExpectationsTestPrivate.qll +++ b/java/ql/test/TestUtilities/InlineExpectationsTestPrivate.qll @@ -20,3 +20,15 @@ private class KtExpectationComment extends KtComment, ExpectationComment { override string getContents() { result = this.getText().suffix(2).trim() } } + +private class XMLExpectationComment extends ExpectationComment instanceof XMLComment { + override string getContents() { result = this.(XMLComment).getText().trim() } + + override Location getLocation() { result = this.(XMLComment).getLocation() } + + override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) { + this.(XMLComment).hasLocationInfo(path, sl, sc, el, ec) + } + + override string toString() { result = this.(XMLComment).toString() } +} diff --git a/java/ql/test/library-tests/xml/Test.java b/java/ql/test/library-tests/xml/Test.java new file mode 100644 index 000000000000..4566fbca2adc --- /dev/null +++ b/java/ql/test/library-tests/xml/Test.java @@ -0,0 +1,3 @@ +public class Test { + +} diff --git a/java/ql/test/library-tests/xml/XMLTest.expected b/java/ql/test/library-tests/xml/XMLTest.expected new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/ql/test/library-tests/xml/XMLTest.ql b/java/ql/test/library-tests/xml/XMLTest.ql new file mode 100644 index 000000000000..e4b8b3a03618 --- /dev/null +++ b/java/ql/test/library-tests/xml/XMLTest.ql @@ -0,0 +1,17 @@ +import semmle.code.xml.XML +import TestUtilities.InlineExpectationsTest + +class XMLTest extends InlineExpectationsTest { + XMLTest() { this = "XMLTest" } + + override string getARelevantTag() { result = "hasXmlResult" } + + override predicate hasActualResult(Location location, string element, string tag, string value) { + tag = "hasXmlResult" and + exists(XMLAttribute a | + a.getLocation() = location and + element = a.toString() and + value = "" + ) + } +} diff --git a/java/ql/test/library-tests/xml/test.xml b/java/ql/test/library-tests/xml/test.xml new file mode 100644 index 000000000000..cd41bd7f36ce --- /dev/null +++ b/java/ql/test/library-tests/xml/test.xml @@ -0,0 +1,4 @@ + + + Text + \ No newline at end of file From 6091f0dbce4da7e8f653e3d2eb4479819cbed00c Mon Sep 17 00:00:00 2001 From: Tony Torralba Date: Fri, 29 Jul 2022 13:44:11 +0200 Subject: [PATCH 2/3] Use camelCase for XML acronym --- java/ql/test/TestUtilities/InlineExpectationsTestPrivate.qll | 2 +- java/ql/test/library-tests/xml/XMLTest.expected | 2 ++ java/ql/test/library-tests/xml/XMLTest.ql | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/java/ql/test/TestUtilities/InlineExpectationsTestPrivate.qll b/java/ql/test/TestUtilities/InlineExpectationsTestPrivate.qll index 7e4a1b65f4cc..e61d3dabe703 100644 --- a/java/ql/test/TestUtilities/InlineExpectationsTestPrivate.qll +++ b/java/ql/test/TestUtilities/InlineExpectationsTestPrivate.qll @@ -21,7 +21,7 @@ private class KtExpectationComment extends KtComment, ExpectationComment { override string getContents() { result = this.getText().suffix(2).trim() } } -private class XMLExpectationComment extends ExpectationComment instanceof XMLComment { +private class XmlExpectationComment extends ExpectationComment instanceof XMLComment { override string getContents() { result = this.(XMLComment).getText().trim() } override Location getLocation() { result = this.(XMLComment).getLocation() } diff --git a/java/ql/test/library-tests/xml/XMLTest.expected b/java/ql/test/library-tests/xml/XMLTest.expected index e69de29bb2d1..61d3c801963f 100644 --- a/java/ql/test/library-tests/xml/XMLTest.expected +++ b/java/ql/test/library-tests/xml/XMLTest.expected @@ -0,0 +1,2 @@ +| test.xml:4:5:4:32 | attribute=value | Unexpected result: hasXmlResult= | +| test.xml:5:29:5:52 | $ hasXmlResult | Missing result:hasXmlResult= | \ No newline at end of file diff --git a/java/ql/test/library-tests/xml/XMLTest.ql b/java/ql/test/library-tests/xml/XMLTest.ql index e4b8b3a03618..fb51e0a15069 100644 --- a/java/ql/test/library-tests/xml/XMLTest.ql +++ b/java/ql/test/library-tests/xml/XMLTest.ql @@ -1,8 +1,8 @@ import semmle.code.xml.XML import TestUtilities.InlineExpectationsTest -class XMLTest extends InlineExpectationsTest { - XMLTest() { this = "XMLTest" } +class XmlTest extends InlineExpectationsTest { + XmlTest() { this = "XmlTest" } override string getARelevantTag() { result = "hasXmlResult" } From ec03ebbbfca2e7b5bce8cf0875cbe8c0b0628d95 Mon Sep 17 00:00:00 2001 From: Tony Torralba Date: Fri, 29 Jul 2022 13:44:25 +0200 Subject: [PATCH 3/3] Add spurious and missing test cases --- java/ql/test/library-tests/xml/test.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java/ql/test/library-tests/xml/test.xml b/java/ql/test/library-tests/xml/test.xml index cd41bd7f36ce..f0d9262f09f5 100644 --- a/java/ql/test/library-tests/xml/test.xml +++ b/java/ql/test/library-tests/xml/test.xml @@ -1,4 +1,6 @@ Text + Text + Text \ No newline at end of file