test harness: improve catching of usage errors in script 'test-driver'
[platform/upstream/automake.git] / t / test-driver-custom-multitest.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: check that we can easily support 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
22 . test-init.sh
23
24 cp "$am_testaux_srcdir"/trivial-test-driver . \
25   || fatal_ "failed to fetch auxiliary script trivial-test-driver"
26
27 cat >> configure.ac << 'END'
28 AC_OUTPUT
29 END
30
31 cat > Makefile.am << 'END'
32 TEST_EXTENSIONS = .t
33 T_LOG_DRIVER = $(SHELL) $(srcdir)/trivial-test-driver
34
35 TESTS = \
36   pass.t \
37   fail.t \
38   fail2.t \
39   pass-fail.t \
40   pass4-skip.t \
41   pass3-skip2-xfail.t \
42   pass-xpass-fail-xfail-skip-error.t
43 END
44
45 cat > pass.t << 'END'
46 echo %% pass %%
47 echo PASS: pass
48 END
49
50 cat > fail.t << 'END'
51 echo %% fail %%
52 echo FAIL: fail
53 END
54
55 cat > fail2.t << 'END'
56 echo %% fail2 %%
57 echo FAIL: stdout >&1
58 echo FAIL: stderr >&2
59 echo :PASS: this should be ignored
60 END
61
62 cat > pass-fail.t << 'END'
63 echo %% pass-fail %%
64 echo 'FAIL: this fails :-('
65 echo 'some randome message'
66 echo 'some randome warning' >&2
67 echo 'PASS: this passes :-)'
68 echo 'INFO: blah'
69 echo 'WARNING: blah blah' >&2
70 END
71
72 cat > pass4-skip.t << 'END'
73 echo %% pass4-skip %%
74 echo PASS: on stdout >&1
75 echo PASS: on stderr >&2
76 echo PASS: 3
77 echo PASS: 4
78 echo SKIP: 1
79 echo this FAIL: should be ignored
80 echo FAIL as should this
81 exit 99
82 END
83
84 cat > pass3-skip2-xfail.t << 'END'
85 echo %% pass4-skip2-xfail %%
86 echo 'PASS: -v'
87 echo 'PASS: --verbose'
88 echo 'SKIP: Oops, unsupported system.'
89 echo 'PASS: -#-#-#-'
90 cp || echo "SKIP: cp cannot read users' mind" >&2
91 mv || echo "XFAIL: mv cannot read users' mind yet"
92 exit 127
93 END
94
95 cat > pass-xpass-fail-xfail-skip-error.t << 'END'
96 echo PASS:
97 echo FAIL:
98 echo XFAIL:
99 echo XPASS:
100 echo SKIP:
101 echo ERROR:
102 echo %% pass-xpass-fail-xfail-skip-error %%
103 END
104
105 chmod a+x *.t
106
107 $ACLOCAL
108 $AUTOCONF
109 $AUTOMAKE
110
111 for vpath in : false; do
112   if $vpath; then
113     mkdir build
114     cd build
115     srcdir=..
116   else
117     srcdir=.
118   fi
119
120   $srcdir/configure
121
122   run_make -O -e FAIL check || { cat test-suite.log; exit 1; }
123   cat test-suite.log
124   # Couple of sanity checks.  These might need to be updated if the
125   # 'trivial-test-driver' script is changed.
126   $FGREP INVALID.NAME stdout test-suite.log && exit 1
127   test -f BAD.LOG && exit 1
128   test -f BAD.TRS && exit 1
129   # These log files must all have been created by the testsuite.
130   cat pass.log
131   cat fail.log
132   cat fail2.log
133   cat pass-fail.log
134   cat pass4-skip.log
135   cat pass3-skip2-xfail.log
136   cat pass-xpass-fail-xfail-skip-error.log
137
138   count_test_results total=23 pass=10 fail=5 skip=4 xfail=2 xpass=1 error=1
139
140   tst=pass-xpass-fail-xfail-skip-error
141   grep  "^PASS: $tst\.t, testcase 1" stdout
142   grep  "^FAIL: $tst\.t, testcase 2" stdout
143   grep "^XFAIL: $tst\.t, testcase 3" stdout
144   grep "^XPASS: $tst\.t, testcase 4" stdout
145   grep  "^SKIP: $tst\.t, testcase 5" stdout
146   grep "^ERROR: $tst\.t, testcase 6" stdout
147
148   # Check that the content of, and only of, the test logs with at least
149   # one failing test case has been copied into 'test-suite.log'.  Note
150   # that test logs containing skipped or xfailed test cases are *not*
151   # copied into 'test-suite.log' -- a behaviour that deliberately differs
152   # from the one of the built-in Automake test drivers.
153   grep '%%' test-suite.log # For debugging.
154   grep '%% fail %%' test-suite.log
155   grep '%% fail2 %%' test-suite.log
156   grep '%% pass-fail %%' test-suite.log
157   grep '%% pass-xpass-fail-xfail-skip-error %%' test-suite.log
158   test $(grep -c '%% ' test-suite.log) -eq 4
159
160   run_make -O TESTS='pass.t pass3-skip2-xfail.t' check
161   cat test-suite.log
162   count_test_results total=7 pass=4 fail=0 skip=2 xfail=1 xpass=0 error=0
163
164   cd $srcdir
165
166 done
167
168 :