tests: expose automake bug#13940
[platform/upstream/automake.git] / t / tap-unplanned.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 # TAP support:
18 #  - unplanned tests are properly reported as errors
19
20 . test-init.sh
21
22 . tap-setup.sh
23
24 cat > all.test <<END
25 1..1
26 ok 1
27 ok 2
28 END
29 run_make -O -e FAIL check
30 count_test_results total=3 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=2
31 grep '^ERROR: all\.test - too many tests run (expected 1, got 2)$' stdout
32 grep '^ERROR: all\.test 2 # UNPLANNED$' stdout
33
34 cat > all.test <<END
35 1..2
36 ok 1
37 ok 2
38 ok 3
39 END
40 run_make -O -e FAIL check
41 count_test_results total=4 pass=2 fail=0 xpass=0 xfail=0 skip=0 error=2
42 grep '^ERROR: all\.test - too many tests run (expected 2, got 3)$' stdout
43 grep '^ERROR: all\.test 3 # UNPLANNED$' stdout
44
45 # Interaction with XFAIL_TESTS.
46 cat > all.test <<END
47 1..2
48 not ok 1
49 ok 2 # SKIP
50 ok 3
51 not ok 4
52 ok 5 # SKIP
53 END
54 run_make -O -e FAIL XFAIL_TESTS=all.test check
55 count_test_results total=6 pass=0 fail=0 xpass=0 xfail=1 skip=1 error=4
56 grep '^ERROR: all\.test - too many tests run (expected 2, got 5)$' stdout
57 grep '^ERROR: all\.test 3 # UNPLANNED$' stdout
58 grep '^ERROR: all\.test 4 # UNPLANNED$' stdout
59 grep '^ERROR: all\.test 5 # UNPLANNED$' stdout
60
61 cat > all.test <<END
62 1..1
63 ok 1
64
65 ok
66 ok 3
67 ok foo
68 ok 5 - bar bar
69
70 not ok
71 not ok 7
72 not ok foo
73 not ok 9 - bar bar
74
75 ok # TODO
76 ok 11 # TODO
77 ok foo # TODO
78 ok 13 - bar bar # TODO
79
80 not ok # TODO
81 not ok 15 # TODO
82 not ok foo # TODO
83 not ok 17 - bar bar # TODO
84
85 ok # SKIP
86 ok 19 # SKIP
87 ok foo # SKIP
88 ok 21 - bar bar # SKIP
89 END
90
91 cat > t <<END
92
93 2
94 3
95 4 foo
96 5 - bar bar
97
98 6
99 7
100 8 foo
101 9 - bar bar
102
103 10
104 11
105 12 foo
106 13 - bar bar
107
108 14
109 15
110 16 foo
111 17 - bar bar
112
113 18
114 19
115 20 foo
116 21 - bar bar
117
118 END
119
120 run_make -O -e FAIL check
121 count_test_results total=22 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=21
122
123 echo 'PASS: all.test 1' > exp
124 sed -e '/^$/d' -e 's/.*/ERROR: all.test & # UNPLANNED/' t >> exp
125 echo 'ERROR: all.test - too many tests run (expected 1, got 21)' >> exp
126
127 $FGREP ': all.test' stdout > got
128
129 cat exp
130 cat got
131 diff exp got
132
133 # Note that, if the TAP input has a trailing plan, it is not possible
134 # to flag unplanned tests as such, since we do not know they're unplanned
135 # until the plan is reached; still, we should give at least an error
136 # message about the unmatched number of tests once we've got the plan.
137
138 for x in 'ok' 'ok 3' 'not ok' 'not ok # TODO' 'ok # TODO' 'ok # SKIP'; do
139   unindent > all.test <<END
140     ok 1
141     ok 2 # SKIP
142     $x
143     1..2
144 END
145   run_make -O -e FAIL check
146   test $($FGREP -c ': all.test' stdout) -eq 4
147   $EGREP '^PASS: all\.test 1($| )' stdout
148   $EGREP '^SKIP: all\.test 2($| )' stdout
149   $EGREP ': all\.test 3($| )' stdout
150   grep '^ERROR: all\.test - too many tests run (expected 2, got 3)$' stdout
151 done
152
153 :