Merge branch master into maint after 1.12 release
[platform/upstream/automake.git] / t / test-driver-custom-multitest-recheck2.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 # Custom test drivers: try the "recheck" functionality with test protocols
18 # that allow multiple testcases in a single test script.  In particular,
19 # check that this still works when we override $(TESTS) and $(TEST_LOGS)
20 # at make runtime.
21 # See also related tests 'test-driver-custom-multitest-recheck.test' and
22 # 'parallel-tests-recheck-override.test'.
23
24 am_parallel_tests=yes
25 . ./defs || Exit 1
26
27 cp "$am_testauxdir"/trivial-test-driver . \
28   || fatal_ "failed to fetch auxiliary script trivial-test-driver"
29
30 cat >> configure.ac << 'END'
31 AC_OUTPUT
32 END
33
34 cat > Makefile.am << 'END'
35 TEST_LOG_DRIVER = $(SHELL) $(srcdir)/trivial-test-driver
36 TESTS = a.test b.test c.test
37 END
38
39 cat > a.test << 'END'
40 #! /bin/sh
41 echo PASS: 1
42 echo PASS: 2
43 : > a.run
44 END
45
46 cat > b.test << 'END'
47 #! /bin/sh
48 echo SKIP: b0
49 if test -f b.ok; then
50   echo XFAIL: b1
51 else
52   echo FAIL: b2
53 fi
54 : > b.run
55 END
56
57 cat > c.test << 'END'
58 #! /bin/sh
59 if test -f c.err; then
60   echo ERROR: xxx
61 elif test -f c.ok; then
62   echo PASS: ok
63 else
64   echo XPASS: xp
65 fi
66 : > c.run
67 END
68
69 chmod a+x *.test
70
71 $ACLOCAL
72 $AUTOCONF
73 $AUTOMAKE
74
75 for vpath in : false; do
76   if $vpath; then
77     mkdir build
78     cd build
79     srcdir=..
80   else
81     srcdir=.
82   fi
83
84   $srcdir/configure
85
86   : Run the tests for the first time.
87   $MAKE check >stdout && { cat stdout; Exit 1; }
88   cat stdout
89   # All the test scripts should have run.
90   test -f a.run
91   test -f b.run
92   test -f c.run
93   count_test_results total=5 pass=2 fail=1 xpass=1 xfail=0 skip=1 error=0
94
95   rm -f *.run
96
97   : An empty '$(TESTS)' or '$(TEST_LOGS)' means that no test should be run.
98   for var in TESTS TEST_LOGS; do
99     env "$var=" $MAKE -e recheck >stdout || { cat stdout; Exit 1; }
100     cat stdout
101     count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
102     test ! -r a.run
103     test ! -r b.run
104     test ! -r c.run
105   done
106   unset var
107
108   : a.test was successful the first time, no need to re-run it.
109   env TESTS=a.test $MAKE -e recheck >stdout \
110     || { cat stdout; Exit 1; }
111   cat stdout
112   count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
113   test ! -r a.run
114   test ! -r b.run
115   test ! -r c.run
116
117   : b.test failed, it should be re-run.  And make it pass this time.
118   echo OK > b.ok
119   TEST_LOGS=b.log $MAKE -e recheck >stdout \
120     || { cat stdout; Exit 1; }
121   cat stdout
122   test ! -r a.run
123   test -f b.run
124   test ! -r c.run
125   count_test_results total=2 pass=0 fail=0 xpass=0 xfail=1 skip=1 error=0
126
127   rm -f *.run
128
129   : No need to re-run a.test or b.test anymore.
130   TEST_LOGS=b.log $MAKE -e recheck >stdout \
131     || { cat stdout; Exit 1; }
132   cat stdout
133   count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
134   test ! -r a.run
135   test ! -r b.run
136   test ! -r c.run
137   TESTS='a.test b.test' $MAKE -e recheck >stdout \
138     || { cat stdout; Exit 1; }
139   cat stdout
140   count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
141   test ! -r a.run
142   test ! -r b.run
143   test ! -r c.run
144
145   : No need to re-run a.test anymore, but c.test should be rerun,
146   : as it contained an XPASS.  And this time, make it fail with
147   : an hard error.
148   # Use 'echo' here, since Solaris 10 /bin/sh would try to optimize
149   # a ':' away after the first iteration, even if it is redirected.
150   echo dummy > c.err
151   env TEST_LOGS='a.log c.log' $MAKE -e recheck >stdout \
152     && { cat stdout; Exit 1; }
153   cat stdout
154   count_test_results total=1 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=1
155   test ! -r a.run
156   test ! -r b.run
157   test -f c.run
158
159   rm -f *.run *.err
160
161   : c.test contained and hard error the last time, so it should be re-run.
162   : This time, make it pass
163   # Use 'echo', not ':'; see comments above for why.
164   echo dummy > c.ok
165   env TESTS='c.test a.test' $MAKE -e recheck >stdout \
166     || { cat stdout; Exit 1; }
167   cat stdout
168   count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
169   test ! -r a.run
170   test ! -r b.run
171   test -f c.run
172
173   rm -f *.run *.err *.ok
174
175   : Nothing should be rerun anymore, as all tests have been eventually
176   : successful.
177   $MAKE recheck >stdout || { cat stdout; Exit 1; }
178   cat stdout
179   count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
180   test ! -r a.run
181   test ! -r b.run
182   test ! -r c.run
183
184   cd $srcdir
185
186 done
187
188 :