tests: avoid one tricky use of "make -e"
[platform/upstream/automake.git] / t / parallel-tests-basics.sh
1 #! /bin/sh
2 # Copyright (C) 2009-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 # Basic checks on parallel-tests support:
18 #  - console output
19 #  - log files, and what goes in 'test-suite.log'
20 #  - make clean
21 #  - dependencies between tests
22 #  - TESTS redefinition at runtime
23 #  - TEST_LOGS redefinition at runtime
24 #  - RECHECK_LOGS redefinition at runtime
25
26 . test-init.sh
27
28 cat >> configure.ac << 'END'
29 AC_OUTPUT
30 END
31
32 cat > Makefile.am << 'END'
33 TESTS = foo.test bar.test baz.test
34 XFAIL_TESTS = bar.test
35 foo.log: bar.log
36 bar.log: baz.log
37 END
38
39 # foo.test and bar.test sleep to ensure their logs are always strictly newer
40 # than the logs of their prerequisites, for HP-UX make.  The quoting pleases
41 # maintainer-check.
42 cat > foo.test <<'END'
43 #! /bin/sh
44 echo "this is $0"
45 sleep '1'
46 exit 0
47 END
48 cat > bar.test <<'END'
49 #! /bin/sh
50 echo "this is $0"
51 sleep '1'
52 exit 99
53 END
54 cat > baz.test <<'END'
55 #! /bin/sh
56 echo "this is $0"
57 exit 1
58 END
59 chmod a+x foo.test bar.test baz.test
60
61 $ACLOCAL
62 $AUTOCONF
63 $AUTOMAKE -a
64
65 ./configure
66
67 $MAKE check >stdout && { cat stdout; exit 1; }
68 cat stdout
69 count_test_results total=3 pass=1 fail=1 skip=0 xfail=0 xpass=0 error=1
70 test -f test-suite.log
71 cat test-suite.log
72 test $(grep -c '^FAIL:' test-suite.log) -eq 1
73 test $(grep -c '^ERROR:' test-suite.log) -eq 1
74 $EGREP '^(X?PASS|XFAIL|SKIP)' test-suite.log && exit 1
75 test -f baz.log
76 test -f bar.log
77 test -f foo.log
78
79 $MAKE clean
80 test ! -e baz.log
81 test ! -e bar.log
82 test ! -e foo.log
83 test ! -e test-suite.log
84
85 # Check dependencies: baz.test needs to run before bar.test,
86 # but foo.test is not needed.
87 # Note that this usage has a problem: the summary will only
88 # take bar.log into account, because the $(TEST_SUITE_LOG) rule
89 # does not "see" baz.log.  Hmm.
90 env TESTS='bar.test' $MAKE -e check >stdout && { cat stdout; exit 1; }
91 cat stdout
92 grep '^FAIL: baz\.test$' stdout
93 grep '^ERROR: bar\.test$' stdout
94
95 test -f baz.log
96 test -f bar.log
97 test ! -e foo.log
98 test -f test-suite.log
99
100 # Upon a lazy rerun, foo.test should be run, but the others shouldn't.
101 # Note that the lazy rerun still exits with a failure, due to the previous
102 # test failures.
103 # Note that the previous test and this one taken together expose the timing
104 # issue that requires the check-TESTS rule to always remove TEST_SUITE_LOG
105 # before running the tests lazily.
106 env RECHECK_LOGS= $MAKE -e check > stdout && { cat stdout; exit 1; }
107 cat stdout
108 test -f foo.log
109 grep '^PASS: foo\.test$' stdout
110 grep bar.test stdout && exit 1
111 grep baz.test stdout && exit 1
112 grep '^# PASS: *1$' stdout
113 grep '^# FAIL: *1$' stdout
114 grep '^# ERROR: *1$' stdout
115
116 # Now, explicitly retry with all test logs already updated, and ensure
117 # that the summary is still displayed.
118 env RECHECK_LOGS= $MAKE -e check > stdout && { cat stdout; exit 1; }
119 cat stdout
120 grep foo.test stdout && exit 1
121 grep bar.test stdout && exit 1
122 grep baz.test stdout && exit 1
123 grep '^# PASS: *1$' stdout
124 grep '^# FAIL: *1$' stdout
125 grep '^# ERROR: *1$' stdout
126
127 # Lazily rerunning only foo should only rerun this one test.
128 env RECHECK_LOGS=foo.log $MAKE -e check > stdout && { cat stdout; exit 1; }
129 cat stdout
130 grep foo.test stdout
131 grep bar.test stdout && exit 1
132 grep baz.test stdout && exit 1
133 grep '^# PASS: *1$' stdout
134 grep '^# FAIL: *1$' stdout
135 grep '^# ERROR: *1$' stdout
136
137 $MAKE clean
138 env TEST_LOGS=baz.log $MAKE -e check > stdout && { cat stdout; exit 1; }
139 cat stdout
140 grep foo.test stdout && exit 1
141 grep bar.test stdout && exit 1
142 grep baz.test stdout
143
144 $MAKE clean
145 env TESTS=baz.test $MAKE -e check > stdout && { cat stdout; exit 1; }
146 cat stdout
147 grep foo.test stdout && exit 1
148 grep bar.test stdout && exit 1
149 grep baz.test stdout
150
151 :