34 #include <system_error> 35 #include <type_traits> 52 #if FOLLY_SKIP_AS_FAILURE 53 #define SKIP() GTEST_FATAL_FAILURE_("Test skipped by client") 55 #define SKIP() return GTEST_SUCCESS_("Test skipped by client") 59 #define SKIP_IF(expr) \ 60 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 65 #define TEST_THROW_ERRNO_(statement, errnoValue, fail) \ 66 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 67 if (::folly::test::detail::CheckResult gtest_result = \ 68 ::folly::test::detail::checkThrowErrno( \ 69 [&] { statement; }, errnoValue, #statement)) { \ 71 fail(gtest_result.what()) 86 #define EXPECT_THROW_ERRNO(statement, errnoValue) \ 87 TEST_THROW_ERRNO_(statement, errnoValue, GTEST_NONFATAL_FAILURE_) 88 #define ASSERT_THROW_ERRNO(statement, errnoValue) \ 89 TEST_THROW_ERRNO_(statement, errnoValue, GTEST_FATAL_FAILURE_) 91 #define TEST_THROW_RE_(statement, exceptionType, pattern, fail) \ 92 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 93 if (::folly::test::detail::CheckResult gtest_result = \ 94 ::folly::test::detail::checkThrowRegex<exceptionType>( \ 95 [&] { statement; }, pattern, #statement, #exceptionType)) { \ 97 fail(gtest_result.what()) 119 #define EXPECT_THROW_RE(statement, exceptionType, pattern) \ 120 TEST_THROW_RE_(statement, exceptionType, pattern, GTEST_NONFATAL_FAILURE_) 121 #define ASSERT_THROW_RE(statement, exceptionType, pattern) \ 122 TEST_THROW_RE_(statement, exceptionType, pattern, GTEST_FATAL_FAILURE_) 127 template <
typename T1,
typename T2>
131 std::chrono::duration_cast<std::chrono::seconds>(val1 - val2);
132 if (deltaSecs <= acceptableDeltaSecs &&
133 deltaSecs >= -1 * acceptableDeltaSecs) {
137 << val1.count() <<
" and " << val2.count() <<
" are not within " 138 << acceptableDeltaSecs.count() <<
" secs of each other";
166 template <
typename T>
180 template <
typename Fn>
184 }
catch (
const std::system_error& ex) {
190 if (ex.code().category() != std::generic_category() &&
191 ex.code().category() != std::system_category()) {
193 <<
"Expected: " << statementStr <<
" throws an exception with errno " 194 << errnoValue <<
" (" << std::generic_category().message(errnoValue)
195 <<
")\nActual: it throws a system_error with category " 196 << ex.code().category().name() <<
": " << ex.what();
200 <<
"Expected: " << statementStr <<
" throws an exception with errno " 201 << errnoValue <<
" (" << std::generic_category().message(errnoValue)
202 <<
")\nActual: it throws errno " << ex.code().value() <<
": " 206 }
catch (
const std::exception& ex) {
208 <<
"Expected: " << statementStr <<
" throws an exception with errno " 209 << errnoValue <<
" (" << std::generic_category().message(errnoValue)
210 <<
")\nActual: it throws a different exception: " <<
exceptionStr(ex);
213 <<
"Expected: " << statementStr <<
" throws an exception with errno " 214 << errnoValue <<
" (" << std::generic_category().message(errnoValue)
215 <<
")\nActual: it throws a non-exception type";
218 <<
"Expected: " << statementStr <<
" throws an exception with errno " 219 << errnoValue <<
" (" << std::generic_category().message(errnoValue)
220 <<
")\nActual: it throws nothing";
226 template <
typename ExType,
typename Fn>
230 const char* statementStr,
231 const char* excTypeStr) {
234 "EXPECT_THROW_RE() exception type must derive from std::exception");
238 }
catch (
const std::exception& ex) {
239 const auto* derived =
dynamic_cast<const ExType*
>(&ex);
242 <<
"Expected: " << statementStr <<
"throws a " << excTypeStr
243 <<
")\nActual: it throws a different exception type: " 248 if (!std::regex_search(derived->what(), re)) {
250 <<
"Expected: " << statementStr <<
" throws a " << excTypeStr
251 <<
" with message matching \"" << pattern
252 <<
"\"\nActual: message is: " << derived->what();
257 <<
"Expected: " << statementStr <<
" throws a " << excTypeStr
258 <<
")\nActual: it throws a non-exception type";
260 return CheckResult(
false) <<
"Expected: " << statementStr <<
" throws a " 261 << excTypeStr <<
")\nActual: it throws nothing";
::testing::AssertionResult AreWithinSecs(T1 val1, T2 val2, std::chrono::seconds acceptableDeltaSecs)
CheckResult & operator<<(T &&t)
GTEST_API_ AssertionResult AssertionFailure()
::std::string PrintToString(const T &value)
fbstring exceptionStr(const std::exception &e)
CheckResult checkThrowRegex(Fn &&fn, const char *pattern, const char *statementStr, const char *excTypeStr)
void PrintTo(const dynamic &dyn, std::ostream *os)
—— Concurrent Priority Queue Implementation ——
CheckResult(bool s) noexcept
requires E e noexcept(noexcept(s.error(std::move(e))))
GTEST_API_ AssertionResult AssertionSuccess()
const char * what() const noexcept
static const char *const value
void toAppend(char value, Tgt *result)
CheckResult checkThrowErrno(Fn &&fn, int errnoValue, const char *statementStr)