]> Savannah Git Hosting - gnulib.git/commitdiff
xstrerror: Add tests.
authorBruno Haible <bruno@clisp.org>
Thu, 5 Oct 2023 16:02:26 +0000 (18:02 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 5 Oct 2023 20:08:00 +0000 (22:08 +0200)
* tests/test-xstrerror.c: New file.
* modules/xstrerror-tests: New file.

ChangeLog
modules/xstrerror-tests [new file with mode: 0644]
tests/test-xstrerror.c [new file with mode: 0644]

index b8aefaf2222c864d5169b36a7014527d92d42edf..6df9aaaef71c89313615be988a127110a56e6cbb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2023-10-05  Bruno Haible  <bruno@clisp.org>
 
+       xstrerror: Add tests.
+       * tests/test-xstrerror.c: New file.
+       * modules/xstrerror-tests: New file.
+
        xstrerror: New module.
        * lib/xstrerror.h: New file.
        * lib/xstrerror.c: New file.
diff --git a/modules/xstrerror-tests b/modules/xstrerror-tests
new file mode 100644 (file)
index 0000000..24a5fc9
--- /dev/null
@@ -0,0 +1,12 @@
+Files:
+tests/test-xstrerror.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-xstrerror
+check_PROGRAMS += test-xstrerror
+test_xstrerror_LDADD = $(LDADD) $(LIBINTL)
diff --git a/tests/test-xstrerror.c b/tests/test-xstrerror.c
new file mode 100644 (file)
index 0000000..d725aa1
--- /dev/null
@@ -0,0 +1,45 @@
+/* Test of xstrerror function.
+   Copyright (C) 2023 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
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2023.  */
+
+#include <config.h>
+
+#include "xstrerror.h"
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "macros.h"
+
+int
+main ()
+{
+  /* Test in the "C" locale.  */
+  {
+    char *s = xstrerror ("can't steal", EACCES);
+    ASSERT (strcmp (s, "can't steal: Permission denied") == 0);
+    free (s);
+  }
+  {
+    char *s = xstrerror (NULL, EACCES);
+    ASSERT (strcmp (s, "Permission denied") == 0);
+    free (s);
+  }
+
+  return 0;
+}