fmt/test/test-assert.h

27 lines
708 B
C
Raw Normal View History

2018-03-04 17:16:51 +00: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 15:17:23 +00:00
#ifndef FMT_TEST_ASSERT_H_
#define FMT_TEST_ASSERT_H_
2015-06-22 15:17:23 +00:00
2015-06-22 16:24:54 +00:00
#include <stdexcept>
#include "gtest.h"
2015-06-22 15:17:23 +00:00
class assertion_failure : public std::logic_error {
2015-06-22 16:24:54 +00:00
public:
explicit assertion_failure(const char *message) : std::logic_error(message) {}
2015-06-22 16:24:54 +00:00
};
2015-06-22 15:17:23 +00:00
#define FMT_ASSERT(condition, message) \
if (!(condition)) throw assertion_failure(message);
2015-06-22 15:17:23 +00:00
// Expects an assertion failure.
#define EXPECT_ASSERT(stmt, message) \
FMT_TEST_THROW_(stmt, assertion_failure, message, GTEST_NONFATAL_FAILURE_)
2015-06-22 15:17:23 +00:00
#endif // FMT_TEST_ASSERT_H_