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