2018-03-04 20:16:51 +03:00
|
|
|
// Formatting library for C++ - test version of FMT_ASSERT
|
|
|
|
//
|
|
|
|
// Copyright (c) 2012 - present, Victor Zverovich
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// For the license information refer to format.h.
|
2015-06-22 18:17:23 +03:00
|
|
|
|
2018-09-19 18:55:45 +03:00
|
|
|
#ifndef FMT_TEST_ASSERT_H_
|
|
|
|
#define FMT_TEST_ASSERT_H_
|
2015-06-22 18:17:23 +03:00
|
|
|
|
2015-06-22 19:24:54 +03:00
|
|
|
#include <stdexcept>
|
2020-05-08 01:59:46 +03:00
|
|
|
|
2021-05-01 00:21:49 +03:00
|
|
|
void throw_assertion_failure(const char* message);
|
|
|
|
#define FMT_ASSERT(condition, message) \
|
|
|
|
if (!(condition)) throw_assertion_failure(message);
|
|
|
|
|
|
|
|
#include "gtest-extra.h"
|
2021-04-29 01:59:43 +03:00
|
|
|
#include "gtest/gtest.h"
|
2015-06-22 18:17:23 +03:00
|
|
|
|
2018-09-19 18:55:45 +03:00
|
|
|
class assertion_failure : public std::logic_error {
|
2015-06-22 19:24:54 +03:00
|
|
|
public:
|
2019-01-13 05:27:38 +03:00
|
|
|
explicit assertion_failure(const char* message) : std::logic_error(message) {}
|
2019-10-11 20:44:20 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual void avoid_weak_vtable();
|
2015-06-22 19:24:54 +03:00
|
|
|
};
|
2015-06-22 18:17:23 +03:00
|
|
|
|
2019-10-11 20:44:20 +03:00
|
|
|
void assertion_failure::avoid_weak_vtable() {}
|
|
|
|
|
2021-03-04 18:28:04 +03:00
|
|
|
// We use a separate function (rather than throw directly from FMT_ASSERT) to
|
|
|
|
// avoid GCC's -Wterminate warning when FMT_ASSERT is used in a destructor.
|
|
|
|
inline void throw_assertion_failure(const char* message) {
|
|
|
|
throw assertion_failure(message);
|
|
|
|
}
|
|
|
|
|
2015-06-22 18:17:23 +03:00
|
|
|
// Expects an assertion failure.
|
|
|
|
#define EXPECT_ASSERT(stmt, message) \
|
2018-09-19 18:55:45 +03:00
|
|
|
FMT_TEST_THROW_(stmt, assertion_failure, message, GTEST_NONFATAL_FAILURE_)
|
2015-06-22 18:17:23 +03:00
|
|
|
|
2018-09-19 18:55:45 +03:00
|
|
|
#endif // FMT_TEST_ASSERT_H_
|