diff options
author | Hossein Ghahramanzadeh <hgsilverman@gmail.com> | 2021-10-17 16:53:08 (GMT) |
---|---|---|
committer | Hossein Ghahramanzadeh <hgsilverman@gmail.com> | 2022-01-06 14:46:52 (GMT) |
commit | f20688737ad71746a013596e3798fa44b1abb6a2 (patch) | |
tree | d8d259f0adc24a93d23f1625a155a2c5e7610208 /googletest/src | |
parent | f5b4efef5f6a190c50437a81c2c4bfb1996eeb50 (diff) | |
download | googletest-f20688737ad71746a013596e3798fa44b1abb6a2.zip googletest-f20688737ad71746a013596e3798fa44b1abb6a2.tar.gz googletest-f20688737ad71746a013596e3798fa44b1abb6a2.tar.bz2 |
Get rid of redundant filter matching code
Diffstat (limited to 'googletest/src')
-rw-r--r-- | googletest/src/gtest-internal-inl.h | 4 | ||||
-rw-r--r-- | googletest/src/gtest.cc | 49 |
2 files changed, 1 insertions, 52 deletions
diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index 0b25d2f..765d12d 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -390,10 +390,6 @@ class GTEST_API_ UnitTestOptions { // This function is useful as an __except condition. static int GTestShouldProcessSEH(DWORD exception_code); #endif // GTEST_OS_WINDOWS - - // Returns true if "name" matches the ':' separated list of glob-style - // filters in "filter". - static bool MatchesFilter(const std::string& name, const char* filter); }; // Returns the current application's name, removing directory path if that diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index c2e40f8..e6140b7 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -723,31 +723,6 @@ static bool PatternMatchesString(const std::string& name_str, return true; } -bool UnitTestOptions::MatchesFilter(const std::string& name_str, - const char* filter) { - // The filter is a list of patterns separated by colons (:). - const char* pattern = filter; - while (true) { - // Find the bounds of this pattern. - const char* const next_sep = strchr(pattern, ':'); - const char* const pattern_end = - next_sep != nullptr ? next_sep : pattern + strlen(pattern); - - // Check if this pattern matches name_str. - if (PatternMatchesString(name_str, pattern, pattern_end)) { - return true; - } - - // Give up on this pattern. However, if we found a pattern separator (:), - // advance to the next pattern (skipping over the separator) and restart. - if (next_sep == nullptr) { - return false; - } - pattern = next_sep + 1; - } - return true; -} - class Filter { std::vector<std::string> patterns_; @@ -830,31 +805,9 @@ class PositiveAndNegativeFilter { // suite name and the test name. bool UnitTestOptions::FilterMatchesTest(const std::string& test_suite_name, const std::string& test_name) { - const std::string& full_name = test_suite_name + "." + test_name.c_str(); - // Split --gtest_filter at '-', if there is one, to separate into // positive filter and negative filter portions - std::string str = GTEST_FLAG_GET(filter); - const char* const p = str.c_str(); - const char* const dash = strchr(p, '-'); - std::string positive; - std::string negative; - if (dash == nullptr) { - positive = str.c_str(); // Whole string is a positive filter - negative = ""; - } else { - positive = std::string(p, dash); // Everything up to the dash - negative = std::string(dash + 1); // Everything after the dash - if (positive.empty()) { - // Treat '-test1' as the same as '*-test1' - positive = kUniversalFilter; - } - } - - // A filter is a colon-separated list of patterns. It matches a - // test if any pattern in it matches the test. - return (MatchesFilter(full_name, positive.c_str()) && - !MatchesFilter(full_name, negative.c_str())); + return PositiveAndNegativeFilter{GTEST_FLAG_GET(filter)}.MatchesTest(test_suite_name, test_name); } #if GTEST_HAS_SEH |