enum_name
Loading...
Searching...
No Matches
test-assert.h
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
13void throw_assertion_failure(const char* message);
14#define FMT_ASSERT(condition, message) \
15 if (!(condition)) throw_assertion_failure(message);
16
17#include "gtest/gtest.h"
18
19class assertion_failure : public std::logic_error {
20 public:
21 explicit assertion_failure(const char* message) : std::logic_error(message) {}
22
23 private:
24 virtual void avoid_weak_vtable();
25};
26
27void assertion_failure::avoid_weak_vtable() {}
28
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.
31inline void throw_assertion_failure(const char* message) {
32 throw assertion_failure(message);
33}
34
35// Expects an assertion failure.
36#define EXPECT_ASSERT(stmt, message) \
37 FMT_TEST_THROW_(stmt, assertion_failure, message, GTEST_NONFATAL_FAILURE_)
38
39#endif // FMT_TEST_ASSERT_H_
Definition test-assert.h:19