X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=unittests%2FSupport%2FSpecialCaseListTest.cpp;h=0657f8003e8be26fa0a16229eb7e52ce02062357;hb=c5f2ede9f6e04c3eba1c6d09698f9a0bc662bf9e;hp=1e13dba7753aa074b1ba04db5dd90478ace50c5b;hpb=819242a4468a8ad747a44a7153ff93542b8090d6;p=oota-llvm.git diff --git a/unittests/Support/SpecialCaseListTest.cpp b/unittests/Support/SpecialCaseListTest.cpp index 1e13dba7753..0657f8003e8 100644 --- a/unittests/Support/SpecialCaseListTest.cpp +++ b/unittests/Support/SpecialCaseListTest.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SpecialCaseList.h" #include "gtest/gtest.h" @@ -17,28 +18,39 @@ namespace { class SpecialCaseListTest : public ::testing::Test { protected: - SpecialCaseList *makeSpecialCaseList(StringRef List, std::string &Error) { + std::unique_ptr makeSpecialCaseList(StringRef List, + std::string &Error) { std::unique_ptr MB = MemoryBuffer::getMemBuffer(List); return SpecialCaseList::create(MB.get(), Error); } - SpecialCaseList *makeSpecialCaseList(StringRef List) { + std::unique_ptr makeSpecialCaseList(StringRef List) { std::string Error; - SpecialCaseList *SCL = makeSpecialCaseList(List, Error); + auto SCL = makeSpecialCaseList(List, Error); assert(SCL); assert(Error == ""); return SCL; } + + std::string makeSpecialCaseListFile(StringRef Contents) { + int FD; + SmallString<64> Path; + sys::fs::createTemporaryFile("SpecialCaseListTest", "temp", FD, Path); + raw_fd_ostream OF(FD, true, true); + OF << Contents; + OF.close(); + return Path.str(); + } }; TEST_F(SpecialCaseListTest, Basic) { - std::unique_ptr SCL( + std::unique_ptr SCL = makeSpecialCaseList("# This is a comment.\n" "\n" "src:hello\n" "src:bye\n" "src:hi=category\n" - "src:z*=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")); @@ -48,39 +60,21 @@ TEST_F(SpecialCaseListTest, Basic) { EXPECT_FALSE(SCL->inSection("src", "hello", "category")); } -TEST_F(SpecialCaseListTest, GlobalInitCompat) { - std::unique_ptr 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")); - - SCL.reset(makeSpecialCaseList("global-init:foo\n")); +TEST_F(SpecialCaseListTest, GlobalInit) { + std::unique_ptr 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")); - SCL.reset(makeSpecialCaseList("type:t2=init\n")); + 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")); - SCL.reset(makeSpecialCaseList("global-init-type:t2\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")); - - SCL.reset(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")); - - SCL.reset(makeSpecialCaseList("global-init-src:hello\n")); + 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")); @@ -88,14 +82,14 @@ TEST_F(SpecialCaseListTest, GlobalInitCompat) { } TEST_F(SpecialCaseListTest, Substring) { - std::unique_ptr SCL(makeSpecialCaseList("src:hello\n" - "fun:foo\n" - "global:bar\n")); + std::unique_ptr 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")); - SCL.reset(makeSpecialCaseList("fun:*foo*\n")); + SCL = makeSpecialCaseList("fun:*foo*\n"); EXPECT_TRUE(SCL->inSection("fun", "tomfoolery")); EXPECT_TRUE(SCL->inSection("fun", "foobar")); } @@ -103,24 +97,39 @@ TEST_F(SpecialCaseListTest, Substring) { TEST_F(SpecialCaseListTest, InvalidSpecialCaseList) { std::string Error; EXPECT_EQ(nullptr, makeSpecialCaseList("badline", Error)); - EXPECT_EQ("Malformed line 1: 'badline'", Error); + EXPECT_EQ("malformed line 1: 'badline'", Error); EXPECT_EQ(nullptr, makeSpecialCaseList("src:bad[a-", Error)); - EXPECT_EQ("Malformed regex in line 1: 'bad[a-': invalid character range", + EXPECT_EQ("malformed regex in line 1: 'bad[a-': invalid character range", Error); EXPECT_EQ(nullptr, makeSpecialCaseList("src:a.c\n" "fun:fun(a\n", Error)); - EXPECT_EQ("Malformed regex in line 2: 'fun(a': parentheses not balanced", + EXPECT_EQ("malformed regex in line 2: 'fun(a': parentheses not balanced", Error); - EXPECT_EQ(nullptr, SpecialCaseList::create("unexisting", Error)); - EXPECT_EQ(0U, Error.find("Can't open file 'unexisting':")); + std::vector Files(1, "unexisting"); + EXPECT_EQ(nullptr, SpecialCaseList::create(Files, Error)); + EXPECT_EQ(0U, Error.find("can't open file 'unexisting':")); } TEST_F(SpecialCaseListTest, EmptySpecialCaseList) { - std::unique_ptr SCL(makeSpecialCaseList("")); + std::unique_ptr SCL = makeSpecialCaseList(""); EXPECT_FALSE(SCL->inSection("foo", "bar")); } +TEST_F(SpecialCaseListTest, MultipleBlacklists) { + std::vector Files; + Files.push_back(makeSpecialCaseListFile("src:bar\n" + "src:*foo*\n" + "src:ban=init\n")); + 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")); } - +}