summaryrefslogtreecommitdiff
path: root/tests/macros.h
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2022-02-07 06:57:44 +0100
committerJörg Frings-Fürst <debian@jff.email>2022-02-07 06:57:44 +0100
commit6ffaa52cf732a84c0f8259dbc9b8183960ec5c33 (patch)
treed3136c22e3e805cfc0efe78412cce905a17e0c8d /tests/macros.h
parent591cbf5878b7d4105b275585b9db1324c9dfce56 (diff)
parentaf151c593704a40e10efb28d1e3dd59a23a661f3 (diff)
Merge branch 'release/debian/1.0-1'debian/1.0-1
Diffstat (limited to 'tests/macros.h')
-rw-r--r--tests/macros.h40
1 files changed, 34 insertions, 6 deletions
diff --git a/tests/macros.h b/tests/macros.h
index dd6357a6..392d58fb 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 <stdlib.h>
#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 <string.h> and #include <unistd.h>. */
+#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