proxygen
TestUtils.h File Reference
#include <chrono>
#include <regex>
#include <system_error>
#include <type_traits>
#include <folly/Conv.h>
#include <folly/ExceptionString.h>
#include <folly/Range.h>
#include <folly/portability/GTest.h>

Go to the source code of this file.

Classes

class  folly::test::detail::CheckResult
 

Namespaces

 folly
 —— Concurrent Priority Queue Implementation ——
 
 folly::test
 
 folly::test::detail
 

Macros

#define SKIP()   return GTEST_SUCCESS_("Test skipped by client")
 
#define SKIP_IF(expr)
 
#define TEST_THROW_ERRNO_(statement, errnoValue, fail)
 
#define EXPECT_THROW_ERRNO(statement, errnoValue)   TEST_THROW_ERRNO_(statement, errnoValue, GTEST_NONFATAL_FAILURE_)
 
#define ASSERT_THROW_ERRNO(statement, errnoValue)   TEST_THROW_ERRNO_(statement, errnoValue, GTEST_FATAL_FAILURE_)
 
#define TEST_THROW_RE_(statement, exceptionType, pattern, fail)
 
#define EXPECT_THROW_RE(statement, exceptionType, pattern)   TEST_THROW_RE_(statement, exceptionType, pattern, GTEST_NONFATAL_FAILURE_)
 
#define ASSERT_THROW_RE(statement, exceptionType, pattern)   TEST_THROW_RE_(statement, exceptionType, pattern, GTEST_FATAL_FAILURE_)
 

Functions

template<typename T1 , typename T2 >
::testing::AssertionResult folly::test::AreWithinSecs (T1 val1, T2 val2, std::chrono::seconds acceptableDeltaSecs)
 
template<typename Fn >
CheckResult folly::test::detail::checkThrowErrno (Fn &&fn, int errnoValue, const char *statementStr)
 
template<typename ExType , typename Fn >
CheckResult folly::test::detail::checkThrowRegex (Fn &&fn, const char *pattern, const char *statementStr, const char *excTypeStr)
 
void folly::PrintTo (StringPiece sp,::std::ostream *os)
 

Macro Definition Documentation

#define ASSERT_THROW_ERRNO (   statement,
  errnoValue 
)    TEST_THROW_ERRNO_(statement, errnoValue, GTEST_FATAL_FAILURE_)

Definition at line 88 of file TestUtils.h.

#define ASSERT_THROW_RE (   statement,
  exceptionType,
  pattern 
)    TEST_THROW_RE_(statement, exceptionType, pattern, GTEST_FATAL_FAILURE_)

Definition at line 121 of file TestUtils.h.

#define EXPECT_THROW_ERRNO (   statement,
  errnoValue 
)    TEST_THROW_ERRNO_(statement, errnoValue, GTEST_NONFATAL_FAILURE_)

Check that a statement throws a std::system_error with the expected errno value. This is useful for checking code that uses the functions in folly/Exception.h to throw exceptions.

Like other EXPECT_* and ASSERT_* macros, additional message information can be included using the << stream operator.

Example usage:

EXPECT_THROW_ERRNO(readFile("notpresent.txt"), ENOENT) << "notpresent.txt should not exist";

Definition at line 86 of file TestUtils.h.

#define EXPECT_THROW_RE (   statement,
  exceptionType,
  pattern 
)    TEST_THROW_RE_(statement, exceptionType, pattern, GTEST_NONFATAL_FAILURE_)

Check that a statement throws the expected exception type, and that the exception message matches the specified regular expression.

Partial matches (against just a portion of the error message) are accepted if the regular expression does not explicitly start with "^" and end with "$". (The matching is performed using std::regex_search() rather than std::regex_match().)

This uses ECMA-262 style regular expressions (the default behavior of std::regex).

Like other EXPECT_* and ASSERT_* macros, additional message information can be included using the << stream operator.

Example usage:

EXPECT_THROW_RE(badFunction(), std::runtime_error, "oh noes") << "function did not throw the expected exception";

Definition at line 119 of file TestUtils.h.

