test-assert.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Formatting library for C++ - test version of FMT_ASSERT
  2. //
  3. // Copyright (c) 2012 - present, Victor Zverovich
  4. // All rights reserved.
  5. //
  6. // For the license information refer to format.h.
  7. #ifndef FMT_TEST_ASSERT_H_
  8. #define FMT_TEST_ASSERT_H_
  9. #include <stdexcept>
  10. void throw_assertion_failure(const char* message);
  11. #define FMT_ASSERT(condition, message) \
  12. if (!(condition)) throw_assertion_failure(message);
  13. #include "gtest/gtest.h"
  14. class assertion_failure : public std::logic_error {
  15. public:
  16. explicit assertion_failure(const char* message) : std::logic_error(message) {}
  17. private:
  18. virtual void avoid_weak_vtable();
  19. };
  20. void assertion_failure::avoid_weak_vtable() {}
  21. // We use a separate function (rather than throw directly from FMT_ASSERT) to
  22. // avoid GCC's -Wterminate warning when FMT_ASSERT is used in a destructor.
  23. inline void throw_assertion_failure(const char* message) {
  24. throw assertion_failure(message);
  25. }
  26. // Expects an assertion failure.
  27. #define EXPECT_ASSERT(stmt, message) \
  28. FMT_TEST_THROW_(stmt, assertion_failure, message, GTEST_NONFATAL_FAILURE_)
  29. #endif // FMT_TEST_ASSERT_H_