Fix assertion tests

This commit is contained in:
vitaut 2015-06-22 09:24:54 -07:00
parent 8ab665afbc
commit abcc2d96f0
3 changed files with 17 additions and 9 deletions

View File

@ -153,12 +153,14 @@ inline uint32_t clzll(uint64_t x) {
#endif
// Define FMT_USE_NOEXCEPT to make C++ Format use noexcept (C++11 feature).
#ifndef FMT_NOEXCEPT
# if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \
(FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11)
# define FMT_NOEXCEPT noexcept
# else
# define FMT_NOEXCEPT throw()
# endif
#endif
// A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for a class

View File

@ -25,6 +25,7 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define FMT_NOEXCEPT
#include "test-assert.h"
// Include format.cc instead of format.h to test implementation-specific stuff.

View File

@ -28,15 +28,20 @@
#ifndef FMT_TEST_ASSERT_H
#define FMT_TEST_ASSERT_H
#include <string>
#include <stdexcept>
static std::string last_assert;
class AssertionFailure : public std::logic_error {
public:
explicit AssertionFailure(const char *message) : std::logic_error(message) {}
};
#define FMT_ASSERT(condition, message) \
if (!(condition)) last_assert = message;
if (!(condition)) throw AssertionFailure(message);
#include "gtest-extra.h"
// Expects an assertion failure.
#define EXPECT_ASSERT(stmt, message) \
{ last_assert = ""; stmt; EXPECT_EQ(last_assert, message); }
EXPECT_THROW_MSG(stmt, AssertionFailure, message)
#endif // FMT_TEST_ASSERT_H