mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-30 05:39:12 +02:00
Add ASSERT() that is preserved in production builds.
This commit is contained in:
parent
a8721ffe11
commit
635caff573
@ -30,6 +30,10 @@
|
||||
<release-item>
|
||||
<p>Start work on C handle io object and use it to output help.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Add <code>ASSERT()</code> that is preserved in production builds.</p>
|
||||
</release-item>
|
||||
</release-development-list>
|
||||
</release-core-list>
|
||||
|
||||
|
@ -15,15 +15,21 @@ NDEBUG indicates to C library routines that debugging is off -- set a more reada
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Assert Macros
|
||||
|
||||
Used for assertions that should only be run when debugging. Ideal for conditions that are not likely to happen in production but
|
||||
could occur during development.
|
||||
***********************************************************************************************************************************/
|
||||
// For very important asserts that are shipped with the production code.
|
||||
#define ASSERT(condition) \
|
||||
{ \
|
||||
if (!(condition)) \
|
||||
THROW(AssertError, "assertion '%s' failed", #condition); \
|
||||
}
|
||||
|
||||
// Used for assertions that should only be run when debugging. Ideal for conditions that are not likely to happen in production but
|
||||
// could occur during development.
|
||||
#ifdef DEBUG
|
||||
#define ASSERT_DEBUG(condition) \
|
||||
{ \
|
||||
if (!(condition)) \
|
||||
THROW(AssertError, "assertion '%s' failed", #condition); \
|
||||
THROW(AssertError, "debug assertion '%s' failed", #condition); \
|
||||
}
|
||||
#else
|
||||
#define ASSERT_DEBUG(condition)
|
||||
|
@ -157,7 +157,7 @@ my $oTestDef =
|
||||
},
|
||||
{
|
||||
&TESTDEF_NAME => 'debug-on',
|
||||
&TESTDEF_TOTAL => 1,
|
||||
&TESTDEF_TOTAL => 2,
|
||||
&TESTDEF_C => true,
|
||||
|
||||
&TESTDEF_COVERAGE =>
|
||||
@ -167,7 +167,7 @@ my $oTestDef =
|
||||
},
|
||||
{
|
||||
&TESTDEF_NAME => 'debug-off',
|
||||
&TESTDEF_TOTAL => 1,
|
||||
&TESTDEF_TOTAL => 2,
|
||||
&TESTDEF_C => true,
|
||||
&TESTDEF_CDEF => '-DNDEBUG -DNO_LOG',
|
||||
|
||||
|
@ -8,6 +8,13 @@ Test Run
|
||||
void
|
||||
testRun()
|
||||
{
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
if (testBegin("ASSERT()"))
|
||||
{
|
||||
TEST_RESULT_VOID(ASSERT(true), "assert true");
|
||||
TEST_ERROR(ASSERT(false || false), AssertError, "assertion 'false || false' failed");
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
if (testBegin("ASSERT_DEBUG()"))
|
||||
{
|
||||
|
@ -8,10 +8,17 @@ Test Run
|
||||
void
|
||||
testRun()
|
||||
{
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
if (testBegin("ASSERT()"))
|
||||
{
|
||||
TEST_RESULT_VOID(ASSERT(true), "assert true");
|
||||
TEST_ERROR(ASSERT(false || false), AssertError, "assertion 'false || false' failed");
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
if (testBegin("ASSERT_DEBUG()"))
|
||||
{
|
||||
TEST_RESULT_VOID(ASSERT_DEBUG(true), "assert true");
|
||||
TEST_ERROR(ASSERT_DEBUG(false || false), AssertError, "assertion 'false || false' failed");
|
||||
TEST_ERROR(ASSERT_DEBUG(false || false), AssertError, "debug assertion 'false || false' failed");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user