X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fassert.c;h=cf3afb99e74d173fbb8cfe96873642139c381869;hp=67bf6d9412de144fb40e2cbcc8eea59610b495ac;hb=c5d3e636bfdbead4da6d41439043b2d10b252180;hpb=8a210237d6ac0dfb36ca14b5aebe8be2b967b9e6 diff --git a/functions/assert.c b/functions/assert.c index 67bf6d9..cf3afb9 100644 --- a/functions/assert.c +++ b/functions/assert.c @@ -31,12 +31,39 @@ void _PDCLIB_assert( char const * const message ) #ifdef TEST #include <_PDCLIB_test.h> +#include + +static int rc = 0; +static int EXPECTED_ABORT = 0; + +void aborthandler( int signal ) +{ + TESTCASE( ! EXPECTED_ABORT ); + exit( rc ); +} + +#define NDEBUG +#include + +int disabled_test() +{ + int i = 0; + assert( i == 0 ); /* NDEBUG set, condition met */ + assert( i == 1 ); /* NDEBUG set, condition fails */ + return i; +} + +#undef NDEBUG +#include int main() { - int NO_TESTDRIVER = 0; + int i = 0; BEGIN_TESTS; - TESTCASE( NO_TESTDRIVER ); + TESTCASE( signal( SIGABRT, &aborthandler ) != SIG_ERR ); + assert( i == 0 ); /* NDEBUG not set, condition met */ + puts( "Expecting failed assert() message here:" ); + assert( i == 1 ); /* NDEBUG not set, condition fails - should abort */ return TEST_RESULTS; }