diff options
Diffstat (limited to 'src/mongo/unittest/unittest.h')
-rw-r--r-- | src/mongo/unittest/unittest.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/mongo/unittest/unittest.h b/src/mongo/unittest/unittest.h index f3582d319a0..9e2c2fd0518 100644 --- a/src/mongo/unittest/unittest.h +++ b/src/mongo/unittest/unittest.h @@ -39,6 +39,7 @@ #include <cmath> #include <fmt/format.h> #include <functional> +#include <pcrecpp.h> #include <sstream> #include <string> #include <tuple> @@ -277,6 +278,20 @@ haystack); \ }())) +#define ASSERT_STRING_SEARCH_REGEX(BIG_STRING, REGEX) \ + if (auto tup_ = std::tuple(std::string(BIG_STRING), std::string(REGEX)); \ + pcrecpp::RE(std::get<1>(tup_)).PartialMatch(std::get<0>(tup_))) { \ + } else \ + FAIL(([&] { \ + const auto& [haystack, sub] = tup_; \ + return format(FMT_STRING("Expected to find regular expression {} /{}/ in {} ({})"), \ + #REGEX, \ + sub, \ + #BIG_STRING, \ + haystack); \ + }())) + + /** * Construct a single test, named `TEST_NAME` within the test Suite `SUITE_NAME`. * |