Merge branch 'maint'
[platform/upstream/automake.git] / t / test-driver-custom-multitest-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 # Custom test drivers: try the "recheck" functionality with test protocols
18 # that allow multiple testcases in a single test script.  This test not
19 # only checks implementation details in Automake's custom test drivers
20 # support, but also serves as a "usability test" for our APIs.
21 # See also related tests 'test-driver-custom-multitest-recheck2.test'
22 # and 'parallel-tests-recheck-override.test'.
23 # Keep in sync with 'tap-recheck.test'.
24
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 d.test
37 END
38
39 cat > a.test << 'END'
40 #! /bin/sh
41 echo PASS: aa
42 echo PASS: AA
43 : > a.run
44 END
45
46 cat > b.test << 'END'
47 #! /bin/sh
48 echo PASS:
49 if test -f b.ok; then
50   echo PASS:
51 else
52   echo ERROR:
53 fi
54 : > b.run
55 END
56
57 cat > c.test << 'END'
58 #! /bin/sh
59 if test -f c.pass; then
60   echo PASS: c0
61 else
62   echo FAIL: c0
63 fi
64 if test -f c.xfail; then
65   echo XFAIL: c1
66 else
67   echo XPASS: c1
68 fi
69 echo XFAIL: c2
70 : > c.run
71 END
72
73 cat > d.test << 'END'
74 #! /bin/sh
75 echo SKIP: who cares ...
76 (. ./d.extra) || echo FAIL: d.extra failed
77 : > d.run
78 END
79
80 chmod a+x *.test
81
82 $ACLOCAL
83 $AUTOCONF
84 $AUTOMAKE
85
86 do_recheck ()
87 {
88   case $* in
89     --fail) on_bad_rc='&&';;
90     --pass) on_bad_rc='||';;
91          *) fatal_ "invalid usage of function 'do_recheck'";;
92   esac
93   rm -f *.run
94   eval "\$MAKE recheck >stdout $on_bad_rc { cat stdout; ls -l; Exit 1; }; :"
95   cat stdout; ls -l
96 }
97
98 for vpath in : false; do
99   if $vpath; then
100     mkdir build
101     cd build
102     srcdir=..
103   else
104     srcdir=.
105   fi
106
107   $srcdir/configure
108
109   : A "make recheck" in a clean tree should run no tests.
110   do_recheck --pass
111   cat test-suite.log
112   test ! -r a.run
113   test ! -r a.log
114   test ! -r b.run
115   test ! -r b.log
116   test ! -r c.run
117   test ! -r c.log
118   test ! -r d.run
119   test ! -r d.log
120   count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
121
122   : Run the tests for the first time.
123   $MAKE check >stdout && { cat stdout; Exit 1; }
124   cat stdout
125   ls -l
126   # All the test scripts should have run.
127   test -f a.run
128   test -f b.run
129   test -f c.run
130   test -f d.run
131   count_test_results total=9 pass=3 fail=2 xpass=1 xfail=1 skip=1 error=1
132
133   : Let us make b.test pass.
134   echo OK > b.ok
135   do_recheck --fail
136   # a.test has been successful the first time, so no need to re-run it.
137   # Similar considerations apply to similar checks, below.
138   test ! -r a.run
139   test -f b.run
140   test -f c.run
141   test -f d.run
142   count_test_results total=7 pass=2 fail=2 xpass=1 xfail=1 skip=1 error=0
143
144   : Let us make the first part of c.test pass.
145   echo OK > c.pass
146   do_recheck --fail
147   test ! -r a.run
148   test ! -r b.run
149   test -f c.run
150   test -f d.run
151   count_test_results total=5 pass=1 fail=1 xpass=1 xfail=1 skip=1 error=0
152
153   : Let us make also the second part of c.test pass.
154   echo KO > c.xfail
155   do_recheck --fail
156   test ! -r a.run
157   test ! -r b.run
158   test -f c.run
159   test -f d.run
160   count_test_results total=5 pass=1 fail=1 xpass=0 xfail=2 skip=1 error=0
161
162   : Nothing changed, so only d.test should be run.
163   for i in 1 2; do
164     do_recheck --fail
165     test ! -r a.run
166     test ! -r b.run
167     test ! -r c.run
168     test -f d.run
169     count_test_results total=2 pass=0 fail=1 xpass=0 xfail=0 skip=1 error=0
170   done
171
172   : Let us make d.test run more testcases, and experience _more_ failures.
173   unindent > d.extra <<'END'
174     echo SKIP: s
175     echo FAIL: f 1
176     echo PASS: p 1
177     echo FAIL: f 2
178     echo XPASS: xp
179     echo FAIL: f 3
180     echo FAIL: f 4
181     echo ERROR: e 1
182     echo PASS: p 2
183     echo ERROR: e 2
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 : > d.extra
194   do_recheck --pass
195   test ! -r a.run
196   test ! -r b.run
197   test ! -r c.run
198   test -f d.run
199   count_test_results total=1 pass=0 fail=0 xpass=0 xfail=0 skip=1 error=0
200
201   : All tests have been successful or skipped, nothing should be re-run.
202   do_recheck --pass
203   test ! -r a.run
204   test ! -r b.run
205   test ! -r c.run
206   test ! -r d.run
207   count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
208
209   cd $srcdir
210
211 done
212
213 :