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