Referenced by TEST().

#define SKIP ( )    return GTEST_SUCCESS_("Test skipped by client")

Definition at line 55 of file TestUtils.h.

Referenced by TEST().

#define SKIP_IF (   expr)
Value:
if (!(expr)) { \
#define SKIP()
Definition: TestUtils.h:55
if(FOLLY_USE_SYMBOLIZER) add_library(folly_exception_tracer_base ExceptionTracer.cpp StackTrace.cpp) apply_folly_compile_options_to_target(folly_exception_tracer_base) target_link_libraries(folly_exception_tracer_base PUBLIC folly) add_library(folly_exception_tracer ExceptionStackTraceLib.cpp ExceptionTracerLib.cpp) apply_folly_compile_options_to_target(folly_exception_tracer) target_link_libraries(folly_exception_tracer PUBLIC folly_exception_tracer_base) add_library(folly_exception_counter ExceptionCounterLib.cpp) apply_folly_compile_options_to_target(folly_exception_counter) target_link_libraries(folly_exception_counter PUBLIC folly_exception_tracer) install(FILES ExceptionAbi.h ExceptionCounterLib.h ExceptionTracer.h ExceptionTracerLib.h StackTrace.h DESTINATION $
Definition: CMakeLists.txt:1

Definition at line 59 of file TestUtils.h.

Referenced by TEST().

#define TEST_THROW_ERRNO_ (   statement,
  errnoValue,
  fail 
)
Value:
[&] { statement; }, errnoValue, #statement)) { \
fail(gtest_result.what())
void fail()
if(FOLLY_USE_SYMBOLIZER) add_library(folly_exception_tracer_base ExceptionTracer.cpp StackTrace.cpp) apply_folly_compile_options_to_target(folly_exception_tracer_base) target_link_libraries(folly_exception_tracer_base PUBLIC folly) add_library(folly_exception_tracer ExceptionStackTraceLib.cpp ExceptionTracerLib.cpp) apply_folly_compile_options_to_target(folly_exception_tracer) target_link_libraries(folly_exception_tracer PUBLIC folly_exception_tracer_base) add_library(folly_exception_counter ExceptionCounterLib.cpp) apply_folly_compile_options_to_target(folly_exception_counter) target_link_libraries(folly_exception_counter PUBLIC folly_exception_tracer) install(FILES ExceptionAbi.h ExceptionCounterLib.h ExceptionTracer.h ExceptionTracerLib.h StackTrace.h DESTINATION $
Definition: CMakeLists.txt:1
CheckResult checkThrowErrno(Fn &&fn, int errnoValue, const char *statementStr)
Definition: TestUtils.h:181
int errnoValue
Definition: Subprocess.cpp:225

Definition at line 65 of file TestUtils.h.

#define TEST_THROW_RE_ (   statement,
  exceptionType,
  pattern,
  fail 
)
Value:
::folly::test::detail::checkThrowRegex<exceptionType>( \
[&] { statement; }, pattern, #statement, #exceptionType)) { \
fail(gtest_result.what())
void fail()
if(FOLLY_USE_SYMBOLIZER) add_library(folly_exception_tracer_base ExceptionTracer.cpp StackTrace.cpp) apply_folly_compile_options_to_target(folly_exception_tracer_base) target_link_libraries(folly_exception_tracer_base PUBLIC folly) add_library(folly_exception_tracer ExceptionStackTraceLib.cpp ExceptionTracerLib.cpp) apply_folly_compile_options_to_target(folly_exception_tracer) target_link_libraries(folly_exception_tracer PUBLIC folly_exception_tracer_base) add_library(folly_exception_counter ExceptionCounterLib.cpp) apply_folly_compile_options_to_target(folly_exception_counter) target_link_libraries(folly_exception_counter PUBLIC folly_exception_tracer) install(FILES ExceptionAbi.h ExceptionCounterLib.h ExceptionTracer.h ExceptionTracerLib.h StackTrace.h DESTINATION $
Definition: CMakeLists.txt:1

Definition at line 91 of file TestUtils.h.