maint: Update HACKING
[automake.git] / t / tests-environment-fd-redirect.sh
blob8af35c7897a615e13c221cb4ad483d7b4d79e0ab
1 #! /bin/sh
2 # Copyright (C) 2011-2017 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 # Test for a behaviour of 'TESTS_ENVIRONMENT' and 'AM_TESTS_ENVIRONMENT'
18 # w.r.t. file descriptor redirections which, although undocumented,
19 # is nonetheless required by Gnulib's 'tests/init.sh' and by coreutils'
20 # testsuite.
21 # The checked behaviour is that we can portably do file descriptor
22 # redirections by placing them at the end of a {AM_,}TESTS_ENVIRONMENT
23 # definition without a following semicolon. The need to support this
24 # is detailedly motivated by coreutils bug#8846:
25 # <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=8846>
26 # and the following CC:ed thread on bug-autoconf list:
27 # <https://lists.gnu.org/archive/html/bug-autoconf/2011-06/msg00002.html>
29 . test-init.sh
31 cat >> configure.ac << 'END'
32 AC_OUTPUT
33 END
35 # Use both a shell script and a perl script as tests,
36 # for better coverage.
38 cat >foo.test <<'END'
39 #! /bin/sh
40 set -e
41 echo " " $0: foofoofoo >&8
42 echo " " $0: barbarbar >&9
43 END
45 echo "#! $PERL -w" > bar.test
46 cat >>bar.test <<'END'
47 use warnings FATAL => 'all';
48 use strict;
49 open(FD8, ">&=8") or die "$!";
50 open(FD9, ">&=9") or die "$!";
51 print FD8 " $0: 8888\n";
52 print FD9 " $0: 9999\n";
53 END
55 chmod a+x foo.test bar.test
57 $ACLOCAL
58 $AUTOCONF
60 # Korn Shells seem more vulnerable to the issue highlighted in coreutils
61 # bug#8846 than other shells are. In particular, the default Korn Shell
62 # on Debian GNU/Linux is affected by the issue. So let's try to run our
63 # test with a system Korn Shell too, if that's available.
64 bin_ksh=:
65 case $SHELL in
66 ksh|*/ksh) ;;
67 *) for d in /bin /usr/bin; do
68 test -f $d/ksh && { bin_ksh=$d/ksh; break; }
69 done;;
70 esac
72 for sh in "$SHELL" "$bin_ksh"; do
73 test "$sh" = : && continue
74 for pfx in AM_ ''; do
75 unindent > Makefile.am <<END
76 TESTS = foo.test bar.test
77 ## No trailing semicolon here, *deliberately*.
78 ${pfx}TESTS_ENVIRONMENT = 8>&1 9>&8
79 END
80 $AUTOMAKE -a
81 CONFIG_SHELL="$sh" $sh ./configure CONFIG_SHELL="$sh"
82 run_make -O VERBOSE=y check
83 grep '[ /]foo\.test: foofoofoo$' stdout
84 grep '[ /]foo\.test: barbarbar$' stdout
85 grep '[ /]bar\.test: 8888$' stdout
86 grep '[ /]bar\.test: 9999$' stdout
87 $EGREP '(foofoofoo|barbarbar|8888|9999)' foo.log && exit 1
88 : # For shells with buggy 'set -e'.
89 done
90 done