From be8efac78d067c138ad8dda03df4336e73f94887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 8 Jan 2022 11:51:07 +0100 Subject: New upstream version 1.0 --- tests/macros.h | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'tests/macros.h') diff --git a/tests/macros.h b/tests/macros.h index dd6357a..392d58f 100644 --- a/tests/macros.h +++ b/tests/macros.h @@ -1,5 +1,5 @@ /* Common macros used by gnulib tests. - Copyright (C) 2006-2018 Free Software Foundation, Inc. + Copyright (C) 2006-2022 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,10 +22,10 @@ #include #ifndef FALLTHROUGH -# if __GNUC__ < 7 -# define FALLTHROUGH ((void) 0) -# else +# if (__GNUC__ >= 7) || (__clang_major__ >= 10) # define FALLTHROUGH __attribute__ ((__fallthrough__)) +# else +# define FALLTHROUGH ((void) 0) # endif #endif @@ -56,14 +56,42 @@ { \ if (!(expr)) \ { \ - fprintf (ASSERT_STREAM, "%s:%d: assertion '%s' failed\n", \ - __FILE__, __LINE__, #expr); \ + fprintf (ASSERT_STREAM, "%s:%d: assertion '%s' failed\n", \ + __FILE__, __LINE__, #expr); \ fflush (ASSERT_STREAM); \ abort (); \ } \ } \ while (0) +/* Like ASSERT, except that it uses no stdio. + Requires #include and #include . */ +#define ASSERT_NO_STDIO(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + WRITE_TO_STDERR (__FILE__); \ + WRITE_TO_STDERR (":"); \ + WRITE_MACROEXPANDED_INTEGER_TO_STDERR (__LINE__); \ + WRITE_TO_STDERR (": assertion '"); \ + WRITE_TO_STDERR (#expr); \ + WRITE_TO_STDERR ("' failed\n"); \ + abort (); \ + } \ + } \ + while (0) +#define WRITE_MACROEXPANDED_INTEGER_TO_STDERR(integer) \ + WRITE_INTEGER_TO_STDERR(integer) +#define WRITE_INTEGER_TO_STDERR(integer) \ + WRITE_TO_STDERR (#integer) +#define WRITE_TO_STDERR(string_literal) \ + { \ + const char *s = string_literal; \ + int ret = write (2, s, strlen (s)); \ + (void) ret; \ + } + /* SIZEOF (array) returns the number of elements of an array. It works for arrays that are declared outside functions and for local variables of array type. It does -- cgit v1.2.3