diff --git a/doc/xml/release.xml b/doc/xml/release.xml index f49788941..cd038cf4c 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -30,6 +30,10 @@

Start work on C handle io object and use it to output help.

+ + +

Add ASSERT() that is preserved in production builds.

+
diff --git a/src/common/debug.h b/src/common/debug.h index 1f8499dfb..fa36ffb4a 100644 --- a/src/common/debug.h +++ b/src/common/debug.h @@ -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) diff --git a/test/lib/pgBackRestTest/Common/DefineTest.pm b/test/lib/pgBackRestTest/Common/DefineTest.pm index 2d316bc01..bed50b1ef 100644 --- a/test/lib/pgBackRestTest/Common/DefineTest.pm +++ b/test/lib/pgBackRestTest/Common/DefineTest.pm @@ -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', diff --git a/test/src/module/common/debugOffTest.c b/test/src/module/common/debugOffTest.c index 99ddf08c7..44d13828e 100644 --- a/test/src/module/common/debugOffTest.c +++ b/test/src/module/common/debugOffTest.c @@ -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()")) { diff --git a/test/src/module/common/debugOnTest.c b/test/src/module/common/debugOnTest.c index f2ca06c52..be91e115e 100644 --- a/test/src/module/common/debugOnTest.c +++ b/test/src/module/common/debugOnTest.c @@ -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"); } }