Index: llvm/trunk/include/llvm/Support/SpecialCaseList.h =================================================================== --- llvm/trunk/include/llvm/Support/SpecialCaseList.h +++ llvm/trunk/include/llvm/Support/SpecialCaseList.h @@ -8,15 +8,19 @@ // // This is a utility class used to parse user-provided text files with // "special case lists" for code sanitizers. Such files are used to -// define "ABI list" for DataFlowSanitizer and blacklists for another sanitizers +// define an "ABI list" for DataFlowSanitizer and blacklists for sanitizers // like AddressSanitizer or UndefinedBehaviorSanitizer. // -// Empty lines and lines starting with "#" are ignored. All the rest lines -// should have the form: -// section:wildcard_expression[=category] +// Empty lines and lines starting with "#" are ignored. Sections are defined +// using a '[section_name]' header and can be used to specify sanitizers the +// entries below it apply to. Section names are regular expressions, and +// entries without a section header match all sections (e.g. an '[*]' header +// is assumed.) +// The remaining lines should have the form: +// prefix:wildcard_expression[=category] // If category is not specified, it is assumed to be empty string. -// Definitions of "section" and "category" are sanitizer-specific. For example, -// sanitizer blacklists support sections "src", "fun" and "global". +// Definitions of "prefix" and "category" are sanitizer-specific. For example, +// sanitizer blacklists support prefixes "src", "fun" and "global". // Wildcard expressions define, respectively, source files, functions or // globals which shouldn't be instrumented. // Examples of categories: @@ -26,6 +30,7 @@ // detection for certain globals or source files. // Full special case list file example: // --- +// [address] // # Blacklisted items: // fun:*_ZN4base6subtle* // global:*global_with_bad_access_or_initialization* @@ -34,14 +39,13 @@ // src:file_with_tricky_code.cc // src:ignore-global-initializers-issues.cc=init // +// [dataflow] // # Functions with pure functional semantics: // fun:cos=functional // fun:sin=functional // --- // Note that the wild card is in fact an llvm::Regex, but * is automatically // replaced with .* -// This is similar to the "ignore" feature of ThreadSanitizer. -// http://code.google.com/p/data-race-test/wiki/ThreadSanitizerIgnores // //===----------------------------------------------------------------------===// @@ -49,6 +53,9 @@ #define LLVM_SUPPORT_SPECIALCASELIST_H #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringSet.h" +#include "llvm/Support/Regex.h" +#include "llvm/Support/TrigramIndex.h" #include #include @@ -76,26 +83,63 @@ /// Returns true, if special case list contains a line /// \code - /// @Section:=@Category + /// @Prefix:=@Category /// \endcode - /// and @Query satisfies a wildcard expression . - bool inSection(StringRef Section, StringRef Query, + /// where @Query satisfies wildcard expression in a given @Section. + bool inSection(StringRef Section, StringRef Prefix, StringRef Query, StringRef Category = StringRef()) const; -private: +protected: + // Implementations of the create*() functions that can also be used by derived + // classes. + bool createInternal(const std::vector &Paths, + std::string &Error); + bool createInternal(const MemoryBuffer *MB, std::string &Error); + SpecialCaseList(SpecialCaseList const &) = delete; SpecialCaseList &operator=(SpecialCaseList const &) = delete; - struct Entry; - StringMap> Entries; - StringMap> Regexps; + /// Represents a set of regular expressions. Regular expressions which are + /// "literal" (i.e. no regex metacharacters) are stored in Strings, while all + /// others are represented as a single pipe-separated regex in RegEx. The + /// reason for doing so is efficiency; StringSet is much faster at matching + /// literal strings than Regex. + class Matcher { + public: + bool insert(std::string Regexp, std::string &REError); + void compile(); + bool match(StringRef Query) const; + + private: + StringSet<> Strings; + TrigramIndex Trigrams; + std::unique_ptr RegEx; + std::string UncompiledRegEx; + }; + + using SectionEntries = StringMap>; + + struct Section { + Section(std::unique_ptr M) : SectionMatcher(std::move(M)){}; + + std::unique_ptr SectionMatcher; + SectionEntries Entries; + }; + + std::vector
Sections; bool IsCompiled; SpecialCaseList(); /// Parses just-constructed SpecialCaseList entries from a memory buffer. - bool parse(const MemoryBuffer *MB, std::string &Error); + bool parse(const MemoryBuffer *MB, StringMap &SectionsMap, + std::string &Error); /// compile() should be called once, after parsing all the memory buffers. void compile(); + + // Helper method for derived classes to search by Prefix, Query, and Category + // once they have already resolved a section entry. + bool inSection(const SectionEntries &Entries, StringRef Prefix, + StringRef Query, StringRef Category) const; }; } // namespace llvm Index: llvm/trunk/lib/Support/SpecialCaseList.cpp =================================================================== --- llvm/trunk/lib/Support/SpecialCaseList.cpp +++ llvm/trunk/lib/Support/SpecialCaseList.cpp @@ -17,65 +17,72 @@ #include "llvm/Support/SpecialCaseList.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/ADT/StringSet.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Regex.h" -#include "llvm/Support/TrigramIndex.h" #include #include #include +#include namespace llvm { -/// Represents a set of regular expressions. Regular expressions which are -/// "literal" (i.e. no regex metacharacters) are stored in Strings, while all -/// others are represented as a single pipe-separated regex in RegEx. The -/// reason for doing so is efficiency; StringSet is much faster at matching -/// literal strings than Regex. -struct SpecialCaseList::Entry { - StringSet<> Strings; - TrigramIndex Trigrams; - std::unique_ptr RegEx; +bool SpecialCaseList::Matcher::insert(std::string Regexp, + std::string &REError) { + if (Regex::isLiteralERE(Regexp)) { + Strings.insert(Regexp); + return true; + } + Trigrams.insert(Regexp); - bool match(StringRef Query) const { - if (Strings.count(Query)) - return true; - if (Trigrams.isDefinitelyOut(Query)) - return false; - return RegEx && RegEx->match(Query); + // Replace * with .* + for (size_t pos = 0; (pos = Regexp.find('*', pos)) != std::string::npos; + pos += strlen(".*")) { + Regexp.replace(pos, strlen("*"), ".*"); } -}; -SpecialCaseList::SpecialCaseList() : Entries(), Regexps(), IsCompiled(false) {} + // Check that the regexp is valid. + Regex CheckRE(Regexp); + if (!CheckRE.isValid(REError)) + return false; + + if (!UncompiledRegEx.empty()) + UncompiledRegEx += "|"; + UncompiledRegEx += "^(" + Regexp + ")$"; + return true; +} + +void SpecialCaseList::Matcher::compile() { + if (!UncompiledRegEx.empty()) { + RegEx.reset(new Regex(UncompiledRegEx)); + UncompiledRegEx.clear(); + } +} + +bool SpecialCaseList::Matcher::match(StringRef Query) const { + if (Strings.count(Query)) + return true; + if (Trigrams.isDefinitelyOut(Query)) + return false; + return RegEx && RegEx->match(Query); +} + +SpecialCaseList::SpecialCaseList() : Sections(), IsCompiled(false) {} std::unique_ptr SpecialCaseList::create(const std::vector &Paths, std::string &Error) { std::unique_ptr SCL(new SpecialCaseList()); - for (const auto &Path : Paths) { - ErrorOr> FileOrErr = - MemoryBuffer::getFile(Path); - if (std::error_code EC = FileOrErr.getError()) { - Error = (Twine("can't open file '") + Path + "': " + EC.message()).str(); - return nullptr; - } - std::string ParseError; - if (!SCL->parse(FileOrErr.get().get(), ParseError)) { - Error = (Twine("error parsing file '") + Path + "': " + ParseError).str(); - return nullptr; - } - } - SCL->compile(); - return SCL; + if (SCL->createInternal(Paths, Error)) + return SCL; + return nullptr; } std::unique_ptr SpecialCaseList::create(const MemoryBuffer *MB, std::string &Error) { std::unique_ptr SCL(new SpecialCaseList()); - if (!SCL->parse(MB, Error)) - return nullptr; - SCL->compile(); - return SCL; + if (SCL->createInternal(MB, Error)) + return SCL; + return nullptr; } std::unique_ptr @@ -86,15 +93,71 @@ report_fatal_error(Error); } -bool SpecialCaseList::parse(const MemoryBuffer *MB, std::string &Error) { +bool SpecialCaseList::createInternal(const std::vector &Paths, + std::string &Error) { + StringMap Sections; + for (const auto &Path : Paths) { + ErrorOr> FileOrErr = + MemoryBuffer::getFile(Path); + if (std::error_code EC = FileOrErr.getError()) { + Error = (Twine("can't open file '") + Path + "': " + EC.message()).str(); + return false; + } + std::string ParseError; + if (!parse(FileOrErr.get().get(), Sections, ParseError)) { + Error = (Twine("error parsing file '") + Path + "': " + ParseError).str(); + return false; + } + } + compile(); + return true; +} + +bool SpecialCaseList::createInternal(const MemoryBuffer *MB, + std::string &Error) { + StringMap Sections; + if (!parse(MB, Sections, Error)) + return false; + compile(); + return true; +} + +bool SpecialCaseList::parse(const MemoryBuffer *MB, + StringMap &SectionsMap, + std::string &Error) { // Iterate through each line in the blacklist file. SmallVector Lines; SplitString(MB->getBuffer(), Lines, "\n\r"); + int LineNo = 1; + StringRef Section = "*"; for (auto I = Lines.begin(), E = Lines.end(); I != E; ++I, ++LineNo) { // Ignore empty lines and lines starting with "#" if (I->empty() || I->startswith("#")) continue; + + // Save section names + if (I->startswith("[")) { + if (!I->endswith("]")) { + Error = (Twine("malformed section header on line ") + Twine(LineNo) + + ": " + *I).str(); + return false; + } + + Section = I->slice(1, I->size() - 1); + + std::string REError; + Regex CheckRE(Section); + if (!CheckRE.isValid(REError)) { + Error = + (Twine("malformed regex for section ") + Section + ": '" + REError) + .str(); + return false; + } + + continue; + } + // Get our prefix and unparsed regexp. std::pair SplitLine = I->split(":"); StringRef Prefix = SplitLine.first; @@ -109,61 +172,62 @@ std::string Regexp = SplitRegexp.first; StringRef Category = SplitRegexp.second; - // See if we can store Regexp in Strings. - auto &Entry = Entries[Prefix][Category]; - if (Regex::isLiteralERE(Regexp)) { - Entry.Strings.insert(Regexp); - continue; - } - Entry.Trigrams.insert(Regexp); + // Create this section if it has not been seen before. + if (SectionsMap.find(Section) == SectionsMap.end()) { + std::unique_ptr M = make_unique(); + std::string REError; + if (!M->insert(Section, REError)) { + Error = (Twine("malformed section ") + Section + ": '" + REError).str(); + return false; + } + M->compile(); - // Replace * with .* - for (size_t pos = 0; (pos = Regexp.find('*', pos)) != std::string::npos; - pos += strlen(".*")) { - Regexp.replace(pos, strlen("*"), ".*"); + SectionsMap[Section] = Sections.size(); + Sections.emplace_back(std::move(M)); } - // Check that the regexp is valid. - Regex CheckRE(Regexp); + auto &Entry = Sections[SectionsMap[Section]].Entries[Prefix][Category]; std::string REError; - if (!CheckRE.isValid(REError)) { + if (!Entry.insert(std::move(Regexp), REError)) { Error = (Twine("malformed regex in line ") + Twine(LineNo) + ": '" + SplitLine.second + "': " + REError).str(); return false; } - - // Add this regexp into the proper group by its prefix. - if (!Regexps[Prefix][Category].empty()) - Regexps[Prefix][Category] += "|"; - Regexps[Prefix][Category] += "^" + Regexp + "$"; } return true; } void SpecialCaseList::compile() { assert(!IsCompiled && "compile() should only be called once"); - // Iterate through each of the prefixes, and create Regexs for them. - for (StringMap>::const_iterator I = Regexps.begin(), - E = Regexps.end(); - I != E; ++I) { - for (StringMap::const_iterator II = I->second.begin(), - IE = I->second.end(); - II != IE; ++II) { - Entries[I->getKey()][II->getKey()].RegEx.reset(new Regex(II->getValue())); - } - } - Regexps.clear(); + // Iterate through every section compiling regular expressions for every query + // and creating Section entries. + for (auto &Section : Sections) + for (auto &Prefix : Section.Entries) + for (auto &Category : Prefix.getValue()) + Category.getValue().compile(); + IsCompiled = true; } SpecialCaseList::~SpecialCaseList() {} -bool SpecialCaseList::inSection(StringRef Section, StringRef Query, - StringRef Category) const { +bool SpecialCaseList::inSection(StringRef Section, StringRef Prefix, + StringRef Query, StringRef Category) const { assert(IsCompiled && "SpecialCaseList::compile() was not called!"); - StringMap >::const_iterator I = Entries.find(Section); + + for (auto &SectionIter : Sections) + if (SectionIter.SectionMatcher->match(Section) && + inSection(SectionIter.Entries, Prefix, Query, Category)) + return true; + + return false; +} + +bool SpecialCaseList::inSection(const SectionEntries &Entries, StringRef Prefix, + StringRef Query, StringRef Category) const { + SectionEntries::const_iterator I = Entries.find(Prefix); if (I == Entries.end()) return false; - StringMap::const_iterator II = I->second.find(Category); + StringMap::const_iterator II = I->second.find(Category); if (II == I->second.end()) return false; return II->getValue().match(Query); Index: llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp =================================================================== --- llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -155,7 +155,7 @@ /// given category. bool isIn(const Function &F, StringRef Category) const { return isIn(*F.getParent(), Category) || - SCL->inSection("fun", F.getName(), Category); + SCL->inSection("dataflow", "fun", F.getName(), Category); } /// Returns whether this global alias is listed in the given category. @@ -167,15 +167,16 @@ return true; if (isa(GA.getValueType())) - return SCL->inSection("fun", GA.getName(), Category); + return SCL->inSection("dataflow", "fun", GA.getName(), Category); - return SCL->inSection("global", GA.getName(), Category) || - SCL->inSection("type", GetGlobalTypeString(GA), Category); + return SCL->inSection("dataflow", "global", GA.getName(), Category) || + SCL->inSection("dataflow", "type", GetGlobalTypeString(GA), + Category); } /// Returns whether this module is listed in the given category. bool isIn(const Module &M, StringRef Category) const { - return SCL->inSection("src", M.getModuleIdentifier(), Category); + return SCL->inSection("dataflow", "src", M.getModuleIdentifier(), Category); } }; Index: llvm/trunk/tools/llvm-cov/CoverageFilters.cpp =================================================================== --- llvm/trunk/tools/llvm-cov/CoverageFilters.cpp +++ llvm/trunk/tools/llvm-cov/CoverageFilters.cpp @@ -32,7 +32,7 @@ bool NameWhitelistCoverageFilter::matches( const coverage::CoverageMapping &, const coverage::FunctionRecord &Function) { - return Whitelist.inSection("whitelist_fun", Function.Name); + return Whitelist.inSection("llvmcov", "whitelist_fun", Function.Name); } bool RegionCoverageFilter::matches(const coverage::CoverageMapping &CM, Index: llvm/trunk/tools/sancov/sancov.cc =================================================================== --- llvm/trunk/tools/sancov/sancov.cc +++ llvm/trunk/tools/sancov/sancov.cc @@ -584,13 +584,16 @@ UserBlacklist(createUserBlacklist()) {} bool isBlacklisted(const DILineInfo &I) { - if (DefaultBlacklist && DefaultBlacklist->inSection("fun", I.FunctionName)) + if (DefaultBlacklist && + DefaultBlacklist->inSection("sancov", "fun", I.FunctionName)) return true; - if (DefaultBlacklist && DefaultBlacklist->inSection("src", I.FileName)) + if (DefaultBlacklist && + DefaultBlacklist->inSection("sancov", "src", I.FileName)) return true; - if (UserBlacklist && UserBlacklist->inSection("fun", I.FunctionName)) + if (UserBlacklist && + UserBlacklist->inSection("sancov", "fun", I.FunctionName)) return true; - if (UserBlacklist && UserBlacklist->inSection("src", I.FileName)) + if (UserBlacklist && UserBlacklist->inSection("sancov", "src", I.FileName)) return true; return false; } Index: llvm/trunk/unittests/Support/SpecialCaseListTest.cpp =================================================================== --- llvm/trunk/unittests/Support/SpecialCaseListTest.cpp +++ llvm/trunk/unittests/Support/SpecialCaseListTest.cpp @@ -51,47 +51,75 @@ "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 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 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 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, EmptySpecialCaseList) { std::unique_ptr SCL = makeSpecialCaseList(""); - EXPECT_FALSE(SCL->inSection("foo", "bar")); + EXPECT_FALSE(SCL->inSection("", "foo", "bar")); } TEST_F(SpecialCaseListTest, MultipleBlacklists) { @@ -124,12 +152,12 @@ 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, NoTrigramsInRules) { std::unique_ptr 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 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 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 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 @@ "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 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")); } }