tests: Let 'ltorder.sh' run successfully with Guix dynamic loader
[automake.git] / t / check-fd-redirect.sh
blobeaf2a2a0afb86d1947a64f80f5cc8ae91edecf0f
1 #! /bin/sh
2 # Copyright (C) 2011-2018 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 # Simple Tests support: redirection of file descriptors with
18 # AM_TESTS_FD_REDIRECT.
19 # See also related test 'parallel-tests-fd-redirect.sh'.
21 # For gen-testsuite-part: ==> try-with-serial-tests <==
22 . test-init.sh
24 cat >> configure.ac << 'END'
25 AC_OUTPUT
26 END
28 cat > Makefile.am <<'END'
29 TESTS = foo.test
30 AM_TESTS_FD_REDIRECT = 3<three 4>four 5>>five 7<&0 8>&1 9>&2
31 END
33 echo '3333' > three
34 chmod a-w three
36 : > foo.test
37 chmod a+x foo.test
39 $ACLOCAL
40 $AUTOCONF
41 $AUTOMAKE -a
42 ./configure
44 do_check ()
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
63 # Try using both shell script and a perl script as the test, for
64 # better coverage.
66 cat > foo.test <<'END'
67 #! /bin/sh
68 set -e
70 read FOO <&3
71 test 3333 -eq "$FOO"
72 echo "$FOO" >&4
74 grep '^ok ok ok$' <&7 >&5
76 echo " " $0: foofoofoo >&8
77 echo " " $0: barbarbar >&9
78 END
80 do_check
82 echo "#! $PERL -w" > foo.test
83 cat >> foo.test <<'END'
84 use warnings FATAL => 'all';
85 use strict;
87 open (FD3, "<&=3") or die "opening FD3: $!";
88 open (FD4, ">&=4") or die "opening FD4: $!";
89 open (FD5, ">&=5") or die "opening FD5: $!";
90 open (FD7, "<&=7") or die "opening FD7: $!";
91 open (FD8, ">&=8") or die "opening FD8: $!";
92 open (FD9, ">&=9") or die "opening FD9: $!";
94 chomp (my $FOO = <FD3>);
95 die "$FOO != 3333" if not $FOO eq "3333";
96 print FD4 "$FOO\n";
98 chomp ($_ = <FD7>);
99 die "$_ != 'ok ok ok'" if not $_ eq 'ok ok ok';
100 print FD5 "$_\n";
102 print FD8 " $0: foofoofoo\n";
103 print FD9 " $0: barbarbar\n";
106 do_check