Merge branch 'simplify-exit-trap-workaround' into maint
[platform/upstream/automake.git] / t / parallel-tests-dry-run-2.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2012 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 # Check parallel-tests interactions with "make -n".
18 # See also sister test 'parallel-tests-dry-run-1.test'.
19
20 . ./defs || exit 1
21
22 cat >> configure.ac << 'END'
23 AC_OUTPUT
24 END
25
26 cat > Makefile.am <<'END'
27 TESTS = foo.test bar.test
28 TEST_LOG_COMPILER = $(SHELL)
29 END
30
31 $ACLOCAL
32 $AUTOMAKE -a
33 $AUTOCONF
34
35 ./configure
36
37 make_n_ ()
38 {
39   st=0
40   $MAKE -n "$@" >output 2>&1 || { cat output; ls -l; exit 1; }
41   cat output
42   # Look out for possible errors from common tools used by recipes.
43   $EGREP -i ' (exist|permission|denied|no .*(such|file))' output && exit 1
44   $EGREP '(mv|cp|rm|cat|grep|sed|awk): ' output && exit 1
45   :
46 }
47
48 : > output
49
50 files='foo.log bar.log foo.trs bar.trs'
51
52 for target in check recheck test-suite.log; do
53   test ! -f foo.log
54   test ! -f foo.trs
55   test ! -f bar.log
56   test ! -f bar.trs
57   test ! -f test-suite.log
58 done
59
60 echo 'exit 0' > foo.test
61 echo 'exit 1' > bar.test
62
63 $MAKE check && exit 1
64
65 chmod a-w .
66
67 make_n_ clean
68 test -f foo.log
69 test -f foo.trs
70 test -f foo.log
71 test -f bar.trs
72
73 cat > foo.test <<END
74 echo this is bad
75 exit 1
76 END
77 echo 'exit 0' > bar.test
78
79 for target in check recheck test-suite.log; do
80   make_n_ $target
81   grep '^:test-result: *FAIL' bar.trs
82   grep 'this is bad' foo.log test-suite.log && exit 1
83   : For shells with busted 'set -e'.
84 done
85
86 chmod a-rw $files
87 if test -r foo.log; then
88   : You can still read unreadable files!  Skip these checks.
89 else
90   for target in check recheck test-suite.log; do
91     make_n_ $target
92     for f in $files; do
93       test -f $f && test ! -r $f || exit 1
94     done
95   done
96 fi
97 chmod u+r $files
98
99 chmod u+w .
100 rm -f foo.log bar.trs
101 chmod a-w .
102 for target in check recheck test-suite.log $files; do
103   make_n_ $target
104   test ! -f foo.log
105   test -f foo.trs
106   test ! -f bar.trs
107   test -f bar.log
108 done
109
110 :