tests: use 'parallel-tests' Automake option by default
[platform/upstream/automake.git] / t / tap-recheck.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 # Test the 'recheck' target for TAP test protocol.
18 # Keep in sync with 'test-driver-custom-multitest-recheck.test'.
19
20 . ./defs || Exit 1
21
22 fetch_tap_driver
23
24 cat >> configure.ac <<END
25 AC_OUTPUT
26 END
27
28 cat > Makefile.am << 'END'
29 TEST_LOG_DRIVER = $(srcdir)/tap-driver
30 TESTS = a.test b.test c.test d.test
31 END
32
33 cat > a.test << 'END'
34 #! /bin/sh
35 echo 1..2
36 echo ok 1
37 echo ok 2
38 : > a.run
39 END
40
41 cat > b.test << 'END'
42 #! /bin/sh
43 : > b.run
44 echo 1..2
45 echo ok 1
46 if test -f b.ok; then
47   echo ok 2
48 else
49   echo 'Bail out!'
50 fi
51 END
52
53 cat > c.test << 'END'
54 #! /bin/sh
55 echo 1..3
56 if test -f c.pass; then
57   echo 'ok - c is ok :-)'
58 else
59   echo 'not ok - c is ko :-('
60 fi
61 if test -f c.xfail; then
62   echo 'not ok 2 # TODO'
63 else
64   echo 'ok 2 # TODO'
65 fi
66 echo 'not ok 3 - blah blah # TODO need better diagnostic'
67 : > c.run
68 END
69
70 cat > d.test << 'END'
71 #! /bin/sh
72 test -f ./d.count && . ./d.count
73 echo 1..${test_count-2}
74 echo ok 1 '# SKIP: who cares ...'
75 (. ./d.extra) || echo 'not ok 2 - d.extra failed'
76 : > d.run
77 END
78
79 chmod a+x *.test
80
81 $ACLOCAL
82 $AUTOCONF
83 $AUTOMAKE
84
85 do_recheck ()
86 {
87   case $* in
88     --fail) on_bad_rc='&&';;
89     --pass) on_bad_rc='||';;
90          *) fatal_ "invalid usage of function 'do_recheck'";;
91   esac
92   rm -f *.run
93   eval "\$MAKE recheck >stdout $on_bad_rc { cat stdout; ls -l; Exit 1; }; :"
94   cat stdout; ls -l
95 }
96
97 for vpath in : false; do
98   if $vpath; then
99     mkdir build
100     cd build
101     srcdir=..
102   else
103     srcdir=.
104   fi
105
106   $srcdir/configure
107
108   : A "make recheck" in a clean tree should run no tests.
109   do_recheck --pass
110   cat test-suite.log
111   test ! -r a.run
112   test ! -r a.log
113   test ! -r b.run
114   test ! -r b.log
115   test ! -r c.run
116   test ! -r c.log
117   test ! -r d.run
118   test ! -r d.log
119   count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
120
121   : Run the tests for the first time.
122   $MAKE check >stdout && { cat stdout; Exit 1; }
123   cat stdout
124   ls -l
125   # All the test scripts should have run.
126   test -f a.run
127   test -f b.run
128   test -f c.run
129   test -f d.run
130   count_test_results total=9 pass=3 fail=2 xpass=1 xfail=1 skip=1 error=1
131
132   : Let us make b.test pass.
133   echo OK > b.ok
134   do_recheck --fail
135   # a.test has been successful the first time, so no need to re-run it.
136   # Similar considerations apply to similar checks, below.
137   test ! -r a.run
138   test -f b.run
139   test -f c.run
140   test -f d.run
141   count_test_results total=7 pass=2 fail=2 xpass=1 xfail=1 skip=1 error=0
142
143   : Let us make the first part of c.test pass.
144   echo OK > c.pass
145   do_recheck --fail
146   test ! -r a.run
147   test ! -r b.run
148   test -f c.run
149   test -f d.run
150   count_test_results total=5 pass=1 fail=1 xpass=1 xfail=1 skip=1 error=0
151
152   : Let us make also the second part of c.test pass.
153   echo KO > c.xfail
154   do_recheck --fail
155   test ! -r a.run
156   test ! -r b.run
157   test -f c.run
158   test -f d.run
159   count_test_results total=5 pass=1 fail=1 xpass=0 xfail=2 skip=1 error=0
160
161   : Nothing changed, so only d.test should be run.
162   for i in 1 2; do
163     do_recheck --fail
164     test ! -r a.run
165     test ! -r b.run
166     test ! -r c.run
167     test -f d.run
168     count_test_results total=2 pass=0 fail=1 xpass=0 xfail=0 skip=1 error=0
169   done
170
171   : Let us make d.test run more testcases, and experience _more_ failures.
172   echo 'test_count=9' > d.count
173   unindent > d.extra <<'END'
174     echo 'ok # SKIP s'
175     echo 'not ok - f 1'
176     echo 'ok - p 1'
177     echo 'not ok - f 2'
178     echo 'ok # TODO xp'
179     echo 'not ok - f 3'
180     echo 'not ok - f 4'
181     echo 'ok - p 2'
182     echo 'ok' # Extra test.
183     echo 'Bail out!'
184 END
185   do_recheck --fail
186   test ! -r a.run
187   test ! -r b.run
188   test ! -r c.run
189   test -f d.run
190   count_test_results total=11 pass=2 fail=4 xpass=1 xfail=0 skip=2 error=2
191
192   : Let us finally make d.test pass.
193   echo 'test_count=1' > d.count
194   echo : > d.extra
195   do_recheck --pass
196   test ! -r a.run
197   test ! -r b.run
198   test ! -r c.run
199   test -f d.run
200   count_test_results total=1 pass=0 fail=0 xpass=0 xfail=0 skip=1 error=0
201
202   : All tests have been successful or skipped, nothing should be re-run.
203   do_recheck --pass
204   test ! -r a.run
205   test ! -r b.run
206   test ! -r c.run
207   test ! -r d.run
208   count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
209
210   cd $srcdir
211
212 done
213
214 :