>From 7687815c173602e485c86ab73da09e1b583c9232 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 6 Jan 2019 09:27:42 +0100 Subject: [PATCH 3/3] xstdopen: Add tests. * tests/test-xstdopen.c: New file. * tests/test-xstdopen.sh: New file. * modules/xstdopen-tests: New file. --- ChangeLog | 5 +++++ modules/xstdopen-tests | 12 ++++++++++++ tests/test-xstdopen.c | 32 ++++++++++++++++++++++++++++++++ tests/test-xstdopen.sh | 20 ++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 modules/xstdopen-tests create mode 100644 tests/test-xstdopen.c create mode 100755 tests/test-xstdopen.sh diff --git a/ChangeLog b/ChangeLog index 89e57e6..f9ecd2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2019-01-06 Bruno Haible + 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 index 0000000..0810f4a --- /dev/null +++ b/modules/xstdopen-tests @@ -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 index 0000000..0bd4a43 --- /dev/null +++ b/tests/test-xstdopen.c @@ -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 . */ + +#include + +#include "xstdopen.h" + +#include + +#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 index 0000000..5ad2ad2 --- /dev/null +++ b/tests/test-xstdopen.sh @@ -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 -- 2.7.4