1#! /bin/sh
2# Copyright (C) 2011-2021 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 <https://www.gnu.org/licenses/>.
16
17# Simple Tests support: redirection of file descriptors with
18# AM_TESTS_FD_REDIRECT.
19# See also related test 'parallel-tests-fd-redirect.sh'.
20
21# For gen-testsuite-part: ==> try-with-serial-tests <==
22. test-init.sh
23
24cat >> configure.ac << 'END'
25AC_OUTPUT
26END
27
28cat > Makefile.am <<'END'
29TESTS = foo.test
30AM_TESTS_FD_REDIRECT = 3<three 4>four 5>>five 7<&0 8>&1 9>&2
31END
32
33echo '3333' > three
34chmod a-w three
35
36: > foo.test
37chmod a+x foo.test
38
39$ACLOCAL
40$AUTOCONF
41$AUTOMAKE -a
42./configure
43
44do_check ()
45{
46  cat foo.test # For debugging.
47  echo 'this line will be removed' > four
48  echo 'this line will not be removed' > five
49  st=0; echo 'ok ok ok' | run_make -O -E -e IGNORE check || st=$?
50  cat four
51  test x"$am_serial_tests" = x"yes" || cat foo.log
52  test $st -eq 0
53  grep '[ /]foo\.test: foofoofoo$' stdout
54  grep '[ /]foo\.test: barbarbar$' stderr
55  grep 'this line' four && exit 1
56  grep '^3333$' four
57  grep '^this line will not be removed$' five
58  grep '^ok ok ok$' five
59  $EGREP '(foofoofoo|barbarbar|3333|ok ok ok|this line)' foo.log && exit 1
60  :
61}
62
63# Try using both shell script and a perl script as the test, for
64# better coverage.
65
66cat > foo.test <<'END'
67#! /bin/sh
68set -e
69
70read FOO <&3
71test 3333 -eq "$FOO"
72echo "$FOO" >&4
73
74grep '^ok ok ok$' <&7 >&5
75
76echo " " $0: foofoofoo >&8
77echo " " $0: barbarbar >&9
78END
79
80do_check
81
82echo "#! $PERL -w" > foo.test
83cat >> foo.test <<'END'
84use warnings FATAL => 'all';
85use strict;
86
87open (FD3, "<&=3") or die "opening FD3: $!";
88open (FD4, ">&=4") or die "opening FD4: $!";
89open (FD5, ">&=5") or die "opening FD5: $!";
90open (FD7, "<&=7") or die "opening FD7: $!";
91open (FD8, ">&=8") or die "opening FD8: $!";
92open (FD9, ">&=9") or die "opening FD9: $!";
93
94chomp (my $FOO = <FD3>);
95die "$FOO != 3333" if not $FOO eq "3333";
96print FD4 "$FOO\n";
97
98chomp ($_ = <FD7>);
99die "$_ != 'ok ok ok'" if not $_ eq 'ok ok ok';
100print FD5 "$_\n";
101
102print FD8 "  $0: foofoofoo\n";
103print FD9 "  $0: barbarbar\n";
104END
105
106do_check
107
108:
109