]> Savannah Git Hosting - gnulib.git/commitdiff
xstdopen: Add tests.
authorBruno Haible <bruno@clisp.org>
Sun, 6 Jan 2019 08:27:42 +0000 (09:27 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 6 Jan 2019 08:29:03 +0000 (09:29 +0100)
* tests/test-xstdopen.c: New file.
* tests/test-xstdopen.sh: New file.
* modules/xstdopen-tests: New file.

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

index 89e57e65157f27e77a674df31b7ab7d2fdf83c67..f9ecd2e27bf5e99c9abcf7d8b9c9223fef67199f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2019-01-06  Bruno Haible  <bruno@clisp.org>
 
+       xstdopen: Add tests.
+       * tests/test-xstdopen.c: New file.
+       * tests/test-xstdopen.sh: New file.
+       * modules/xstdopen-tests: New file.
+
        xstdopen: New module.
        * lib/xstdopen.h: New file.
        * lib/xstdopen.c: New file.
diff --git a/modules/xstdopen-tests b/modules/xstdopen-tests
new file mode 100644 (file)
index 0000000..0810f4a
--- /dev/null
@@ -0,0 +1,12 @@
+Files:
+tests/test-xstdopen.c
+tests/test-xstdopen.sh
+tests/macros.h
+
+Depends-on:
+test-framework-sh
+
+Makefile.am:
+TESTS += test-xstdopen.sh
+check_PROGRAMS += test-xstdopen
+test_xstdopen_LDADD = $(LDADD) @LIBINTL@
diff --git a/tests/test-xstdopen.c b/tests/test-xstdopen.c
new file mode 100644 (file)
index 0000000..0bd4a43
--- /dev/null
@@ -0,0 +1,32 @@
+/* Test of xstdopen() function.
+   Copyright (C) 2019 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/>.  */
+
+#include <config.h>
+
+#include "xstdopen.h"
+
+#include <fcntl.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  xstdopen ();
+  ASSERT (open ("Makefile", O_RDONLY) >= 3);
+
+  return 0;
+}
diff --git a/tests/test-xstdopen.sh b/tests/test-xstdopen.sh
new file mode 100755 (executable)
index 0000000..5ad2ad2
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# Test with all of stdin, stdout, stderr open.
+./test-xstdopen || exit 1
+
+# The syntax for closed file descriptors in sh scripts is specified by POSIX in
+# section 2.7.5 of
+# http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
+
+# Test with stdin closed.
+./test-xstdopen <&- || exit 1
+
+# Test with stdout closed.
+./test-xstdopen >&- || exit 1
+
+# Test with stderr closed.
+./test-xstdopen 2>&- || exit 1
+
+# Test with all of stdin, stdout, stderr closed.
+./test-xstdopen <&- >&- 2>&- || exit 1