changeset 40091:fd583bcb1e66

xstdopen: Add tests. * tests/test-xstdopen.c: New file. * tests/test-xstdopen.sh: New file. * modules/xstdopen-tests: New file.
author Bruno Haible <bruno@clisp.org>
date Sun, 06 Jan 2019 09:27:42 +0100
parents bebb827b568f
children 943155cd4a86
files ChangeLog modules/xstdopen-tests tests/test-xstdopen.c tests/test-xstdopen.sh
diffstat 4 files changed, 69 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Jan 06 09:25:59 2019 +0100
+++ b/ChangeLog	Sun Jan 06 09:27:42 2019 +0100
@@ -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.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/xstdopen-tests	Sun Jan 06 09:27:42 2019 +0100
@@ -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@
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-xstdopen.c	Sun Jan 06 09:27:42 2019 +0100
@@ -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;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-xstdopen.sh	Sun Jan 06 09:27:42 2019 +0100
@@ -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