* tests/test-xstdopen.c: New file.
* tests/test-xstdopen.sh: New file.
* modules/xstdopen-tests: New file.
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.
--- /dev/null
+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@
--- /dev/null
+/* 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;
+}
--- /dev/null
+#!/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