Mercurial > minori
comparison dep/fmt/test/test-assert.h @ 343:1faa72660932
*: transfer back to cmake from autotools
autotools just made lots of things more complicated than
they should have and many things broke (i.e. translations)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 20 Jun 2024 05:56:06 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
342:adb79bdde329 | 343:1faa72660932 |
---|---|
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 void 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 | |
19 class 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 | |
27 void 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. | |
31 inline 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_ |