diff options
author | Alexey Samsonov <samsonov@google.com> | 2013-08-12 07:49:36 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2013-08-12 07:49:36 +0000 |
commit | d976d43f23d67e18f097d72fd90923627f334c79 (patch) | |
tree | e57f2453743e9921768ce65f7ce5fe5f56ebe26c /unittests | |
parent | 23331c30aefae840f55b52e2ed343117e5599682 (diff) | |
download | external_llvm-d976d43f23d67e18f097d72fd90923627f334c79.zip external_llvm-d976d43f23d67e18f097d72fd90923627f334c79.tar.gz external_llvm-d976d43f23d67e18f097d72fd90923627f334c79.tar.bz2 |
Introduce factory methods for SpecialCaseList
Summary:
Doing work in constructors is bad: this change suggests to
call SpecialCaseList::create(Path, Error) instead of
"new SpecialCaseList(Path)". Currently the latter may crash with
report_fatal_error, which is undesirable - sometimes we want to report
the error to user gracefully - for example, if he provides an incorrect
file as an argument of Clang's -fsanitize-blacklist flag.
Reviewers: pcc
Reviewed By: pcc
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1327
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188156 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Transforms/Utils/SpecialCaseList.cpp | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/unittests/Transforms/Utils/SpecialCaseList.cpp b/unittests/Transforms/Utils/SpecialCaseList.cpp index 9deee3c..aee412d 100644 --- a/unittests/Transforms/Utils/SpecialCaseList.cpp +++ b/unittests/Transforms/Utils/SpecialCaseList.cpp @@ -34,9 +34,17 @@ protected: M, ST, false, GlobalValue::ExternalLinkage, 0, Name); } - SpecialCaseList *makeSpecialCaseList(StringRef List) { + SpecialCaseList *makeSpecialCaseList(StringRef List, std::string &Error) { OwningPtr<MemoryBuffer> MB(MemoryBuffer::getMemBuffer(List)); - return new SpecialCaseList(MB.get()); + return SpecialCaseList::create(MB.get(), Error); + } + + SpecialCaseList *makeSpecialCaseList(StringRef List) { + std::string Error; + SpecialCaseList *SCL = makeSpecialCaseList(List, Error); + assert(SCL); + assert(Error == ""); + return SCL; } LLVMContext Ctx; @@ -155,4 +163,26 @@ TEST_F(SpecialCaseListTest, Substring) { EXPECT_TRUE(SCL->isIn(*F)); } +TEST_F(SpecialCaseListTest, InvalidSpecialCaseList) { + std::string Error; + EXPECT_EQ(0, makeSpecialCaseList("badline", Error)); + EXPECT_EQ("Malformed line 1: 'badline'", Error); + EXPECT_EQ(0, makeSpecialCaseList("src:bad[a-", Error)); + EXPECT_EQ("Malformed regex in line 1: 'bad[a-': invalid character range", + Error); + EXPECT_EQ(0, makeSpecialCaseList("src:a.c\n" + "fun:fun(a\n", + Error)); + EXPECT_EQ("Malformed regex in line 2: 'fun(a': parentheses not balanced", + Error); + EXPECT_EQ(0, SpecialCaseList::create("unexisting", Error)); + EXPECT_EQ("Can't open file 'unexisting': No such file or directory", Error); +} + +TEST_F(SpecialCaseListTest, EmptySpecialCaseList) { + OwningPtr<SpecialCaseList> SCL(makeSpecialCaseList("")); + Module M("foo", Ctx); + EXPECT_FALSE(SCL->isIn(M)); +} + } |