libcryfs/test/cpp-utils/assert/assert_debug_test.cpp

51 lines
1.1 KiB
C++
Raw Normal View History

#include <gtest/gtest.h>
#include <gmock/gmock.h>
2015-07-22 13:38:36 +02:00
#ifdef NDEBUG
#define _REAL_NDEBUG
#endif
2015-07-22 13:38:36 +02:00
//Include the ASSERT macro for a debug build
#undef NDEBUG
2016-02-11 12:53:42 +01:00
#include "cpp-utils/assert/assert.h"
2015-07-22 13:38:36 +02:00
TEST(AssertTest_DebugBuild, DoesntDieIfTrue) {
ASSERT(true, "bla");
}
TEST(AssertTest_DebugBuild, DiesIfFalse) {
EXPECT_DEATH(
ASSERT(false, "bla"),
""
);
}
TEST(AssertTest_DebugBuild, AssertMessage) {
2018-07-09 04:34:08 +02:00
#if defined(_MSC_VER)
constexpr const char* EXPECTED = R"(Assertion \[2==5\] failed in .*assert_debug_test.cpp:\d+: my message)";
#else
constexpr const char* EXPECTED = R"(Assertion \[2==5\] failed in .*assert_debug_test.cpp:[0-9]+: my message)";
#endif
2015-07-22 13:38:36 +02:00
EXPECT_DEATH(
ASSERT(2==5, "my message"),
2018-07-09 04:34:08 +02:00
EXPECTED
2015-07-22 13:38:36 +02:00
);
}
#if !(defined(_MSC_VER) && defined(_REAL_NDEBUG))
TEST(AssertTest_DebugBuild, AssertMessageContainsBacktrace) {
EXPECT_DEATH(
ASSERT(2==5, "my message"),
2018-09-19 12:01:31 +02:00
"cpputils::"
);
}
#else
TEST(AssertTest_DebugBuild, AssertMessageContainsBacktrace) {
EXPECT_DEATH(
ASSERT(2==5, "my message"),
"#1"
);
}
#endif