You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-17 01:12:23 +02:00
Add ASSERT() that is preserved in production builds.
This commit is contained in:
@ -30,6 +30,10 @@
|
|||||||
<release-item>
|
<release-item>
|
||||||
<p>Start work on C handle io object and use it to output help.</p>
|
<p>Start work on C handle io object and use it to output help.</p>
|
||||||
</release-item>
|
</release-item>
|
||||||
|
|
||||||
|
<release-item>
|
||||||
|
<p>Add <code>ASSERT()</code> that is preserved in production builds.</p>
|
||||||
|
</release-item>
|
||||||
</release-development-list>
|
</release-development-list>
|
||||||
</release-core-list>
|
</release-core-list>
|
||||||
|
|
||||||
|
@ -15,15 +15,21 @@ NDEBUG indicates to C library routines that debugging is off -- set a more reada
|
|||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Assert Macros
|
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
|
#ifdef DEBUG
|
||||||
#define ASSERT_DEBUG(condition) \
|
#define ASSERT_DEBUG(condition) \
|
||||||
{ \
|
{ \
|
||||||
if (!(condition)) \
|
if (!(condition)) \
|
||||||
THROW(AssertError, "assertion '%s' failed", #condition); \
|
THROW(AssertError, "debug assertion '%s' failed", #condition); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define ASSERT_DEBUG(condition)
|
#define ASSERT_DEBUG(condition)
|
||||||
|
@ -157,7 +157,7 @@ my $oTestDef =
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&TESTDEF_NAME => 'debug-on',
|
&TESTDEF_NAME => 'debug-on',
|
||||||
&TESTDEF_TOTAL => 1,
|
&TESTDEF_TOTAL => 2,
|
||||||
&TESTDEF_C => true,
|
&TESTDEF_C => true,
|
||||||
|
|
||||||
&TESTDEF_COVERAGE =>
|
&TESTDEF_COVERAGE =>
|
||||||
@ -167,7 +167,7 @@ my $oTestDef =
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&TESTDEF_NAME => 'debug-off',
|
&TESTDEF_NAME => 'debug-off',
|
||||||
&TESTDEF_TOTAL => 1,
|
&TESTDEF_TOTAL => 2,
|
||||||
&TESTDEF_C => true,
|
&TESTDEF_C => true,
|
||||||
&TESTDEF_CDEF => '-DNDEBUG -DNO_LOG',
|
&TESTDEF_CDEF => '-DNDEBUG -DNO_LOG',
|
||||||
|
|
||||||
|
@ -8,6 +8,13 @@ Test Run
|
|||||||
void
|
void
|
||||||
testRun()
|
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()"))
|
if (testBegin("ASSERT_DEBUG()"))
|
||||||
{
|
{
|
||||||
|
@ -8,10 +8,17 @@ Test Run
|
|||||||
void
|
void
|
||||||
testRun()
|
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()"))
|
if (testBegin("ASSERT_DEBUG()"))
|
||||||
{
|
{
|
||||||
TEST_RESULT_VOID(ASSERT_DEBUG(true), "assert true");
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user