From: solar Date: Thu, 15 Dec 2005 12:35:00 +0000 (+0000) Subject: Added test driver. X-Git-Tag: v0.4~38 X-Git-Url: https://pd.if.org/git/?p=pdclib;a=commitdiff_plain;h=c5d3e636bfdbead4da6d41439043b2d10b252180 Added test driver. --- 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; }