tests: cosmetic changes in t/extra-sources.sh
[platform/upstream/automake.git] / t / check-fd-redirect.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2013 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 # 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
24 cat >> configure.ac << 'END'
25 AC_OUTPUT
26 END
27
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
32
33 echo '3333' > three
34 chmod a-w three
35
36 : > foo.test
37 chmod a+x foo.test
38
39 $ACLOCAL
40 $AUTOCONF
41 $AUTOMAKE -a
42 ./configure
43
44 do_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
66 cat > foo.test <<'END'
67 #! /bin/sh
68 set -e
69
70 read FOO <&3
71 test 3333 -eq "$FOO"
72 echo "$FOO" >&4
73
74 grep '^ok ok ok$' <&7 >&5
75
76 echo " " $0: foofoofoo >&8
77 echo " " $0: barbarbar >&9
78 END
79
80 do_check
81
82 echo "#! $PERL -w" > foo.test
83 cat >> foo.test <<'END'
84 use warnings FATAL => 'all';
85 use strict;
86
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: $!";
93
94 chomp (my $FOO = <FD3>);
95 die "$FOO != 3333" if not $FOO eq "3333";
96 print FD4 "$FOO\n";
97
98 chomp ($_ = <FD7>);
99 die "$_ != 'ok ok ok'" if not $_ eq 'ok ok ok';
100 print FD5 "$_\n";
101
102 print FD8 "  $0: foofoofoo\n";
103 print FD9 "  $0: barbarbar\n";
104 END
105
106 do_check
107
108 :