2016-02-10 00:58:03 +01:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <gmock/gmock.h>
|
2015-07-22 13:38:36 +02:00
|
|
|
|
|
|
|
//Include the ASSERT macro for a release build
|
2016-07-10 22:15:48 +02:00
|
|
|
#ifndef NDEBUG
|
2015-07-22 13:38:36 +02:00
|
|
|
#define NDEBUG
|
2016-07-10 22:15:48 +02:00
|
|
|
#endif
|
2016-02-11 12:53:42 +01:00
|
|
|
#include "cpp-utils/assert/assert.h"
|
2015-07-22 13:38:36 +02:00
|
|
|
|
|
|
|
using testing::MatchesRegex;
|
|
|
|
|
|
|
|
TEST(AssertTest_ReleaseBuild, DoesntThrowIfTrue) {
|
|
|
|
ASSERT(true, "bla");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(AssertTest_ReleaseBuild, ThrowsIfFalse) {
|
|
|
|
EXPECT_THROW(
|
|
|
|
ASSERT(false, "bla"),
|
|
|
|
cpputils::AssertFailed
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(AssertTest_ReleaseBuild, AssertMessage) {
|
|
|
|
try {
|
|
|
|
ASSERT(2==5, "my message");
|
|
|
|
FAIL();
|
|
|
|
} catch (const cpputils::AssertFailed &e) {
|
|
|
|
EXPECT_THAT(e.what(), MatchesRegex(
|
2015-10-03 01:30:42 +02:00
|
|
|
"Assertion \\[2==5\\] failed in .*/assert_release_test.cpp:23: my message.*"
|
2015-07-22 13:38:36 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|