- Test showBacktraceOnSigsegv
- Test that failed assertions show a backtrace
This commit is contained in:
parent
3563f4687d
commit
ec9931e09e
@ -37,6 +37,7 @@ set(SOURCES
|
||||
data/DataFixture.cpp
|
||||
data/DataUtils.cpp
|
||||
data/Data.cpp
|
||||
assert/assert.h
|
||||
assert/backtrace_nonwindows.cpp
|
||||
assert/backtrace_windows.cpp
|
||||
assert/AssertFailed.cpp
|
||||
|
1
src/cpp-utils/assert/assert.cpp
Normal file
1
src/cpp-utils/assert/assert.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "assert.h"
|
@ -43,8 +43,6 @@ set(SOURCES
|
||||
logging/LoggingIncludeTest.cpp
|
||||
assert/assert_release_test.cpp
|
||||
assert/backtrace_test.cpp
|
||||
assert/backtrace_include_test.cpp
|
||||
assert/assert_include_test.cpp
|
||||
assert/assert_debug_test.cpp
|
||||
system/GetTotalMemoryTest.cpp
|
||||
system/TimeTest.cpp
|
||||
|
@ -23,3 +23,10 @@ TEST(AssertTest_DebugBuild, AssertMessage) {
|
||||
"Assertion \\[2==5\\] failed in .*/assert_debug_test.cpp:[0-9]+: my message"
|
||||
);
|
||||
}
|
||||
|
||||
TEST(AssertTest_DebugBuild, AssertMessageContainsBacktrace) {
|
||||
EXPECT_DEATH(
|
||||
ASSERT(2==5, "my message"),
|
||||
"cpputils::backtrace"
|
||||
);
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
#include "cpp-utils/assert/assert.h"
|
||||
|
||||
// Test the header can be included without needing additional dependencies
|
@ -8,6 +8,7 @@
|
||||
#include "cpp-utils/assert/assert.h"
|
||||
|
||||
using testing::MatchesRegex;
|
||||
using testing::HasSubstr;
|
||||
|
||||
TEST(AssertTest_ReleaseBuild, DoesntThrowIfTrue) {
|
||||
ASSERT(true, "bla");
|
||||
@ -26,7 +27,18 @@ TEST(AssertTest_ReleaseBuild, AssertMessage) {
|
||||
FAIL();
|
||||
} catch (const cpputils::AssertFailed &e) {
|
||||
EXPECT_THAT(e.what(), MatchesRegex(
|
||||
"Assertion \\[2==5\\] failed in .*/assert_release_test.cpp:25: my message.*"
|
||||
"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"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +0,0 @@
|
||||
#include "cpp-utils/assert/backtrace.h"
|
||||
|
||||
// Test the header can be included without needing additional dependencies
|
||||
|
@ -14,3 +14,19 @@ TEST(BacktraceTest, ContainsTopLevelLine) {
|
||||
EXPECT_THAT(backtrace, HasSubstr("BacktraceTest"));
|
||||
EXPECT_THAT(backtrace, HasSubstr("ContainsTopLevelLine"));
|
||||
}
|
||||
|
||||
namespace {
|
||||
void cause_sigsegv() {
|
||||
cpputils::showBacktraceOnSigSegv();
|
||||
int* ptr = nullptr;
|
||||
int a = *ptr;
|
||||
(void)a;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(BacktraceTest, ShowBacktraceOnSigSegv) {
|
||||
EXPECT_DEATH(
|
||||
cause_sigsegv(),
|
||||
"cpputils::backtrace"
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user