libcryfs/test/cpp-utils/assert/assert_release_test.cpp
Sebastian Messmer ec9931e09e - Test showBacktraceOnSigsegv
- Test that failed assertions show a backtrace
2018-05-16 22:42:03 -07:00

45 lines
962 B
C++

#include <gtest/gtest.h>
#include <gmock/gmock.h>
//Include the ASSERT macro for a release build
#ifndef NDEBUG
#define NDEBUG
#endif
#include "cpp-utils/assert/assert.h"
using testing::MatchesRegex;
using testing::HasSubstr;
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(
"Assertion \\[2==5\\] failed in .*/assert_release_test.cpp:26: my message.*"
));
}
}
TEST(AssertTest_ReleaseBuild, AssertMessageContainsBacktrace) {
try {
ASSERT(2==5, "my message");
FAIL();
} catch (const cpputils::AssertFailed &e) {
EXPECT_THAT(e.what(), HasSubstr(
"cpputils::backtrace"
));
}
}