]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests/unit: fix empty statements with no effect
authorDaniel Stenberg <daniel@haxx.se>
Tue, 29 Dec 2020 16:21:24 +0000 (17:21 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 29 Dec 2020 22:02:43 +0000 (23:02 +0100)
... by making macros use "do {} while(0)"

tests/unit/curlcheck.h

index 88bbdcb52e3689c6522292e3dc55686130c3555e..3651551b3f8f1fc3e2c895e0c2216dae2d45f6f1 100644 (file)
 #include "test.h"
 
 /* The fail macros mark the current test step as failed, and continue */
-#define fail_if(expr, msg)                              \
-  if(expr) {                                            \
-    fprintf(stderr, "%s:%d Assertion '%s' met: %s\n",   \
-            __FILE__, __LINE__, #expr, msg);            \
-    unitfail++;                                         \
-  }
+#define fail_if(expr, msg)                                \
+  do {                                                    \
+    if(expr) {                                            \
+      fprintf(stderr, "%s:%d Assertion '%s' met: %s\n",   \
+              __FILE__, __LINE__, #expr, msg);            \
+      unitfail++;                                         \
+    }                                                     \
+  } while(0)
 
-#define fail_unless(expr, msg)                           \
-  if(!(expr)) {                                          \
-    fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \
-            __FILE__, __LINE__, #expr, msg);             \
-    unitfail++;                                          \
-  }
+#define fail_unless(expr, msg)                             \
+  do {                                                     \
+    if(!(expr)) {                                          \
+      fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \
+              __FILE__, __LINE__, #expr, msg);             \
+      unitfail++;                                          \
+    }                                                      \
+  } while(0)
 
-#define verify_memory(dynamic, check, len)                                  \
-  if(dynamic && memcmp(dynamic, check, len)) {                              \
-    fprintf(stderr, "%s:%d Memory buffer mismatch size %d. '%s' is not\n",  \
-            __FILE__, __LINE__, len,                                        \
-            hexdump((const unsigned char *)check, len));                    \
-    fprintf(stderr, "%s:%d the same as '%s'\n", __FILE__, __LINE__,         \
-            hexdump((const unsigned char *)dynamic, len));                  \
-    unitfail++;                                                             \
-  }
+#define verify_memory(dynamic, check, len)                              \
+  do {                                                                  \
+    if(dynamic && memcmp(dynamic, check, len)) {                             \
+      fprintf(stderr, "%s:%d Memory buffer mismatch size %d. '%s' is not\n", \
+              __FILE__, __LINE__, len,                                  \
+              hexdump((const unsigned char *)check, len));              \
+      fprintf(stderr, "%s:%d the same as '%s'\n", __FILE__, __LINE__,   \
+              hexdump((const unsigned char *)dynamic, len));            \
+      unitfail++;                                                       \
+    }                                                                   \
+  } while(0)
 
 /* fail() is for when the test case figured out by itself that a check
    proved a failure */
 
 
 /* The abort macros mark the current test step as failed, and exit the test */
-#define abort_if(expr, msg)                                   \
-  if(expr) {                                                  \
-    fprintf(stderr, "%s:%d Abort assertion '%s' met: %s\n",   \
-            __FILE__, __LINE__, #expr, msg);                  \
-    unitfail++;                                               \
-    goto unit_test_abort;                                     \
-  }
+#define abort_if(expr, msg)                                     \
+  do {                                                          \
+    if(expr) {                                                  \
+      fprintf(stderr, "%s:%d Abort assertion '%s' met: %s\n",   \
+              __FILE__, __LINE__, #expr, msg);                  \
+      unitfail++;                                               \
+      goto unit_test_abort;                                     \
+    }                                                           \
+  } while(0)
 
-#define abort_unless(expr, msg)                                \
-  if(!(expr)) {                                                \
-    fprintf(stderr, "%s:%d Abort assertion '%s' failed: %s\n", \
-            __FILE__, __LINE__, #expr, msg);                   \
-    unitfail++;                                                \
-    goto unit_test_abort;                                      \
-  }
+#define abort_unless(expr, msg)                                         \
+  do {                                                                  \
+    if(!(expr)) {                                                       \
+      fprintf(stderr, "%s:%d Abort assertion '%s' failed: %s\n",        \
+              __FILE__, __LINE__, #expr, msg);                          \
+      unitfail++;                                                       \
+      goto unit_test_abort;                                             \
+    }                                                                   \
+  } while(0)
 
-#define abort_test(msg) do {                                  \
+#define abort_test(msg)                                       \
+  do {                                                        \
     fprintf(stderr, "%s:%d test aborted: '%s'\n",             \
             __FILE__, __LINE__, msg);                         \
     unitfail++;                                               \
@@ -80,7 +91,6 @@
   } while(0)
 
 
-
 extern int unitfail;
 
 #define UNITTEST_START                          \