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