]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
*alloc-gnu tests: Use ASSERT macro.
authorBruno Haible <bruno@clisp.org>
Fri, 14 May 2021 13:35:24 +0000 (15:35 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 14 May 2021 13:53:31 +0000 (15:53 +0200)
* tests/test-malloc-gnu.c: Include "macros.h".
(main): Use ASSERT.
* tests/test-calloc-gnu.c: Include "macros.h".
(main): Use ASSERT.
* tests/test-realloc-gnu.c: Include "macros.h".
(main): Use ASSERT.
* tests/test-reallocarray.c: Include "macros.h".
(main): Use ASSERT.
* modules/malloc-gnu-tests (Files): Add tests/macros.h.
* modules/calloc-gnu-tests (Files): Likewise.
* modules/realloc-gnu-tests (Files): Likewise.
* modules/reallocarray-tests (Files): Likewise.

ChangeLog
modules/calloc-gnu-tests
modules/malloc-gnu-tests
modules/realloc-gnu-tests
modules/reallocarray-tests
tests/test-calloc-gnu.c
tests/test-malloc-gnu.c
tests/test-realloc-gnu.c
tests/test-reallocarray.c

index 35afdfeb959fef897b760a291a139191160c25f1..3367d8dda56d01dd24124e20d5cf3cec30807f23 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2021-05-14  Bruno Haible  <bruno@clisp.org>
+
+       *alloc-gnu tests: Use ASSERT macro.
+       * tests/test-malloc-gnu.c: Include "macros.h".
+       (main): Use ASSERT.
+       * tests/test-calloc-gnu.c: Include "macros.h".
+       (main): Use ASSERT.
+       * tests/test-realloc-gnu.c: Include "macros.h".
+       (main): Use ASSERT.
+       * tests/test-reallocarray.c: Include "macros.h".
+       (main): Use ASSERT.
+       * modules/malloc-gnu-tests (Files): Add tests/macros.h.
+       * modules/calloc-gnu-tests (Files): Likewise.
+       * modules/realloc-gnu-tests (Files): Likewise.
+       * modules/reallocarray-tests (Files): Likewise.
+
 2021-05-14  Simon Josefsson  <simon@josefsson.org>
 
        valgrind-tests: Fix 'sh: yes: unknown operand' error.
index a4804fd2822db8ae5650efc78cf15f52bbb4214c..f0f061cd1103bcd2a2bd1bde01103d71dda44cf1 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-calloc-gnu.c
+tests/macros.h
 
 Depends-on:
 stdint
index 9a6f01cfa92d8c36c617931edffb3f0df22bcd27..dc1a34fe5cc6809ef862863cda3021858ed73a7b 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-malloc-gnu.c
+tests/macros.h
 
 Depends-on:
 stdint
index 9d26260ba732957d099f218932dba0ef676a41c9..c1dbe17b18b6eb82573dc0f9bff2faddf2ac810d 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-realloc-gnu.c
+tests/macros.h
 
 Depends-on:
 stdint
index 4b61da14351c0d093c38314204c67e43fe69dfb2..3082281dea07778c62ae263ec390fbf92542ec54 100644 (file)
@@ -1,6 +1,7 @@
 Files:
 tests/test-reallocarray.c
 tests/signature.h
+tests/macros.h
 
 Depends-on:
 stdint
index dbef019143f5f46406b4e502f3345b1c72be6a01..a98a75f703510dd4dbdb990464159a2741964eb0 100644 (file)
 
 #include <config.h>
 
+/* Specification.  */
 #include <stdlib.h>
 
 #include <errno.h>
 #include <stdint.h>
 
+#include "macros.h"
+
 /* Return N.
    Usual compilers are not able to infer something about the return value.  */
 static size_t
@@ -44,8 +47,7 @@ main ()
   /* Check that calloc (0, 0) is not a NULL pointer.  */
   {
     void * volatile p = calloc (0, 0);
-    if (p == NULL)
-      return 1;
+    ASSERT (p != NULL);
     free (p);
   }
 
@@ -58,11 +60,12 @@ main ()
     for (size_t n = 2; n != 0; n <<= 1)
       {
         void *volatile p = calloc (PTRDIFF_MAX / n + 1, identity (n));
-        if (!(p == NULL && errno == ENOMEM))
-          return 2;
-        p = calloc (SIZE_MAX / n + 1, identity (n));
-        if (!(p == NULL && errno == ENOMEM))
-          return 3;
+        ASSERT (p == NULL);
+        ASSERT (errno == ENOMEM);
+
+       p = calloc (SIZE_MAX / n + 1, identity (n));
+        ASSERT (p == NULL);
+        ASSERT (errno == ENOMEM);
       }
   }
 
