855e342aaeeb0a6b976d24e7749742e84697f81a
[platform/upstream/automake.git] / tests / tests-environment-fd-redirect.test
1 #! /bin/sh
2 # Copyright (C) 2011 Free Software Foundation, Inc.
3 #
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.
8 #
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.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
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 #   <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8846>
26 # and the following CC:ed thread on bug-autoconf list:
27 #   <http://lists.gnu.org/archive/html/bug-autoconf/2011-06/msg00002.html>
28
29 am_parallel_tests=yes
30 . ./defs || Exit 1
31
32 cat >> configure.in << 'END'
33 AC_OUTPUT
34 END
35
36 # Use both a shell script and a perl script as tests,
37 # for better coverage.
38
39 cat >foo.test <<'END'
40 #! /bin/sh
41 set -e
42 echo " " $0: foofoofoo >&8
43 echo " " $0: barbarbar >&9
44 END
45
46 echo "#! $PERL -w" > bar.test
47 cat >>bar.test <<'END'
48 use warnings FATAL => 'all';
49 use strict;
50 open(FD8, ">&=8") or die "$!";
51 open(FD9, ">&=9") or die "$!";
52 print FD8 "  $0: 8888\n";
53 print FD9 "  $0: 9999\n";
54 END
55
56 chmod a+x foo.test bar.test
57
58 $ACLOCAL
59 $AUTOCONF
60
61 # Korn Shells seem more vulnerable to the issue highlighted in coreutils
62 # bug#8846 than other shells are.  In particular, the default Korn Shell
63 # on Debian GNU/Linux is affected by the issue.  So let's try to run our
64 # test with a system Korn Shell too, if that's available.
65 bin_ksh=:
66 case $SHELL in
67   ksh|*/ksh) ;;
68   *) for d in /bin /usr/bin; do
69        test -f $d/ksh && { bin_ksh=$d/ksh; break; }
70      done;;
71 esac
72
73 for sh in "$SHELL" "$bin_ksh"; do
74   test "$sh" = : && continue
75   for pfx in AM_ ''; do
76     unindent > Makefile.am <<END
77       TESTS = foo.test bar.test
78       ## No trailing semicolon here, *deliberately*.
79       ${pfx}TESTS_ENVIRONMENT = 8>&1 9>&8
80 END
81     $AUTOMAKE -a
82     CONFIG_SHELL="$sh" $sh ./configure CONFIG_SHELL="$sh"
83     VERBOSE=y $MAKE check >stdout || { cat stdout; Exit 1; }
84     cat stdout
85     grep '[ /]foo\.test: foofoofoo$' stdout
86     grep '[ /]foo\.test: barbarbar$' stdout
87     grep '[ /]bar\.test: 8888$' stdout
88     grep '[ /]bar\.test: 9999$' stdout
89     $EGREP '(foofoofoo|barbarbar|8888|9999)' foo.log && Exit 1
90     : # For shells with buggy 'set -e'.
91   done
92 done
93
94 :