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 8 #ifndef FMT_TEST_ASSERT_H_ 9 #define FMT_TEST_ASSERT_H_ 10 11 #include <stdexcept> 12 13 #include "gtest.h" 14 15 class assertion_failure : public std::logic_error { 16 public: assertion_failure(const char * message)17 explicit assertion_failure(const char* message) : std::logic_error(message) {} 18 19 private: 20 virtual void avoid_weak_vtable(); 21 }; 22 avoid_weak_vtable()23void assertion_failure::avoid_weak_vtable() {} 24 25 #define FMT_ASSERT(condition, message) \ 26 if (!(condition)) throw assertion_failure(message); 27 28 // Expects an assertion failure. 29 #define EXPECT_ASSERT(stmt, message) \ 30 FMT_TEST_THROW_(stmt, assertion_failure, message, GTEST_NONFATAL_FAILURE_) 31 32 #endif // FMT_TEST_ASSERT_H_ 33