summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/SpecialCaseListTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/Support/SpecialCaseListTest.cpp')
-rw-r--r--llvm/unittests/Support/SpecialCaseListTest.cpp138
1 files changed, 83 insertions, 55 deletions
diff --git a/llvm/unittests/Support/SpecialCaseListTest.cpp b/llvm/unittests/Support/SpecialCaseListTest.cpp
index 130848845e4..0aa8452c0dd 100644
--- a/llvm/unittests/Support/SpecialCaseListTest.cpp
+++ b/llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -51,47 +51,75 @@ TEST_F(SpecialCaseListTest, Basic) {
"src:bye\n"
"src:hi=category\n"
"src:z*=category\n");
- EXPECT_TRUE(SCL->inSection("src", "hello"));
- EXPECT_TRUE(SCL->inSection("src", "bye"));
- EXPECT_TRUE(SCL->inSection("src", "hi", "category"));
- EXPECT_TRUE(SCL->inSection("src", "zzzz", "category"));
- EXPECT_FALSE(SCL->inSection("src", "hi"));
- EXPECT_FALSE(SCL->inSection("fun", "hello"));
- EXPECT_FALSE(SCL->inSection("src", "hello", "category"));
+ EXPECT_TRUE(SCL->inSection("", "src", "hello"));
+ EXPECT_TRUE(SCL->inSection("", "src", "bye"));
+ EXPECT_TRUE(SCL->inSection("", "src", "hi", "category"));
+ EXPECT_TRUE(SCL->inSection("", "src", "zzzz", "category"));
+ EXPECT_FALSE(SCL->inSection("", "src", "hi"));
+ EXPECT_FALSE(SCL->inSection("", "fun", "hello"));
+ EXPECT_FALSE(SCL->inSection("", "src", "hello", "category"));
+}
+
+TEST_F(SpecialCaseListTest, SectionRegexErrorHandling) {
+ std::string Error;
+ EXPECT_EQ(makeSpecialCaseList("[address", Error), nullptr);
+ EXPECT_TRUE(((StringRef)Error).startswith("malformed section header "));
+
+ EXPECT_EQ(makeSpecialCaseList("[[]", Error), nullptr);
+ EXPECT_TRUE(((StringRef)Error).startswith("malformed regex for section [: "));
+}
+
+TEST_F(SpecialCaseListTest, Section) {
+ std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("src:global\n"
+ "[sect1|sect2]\n"
+ "src:test1\n"
+ "[sect3*]\n"
+ "src:test2\n");
+ EXPECT_TRUE(SCL->inSection("arbitrary", "src", "global"));
+ EXPECT_TRUE(SCL->inSection("", "src", "global"));
+ EXPECT_TRUE(SCL->inSection("sect1", "src", "test1"));
+ EXPECT_FALSE(SCL->inSection("sect1-arbitrary", "src", "test1"));
+ EXPECT_FALSE(SCL->inSection("sect", "src", "test1"));
+ EXPECT_FALSE(SCL->inSection("sect1", "src", "test2"));
+ EXPECT_TRUE(SCL->inSection("sect2", "src", "test1"));
+ EXPECT_TRUE(SCL->inSection("sect3", "src", "test2"));
+ EXPECT_TRUE(SCL->inSection("sect3-arbitrary", "src", "test2"));
+ EXPECT_FALSE(SCL->inSection("", "src", "test1"));
+ EXPECT_FALSE(SCL->inSection("", "src", "test2"));
}
TEST_F(SpecialCaseListTest, GlobalInit) {
std::unique_ptr<SpecialCaseList> SCL =
makeSpecialCaseList("global:foo=init\n");
- EXPECT_FALSE(SCL->inSection("global", "foo"));
- EXPECT_FALSE(SCL->inSection("global", "bar"));
- EXPECT_TRUE(SCL->inSection("global", "foo", "init"));
- EXPECT_FALSE(SCL->inSection("global", "bar", "init"));
+ EXPECT_FALSE(SCL->inSection("", "global", "foo"));
+ EXPECT_FALSE(SCL->inSection("", "global", "bar"));
+ EXPECT_TRUE(SCL->inSection("", "global", "foo", "init"));
+ EXPECT_FALSE(SCL->inSection("", "global", "bar", "init"));
SCL = makeSpecialCaseList("type:t2=init\n");
- EXPECT_FALSE(SCL->inSection("type", "t1"));
- EXPECT_FALSE(SCL->inSection("type", "t2"));
- EXPECT_FALSE(SCL->inSection("type", "t1", "init"));
- EXPECT_TRUE(SCL->inSection("type", "t2", "init"));
+ EXPECT_FALSE(SCL->inSection("", "type", "t1"));
+ EXPECT_FALSE(SCL->inSection("", "type", "t2"));
+ EXPECT_FALSE(SCL->inSection("", "type", "t1", "init"));
+ EXPECT_TRUE(SCL->inSection("", "type", "t2", "init"));
SCL = makeSpecialCaseList("src:hello=init\n");
- EXPECT_FALSE(SCL->inSection("src", "hello"));
- EXPECT_FALSE(SCL->inSection("src", "bye"));
- EXPECT_TRUE(SCL->inSection("src", "hello", "init"));
- EXPECT_FALSE(SCL->inSection("src", "bye", "init"));
+ EXPECT_FALSE(SCL->inSection("", "src", "hello"));
+ EXPECT_FALSE(SCL->inSection("", "src", "bye"));
+ EXPECT_TRUE(SCL->inSection("", "src", "hello", "init"));
+ EXPECT_FALSE(SCL->inSection("", "src", "bye", "init"));
}
TEST_F(SpecialCaseListTest, Substring) {
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("src:hello\n"
"fun:foo\n"
"global:bar\n");
- EXPECT_FALSE(SCL->inSection("src", "othello"));
- EXPECT_FALSE(SCL->inSection("fun", "tomfoolery"));
- EXPECT_FALSE(SCL->inSection("global", "bartender"));
+ EXPECT_FALSE(SCL->inSection("", "src", "othello"));
+ EXPECT_FALSE(SCL->inSection("", "fun", "tomfoolery"));
+ EXPECT_FALSE(SCL->inSection("", "global", "bartender"));
SCL = makeSpecialCaseList("fun:*foo*\n");
- EXPECT_TRUE(SCL->inSection("fun", "tomfoolery"));
- EXPECT_TRUE(SCL->inSection("fun", "foobar"));
+ EXPECT_TRUE(SCL->inSection("", "fun", "tomfoolery"));
+ EXPECT_TRUE(SCL->inSection("", "fun", "foobar"));
}
TEST_F(SpecialCaseListTest, InvalidSpecialCaseList) {
@@ -113,7 +141,7 @@ TEST_F(SpecialCaseListTest, InvalidSpecialCaseList) {
TEST_F(SpecialCaseListTest, EmptySpecialCaseList) {
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("");
- EXPECT_FALSE(SCL->inSection("foo", "bar"));
+ EXPECT_FALSE(SCL->inSection("", "foo", "bar"));
}
TEST_F(SpecialCaseListTest, MultipleBlacklists) {
@@ -124,12 +152,12 @@ TEST_F(SpecialCaseListTest, MultipleBlacklists) {
Files.push_back(makeSpecialCaseListFile("src:baz\n"
"src:*fog*\n"));
auto SCL = SpecialCaseList::createOrDie(Files);
- EXPECT_TRUE(SCL->inSection("src", "bar"));
- EXPECT_TRUE(SCL->inSection("src", "baz"));
- EXPECT_FALSE(SCL->inSection("src", "ban"));
- EXPECT_TRUE(SCL->inSection("src", "ban", "init"));
- EXPECT_TRUE(SCL->inSection("src", "tomfoolery"));
- EXPECT_TRUE(SCL->inSection("src", "tomfoglery"));
+ EXPECT_TRUE(SCL->inSection("", "src", "bar"));
+ EXPECT_TRUE(SCL->inSection("", "src", "baz"));
+ EXPECT_FALSE(SCL->inSection("", "src", "ban"));
+ EXPECT_TRUE(SCL->inSection("", "src", "ban", "init"));
+ EXPECT_TRUE(SCL->inSection("", "src", "tomfoolery"));
+ EXPECT_TRUE(SCL->inSection("", "src", "tomfoglery"));
for (auto &Path : Files)
sys::fs::remove(Path);
}
@@ -137,35 +165,35 @@ TEST_F(SpecialCaseListTest, MultipleBlacklists) {
TEST_F(SpecialCaseListTest, NoTrigramsInRules) {
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("fun:b.r\n"
"fun:za*az\n");
- EXPECT_TRUE(SCL->inSection("fun", "bar"));
- EXPECT_FALSE(SCL->inSection("fun", "baz"));
- EXPECT_TRUE(SCL->inSection("fun", "zakaz"));
- EXPECT_FALSE(SCL->inSection("fun", "zaraza"));
+ EXPECT_TRUE(SCL->inSection("", "fun", "bar"));
+ EXPECT_FALSE(SCL->inSection("", "fun", "baz"));
+ EXPECT_TRUE(SCL->inSection("", "fun", "zakaz"));
+ EXPECT_FALSE(SCL->inSection("", "fun", "zaraza"));
}
TEST_F(SpecialCaseListTest, NoTrigramsInARule) {
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("fun:*bar*\n"
"fun:za*az\n");
- EXPECT_TRUE(SCL->inSection("fun", "abara"));
- EXPECT_FALSE(SCL->inSection("fun", "bor"));
- EXPECT_TRUE(SCL->inSection("fun", "zakaz"));
- EXPECT_FALSE(SCL->inSection("fun", "zaraza"));
+ EXPECT_TRUE(SCL->inSection("", "fun", "abara"));
+ EXPECT_FALSE(SCL->inSection("", "fun", "bor"));
+ EXPECT_TRUE(SCL->inSection("", "fun", "zakaz"));
+ EXPECT_FALSE(SCL->inSection("", "fun", "zaraza"));
}
TEST_F(SpecialCaseListTest, RepetitiveRule) {
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("fun:*bar*bar*bar*bar*\n"
"fun:bar*\n");
- EXPECT_TRUE(SCL->inSection("fun", "bara"));
- EXPECT_FALSE(SCL->inSection("fun", "abara"));
- EXPECT_TRUE(SCL->inSection("fun", "barbarbarbar"));
- EXPECT_TRUE(SCL->inSection("fun", "abarbarbarbar"));
- EXPECT_FALSE(SCL->inSection("fun", "abarbarbar"));
+ EXPECT_TRUE(SCL->inSection("", "fun", "bara"));
+ EXPECT_FALSE(SCL->inSection("", "fun", "abara"));
+ EXPECT_TRUE(SCL->inSection("", "fun", "barbarbarbar"));
+ EXPECT_TRUE(SCL->inSection("", "fun", "abarbarbarbar"));
+ EXPECT_FALSE(SCL->inSection("", "fun", "abarbarbar"));
}
TEST_F(SpecialCaseListTest, SpecialSymbolRule) {
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("src:*c\\+\\+abi*\n");
- EXPECT_TRUE(SCL->inSection("src", "c++abi"));
- EXPECT_FALSE(SCL->inSection("src", "c\\+\\+abi"));
+ EXPECT_TRUE(SCL->inSection("", "src", "c++abi"));
+ EXPECT_FALSE(SCL->inSection("", "src", "c\\+\\+abi"));
}
TEST_F(SpecialCaseListTest, PopularTrigram) {
@@ -173,20 +201,20 @@ TEST_F(SpecialCaseListTest, PopularTrigram) {
"fun:*aaaaa*\n"
"fun:*aaaa*\n"
"fun:*aaa*\n");
- EXPECT_TRUE(SCL->inSection("fun", "aaa"));
- EXPECT_TRUE(SCL->inSection("fun", "aaaa"));
- EXPECT_TRUE(SCL->inSection("fun", "aaaabbbaaa"));
+ EXPECT_TRUE(SCL->inSection("", "fun", "aaa"));
+ EXPECT_TRUE(SCL->inSection("", "fun", "aaaa"));
+ EXPECT_TRUE(SCL->inSection("", "fun", "aaaabbbaaa"));
}
TEST_F(SpecialCaseListTest, EscapedSymbols) {
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("src:*c\\+\\+abi*\n"
"src:*hello\\\\world*\n");
- EXPECT_TRUE(SCL->inSection("src", "dir/c++abi"));
- EXPECT_FALSE(SCL->inSection("src", "dir/c\\+\\+abi"));
- EXPECT_FALSE(SCL->inSection("src", "c\\+\\+abi"));
- EXPECT_TRUE(SCL->inSection("src", "C:\\hello\\world"));
- EXPECT_TRUE(SCL->inSection("src", "hello\\world"));
- EXPECT_FALSE(SCL->inSection("src", "hello\\\\world"));
+ EXPECT_TRUE(SCL->inSection("", "src", "dir/c++abi"));
+ EXPECT_FALSE(SCL->inSection("", "src", "dir/c\\+\\+abi"));
+ EXPECT_FALSE(SCL->inSection("", "src", "c\\+\\+abi"));
+ EXPECT_TRUE(SCL->inSection("", "src", "C:\\hello\\world"));
+ EXPECT_TRUE(SCL->inSection("", "src", "hello\\world"));
+ EXPECT_FALSE(SCL->inSection("", "src", "hello\\\\world"));
}
}
OpenPOWER on IntegriCloud