summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-02-03 12:15:07 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2020-02-03 12:55:54 +0100
commit404771d0ec11f26a0b631018719e2918a049455b (patch)
treed7f2bed62c67b05e01095865056634db0f9b6be7 /test
parent11a40ab11f72f85e905bdba4d3274870fbcaeaee (diff)
patterns: test for empty terms, reject them
Diffstat (limited to 'test')
-rw-r--r--test/libapt/pattern_test.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/libapt/pattern_test.cc b/test/libapt/pattern_test.cc
index 84d09351c..bfcaf2093 100644
--- a/test/libapt/pattern_test.cc
+++ b/test/libapt/pattern_test.cc
@@ -14,6 +14,32 @@
using namespace APT::Internal;
+#define EXPECT_EXCEPTION(exp, exc, msg) \
+ caught = false; \
+ try \
+ { \
+ exp; \
+ } \
+ catch (exc & e) \
+ { \
+ caught = true; \
+ EXPECT_TRUE(e.message.find(msg) != std::string::npos) << msg << " not in " << e.message; \
+ }; \
+ EXPECT_TRUE(caught) << #exp "should have thrown an exception"
+
+TEST(TreeParserTest, ParseInvalid)
+{
+ bool caught = false;
+
+ // Not a valid pattern: Reject
+ EXPECT_EXCEPTION(PatternTreeParser("?").parse(), PatternTreeParser::Error, "Pattern must have a term");
+ EXPECT_EXCEPTION(PatternTreeParser("?AB?").parse(), PatternTreeParser::Error, "Pattern must have a term");
+ EXPECT_EXCEPTION(PatternTreeParser("~").parse(), PatternTreeParser::Error, "Unknown short pattern");
+
+ // Not a pattern at all: Report nullptr
+ EXPECT_EQ(PatternTreeParser("A?").parse(), nullptr);
+}
+
TEST(TreeParserTest, ParseWord)
{
auto node = PatternTreeParser("?word(word)").parseTop();