diff options
author | Werner Koch <[email protected]> | 2025-04-04 10:21:48 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2025-04-04 10:21:48 +0000 |
commit | be036dccd756e326470afcd7928a1d20790fc24a (patch) | |
tree | a8ea4efdfce1067215a61727cf210381a3a70b52 | |
parent | New public API gpgrt_strlist_* (diff) | |
download | libgpg-error-be036dccd756e326470afcd7928a1d20790fc24a.tar.gz libgpg-error-be036dccd756e326470afcd7928a1d20790fc24a.zip |
tests: Add macros to improve the debug output.
* tests/t-common.h (current_func): New var.
(enter_test_function, leave_test_function): New macros.
(die, fail, show): Print the fucntion name.
-rw-r--r-- | tests/t-common.h | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/tests/t-common.h b/tests/t-common.h index db496e2..edc7a93 100644 --- a/tests/t-common.h +++ b/tests/t-common.h @@ -32,13 +32,18 @@ static int verbose; static int debug; static int errorcount; - +static const char *current_func; static void die (const char *format, ...) GPGRT_ATTR_NR_PRINTF(1,2); static void fail (const char *format, ...) GPGRT_ATTR_PRINTF(1,2); static void show (const char *format, ...) GPGRT_ATTR_PRINTF(1,2); +/* Set the name of the function to be used in error messages. */ +#define enter_test_function() do { current_func = __func__; } while(0) +#define leave_test_function() do { current_func = NULL; } while(0) + + static void * xmalloc (size_t n) { @@ -75,7 +80,10 @@ die (const char *format, ...) #ifdef HAVE_FLOCKFILE flockfile (stderr); #endif - fprintf (stderr, "%s: ", PGM); + if (current_func) + fprintf (stderr, "%s:%s: ", PGM, current_func); + else + fprintf (stderr, "%s: ", PGM); va_start (arg_ptr, format) ; vfprintf (stderr, format, arg_ptr); va_end (arg_ptr); @@ -99,7 +107,10 @@ fail (const char *format, ...) #ifdef HAVE_FLOCKFILE flockfile (stderr); #endif - fprintf (stderr, "%s: ", PGM); + if (current_func) + fprintf (stderr, "%s:%s: ", PGM, current_func); + else + fprintf (stderr, "%s: ", PGM); va_start (arg_ptr, format); vfprintf (stderr, format, arg_ptr); va_end (arg_ptr); @@ -124,7 +135,10 @@ show (const char *format, ...) #ifdef HAVE_FLOCKFILE flockfile (stderr); #endif - fprintf (stderr, "%s: ", PGM); + if (current_func) + fprintf (stderr, "%s:%s: ", PGM, current_func); + else + fprintf (stderr, "%s: ", PGM); va_start (arg_ptr, format); vfprintf (stderr, format, arg_ptr); if (*format && format[strlen(format)-1] != '\n') |