index 13217c1b5113109e8f83cfdcd68a38130e2766d5..0160c6c49cba897e9e3ec51e797eb679b0246a3c 100644 (file)
 
 #include <config.h>
 
+/* Specification.  */
 #include <stdlib.h>
 
 #include <errno.h>
 #include <stdint.h>
 
+#include "macros.h"
+
 int
 main (int argc, char **argv)
 {
   /* Check that malloc (0) is not a NULL pointer.  */
   void *volatile p = malloc (0);
-  if (p == NULL)
-    return 1;
+  ASSERT (p != NULL);
   free (p);
 
   /* Check that malloc (n) fails when n exceeds PTRDIFF_MAX.  */
@@ -35,8 +37,8 @@ main (int argc, char **argv)
     {
       size_t one = argc != 12345;
       p = malloc (PTRDIFF_MAX + one);
-      if (!(p == NULL && errno == ENOMEM))
-        return 1;
+      ASSERT (p == NULL);
+      ASSERT (errno == ENOMEM);
     }
 
   return 0;
index a36673888b3017ebffdda6cc0ebe18693149d1c9..3a787ed91f40cb5d16ea5dee7fca192eca090316 100644 (file)
 
 #include <config.h>
 
+/* Specification.  */
 #include <stdlib.h>
 
 #include <errno.h>
 #include <stdint.h>
 
+#include "macros.h"
+
 int
 main (int argc, char **argv)
 {
   /* Check that realloc (NULL, 0) is not a NULL pointer.  */
   void *volatile p = realloc (NULL, 0);
-  if (p == NULL)
-    return 1;
+  ASSERT (p != NULL);
 
   /* Check that realloc (p, n) fails when p is non-null and n exceeds
      PTRDIFF_MAX.  */
@@ -35,8 +37,8 @@ main (int argc, char **argv)
     {
       size_t one = argc != 12345;
       p = realloc (p, PTRDIFF_MAX + one);
-      if (!(p == NULL && errno == ENOMEM))
-        return 1;
+      ASSERT (p == NULL);
+      ASSERT (errno == ENOMEM);
     }
 
   free (p);
index 8067542d5870fd01e75e059c7f92783cdc30894d..f0839ff748e7e9a6821babdcad34084420f6a34d 100644 (file)
 
 #include <config.h>
 
+/* Specification.  */
 #include <stdlib.h>
+
 #include <errno.h>
 #include <stdint.h>
 
 #include "signature.h"
 SIGNATURE_CHECK (reallocarray, void *, (void *, size_t, size_t));
 
+#include "macros.h"
+
 int
 main ()
 {
@@ -33,17 +37,13 @@ main ()
       void *volatile p = NULL;
 
       p = reallocarray (p, PTRDIFF_MAX / n + 1, n);
-      if (p)
-        return 1;
-      if (errno != ENOMEM)
-        return 2;
+      ASSERT (p == NULL);
+      ASSERT (errno == ENOMEM);
 
       p = reallocarray (p, SIZE_MAX / n + 1, n);
-      if (p)
-        return 3;
-      if (!(errno == ENOMEM
-            || errno == EOVERFLOW /* NetBSD */))
-        return 4;
+      ASSERT (p == NULL);
+      ASSERT (errno == ENOMEM
+              || errno == EOVERFLOW /* NetBSD */);
 
       /* Reallocarray should not crash with zero sizes.  */
       p = reallocarray (p, 0, n);