Skip to content

Commit

Permalink
Release tests for UnitTestOptions::MatchesFilter
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 416567004
Change-Id: Ic407e0fcdf8ffd1c012a1b12df2837bdac1dccb4
  • Loading branch information
dinord authored and copybara-github committed Dec 15, 2021
1 parent 054a986 commit 97a4675
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions googletest/test/gtest_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7799,3 +7799,35 @@ TEST(RegisterTest, WasRegistered) {

FAIL() << "Didn't find the test!";
}

// Test that the pattern globbing algorithm is linear. If not, this test should
// time out.
TEST(PatternGlobbingTest, MatchesFilterLinearRuntime) {
std::string name(100, 'a'); // Construct the string (a^100)b
name.push_back('b');

std::string pattern; // Construct the string ((a*)^100)b
for (int i = 0; i < 100; ++i) {
pattern.append("a*");
}
pattern.push_back('b');

EXPECT_TRUE(
testing::internal::UnitTestOptions::MatchesFilter(name, pattern.c_str()));
}

TEST(PatternGlobbingTest, MatchesFilterWithMultiplePatterns) {
const std::string name = "aaaa";
EXPECT_TRUE(testing::internal::UnitTestOptions::MatchesFilter(name, "a*"));
EXPECT_TRUE(testing::internal::UnitTestOptions::MatchesFilter(name, "a*:"));
EXPECT_FALSE(testing::internal::UnitTestOptions::MatchesFilter(name, "ab"));
EXPECT_FALSE(testing::internal::UnitTestOptions::MatchesFilter(name, "ab:"));
EXPECT_TRUE(testing::internal::UnitTestOptions::MatchesFilter(name, "ab:a*"));
}

TEST(PatternGlobbingTest, MatchesFilterEdgeCases) {
EXPECT_FALSE(testing::internal::UnitTestOptions::MatchesFilter("", "*a"));
EXPECT_TRUE(testing::internal::UnitTestOptions::MatchesFilter("", "*"));
EXPECT_FALSE(testing::internal::UnitTestOptions::MatchesFilter("a", ""));
EXPECT_TRUE(testing::internal::UnitTestOptions::MatchesFilter("", ""));
}

0 comments on commit 97a4675

Please sign in to comment.