diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2025-03-22 18:00:25 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2025-03-22 18:00:25 +0100 |
commit | 0737819efdd0bae112d16d874cac7e747e43cd08 (patch) | |
tree | 98a9ac84f7f347ae530c14852c68870682f3d04c /tests/macros.h | |
parent | 163a663518f33bab48b28431972e580b366b4d49 (diff) | |
parent | e670957a8693f860cf7d77fed4ce6b4b056a8083 (diff) |
Merge branch 'release/debian/1.3-1'debian/1.3-1
Diffstat (limited to 'tests/macros.h')
-rw-r--r-- | tests/macros.h | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/tests/macros.h b/tests/macros.h index d182cd6f..55163c65 100644 --- a/tests/macros.h +++ b/tests/macros.h @@ -29,12 +29,39 @@ # endif #endif +/* Define NO_MAIN_HERE before including this file, if this compilation unit + does not contain a main() function. */ + +/* Optionally define CONTINUE_AFTER_ASSERT to 1 before including this file, + if you wish execution to continue after an ASSERT or ASSERT_NO_STDIO + failure. */ +#ifndef CONTINUE_AFTER_ASSERT +# define CONTINUE_AFTER_ASSERT 0 +#endif + /* Define ASSERT_STREAM before including this file if ASSERT must target a stream other than stderr. */ #ifndef ASSERT_STREAM # define ASSERT_STREAM stderr #endif +/* Define print_stack_trace() to a no-op, if the module 'stack-trace' is not + in use. */ +#if !GNULIB_STACK_TRACE +# define print_stack_trace() /* nothing */ +#endif + +/* Exit status of the test. + Initialized to EXIT_SUCCESS. + Set to EXIT_FAILURE when an ASSERT or ASSERT_NO_STDIO fails. */ +/* To satisfy the "one definition rule", we define the variable in the + compilation unit that contains the main() function. */ +#ifdef NO_MAIN_HERE +extern int volatile test_exit_status; +#else +int volatile test_exit_status = EXIT_SUCCESS; +#endif + /* ASSERT (condition); verifies that the specified condition is fulfilled. If not, a message is printed to ASSERT_STREAM if defined (defaulting to stderr if @@ -59,7 +86,13 @@ fprintf (ASSERT_STREAM, "%s:%d: assertion '%s' failed\n", \ __FILE__, __LINE__, #expr); \ fflush (ASSERT_STREAM); \ - abort (); \ + if (CONTINUE_AFTER_ASSERT) \ + { \ + print_stack_trace (); \ + test_exit_status = EXIT_FAILURE; \ + } \ + else \ + abort (); \ } \ } \ while (0) @@ -77,7 +110,13 @@ WRITE_TO_STDERR (": assertion '"); \ WRITE_TO_STDERR (#expr); \ WRITE_TO_STDERR ("' failed\n"); \ - abort (); \ + if (CONTINUE_AFTER_ASSERT) \ + { \ + print_stack_trace (); \ + test_exit_status = EXIT_FAILURE; \ + } \ + else \ + abort (); \ } \ } \ while (0) |