test harness: improve catching of usage errors in script 'test-driver'
[platform/upstream/automake.git] / t / tap-fancy.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: some unusual forms for valid TAP input.
18 # See also related test 'tap-fancy2.sh'.
19
20 . test-init.sh
21
22 . tap-setup.sh
23
24 #
25 # From manpage Test::Harness::TAP(3):
26 #
27 #   Lines written to standard output matching /^(not )?ok\b/ must be
28 #   interpreted as test lines. All other lines must not be considered
29 #   test output.
30 #
31 # Unfortunately, the exact format of TODO and SKIP directives is not as
32 # clearly described in that manpage; but a simple reverse-engineering of
33 # the prove(1) utility shows that it is probably given by the perl regex
34 # /#\s*(TODO|SKIP)\b/.
35 #
36
37 cat > all.test <<END
38 1..21
39
40 ok? a question
41 not ok? a question
42
43 ok+plus
44 not ok+plus
45
46 ok-minus
47 not ok-minus
48
49 ok#55
50 not ok#55
51
52 ok${tab}  ${tab}9
53 ok ${tab}${tab}          10
54
55 not ok${tab}  ${tab}11
56 not ok ${tab}${tab}          12
57
58 ok# SKIP
59 ok${tab}#SKIP--who cares?
60 ok?#SKIP!
61 ok!#SKIP?
62
63 not ok# TODO
64 not ok${tab}#TODO--who cares?
65 not ok?#TODO!
66 not ok!#TODO?
67
68 ok~#TODO
69 END
70
71 run_make -O -e FAIL check
72 count_test_results total=21 pass=6 fail=6 xfail=4 xpass=1 skip=4 error=0
73
74 #
75 # "Weird" characters support.
76 #
77
78 # The "#" character might cause confusion w.r.t. TAP directives (TODO,
79 # SKIP), so we don't attempt to use it.
80 weirdchars=\''"$!&()[]<>;^?*/@%=,.:'
81
82 cat > all.test <<END
83 1..6
84 ok $weirdchars
85 not ok $weirdchars
86 ok $weirdchars # TODO
87 not ok $weirdchars # TODO
88 ok $weirdchars # SKIP
89 Bail out! $weirdchars
90 END
91
92 run_make -O -e FAIL check
93 count_test_results total=6 pass=1 fail=1 xfail=1 xpass=1 skip=1 error=1
94 $FGREP "PASS: all.test 1 $weirdchars" stdout
95 $FGREP "FAIL: all.test 2 $weirdchars" stdout
96 $FGREP "XPASS: all.test 3 $weirdchars" stdout
97 $FGREP "XFAIL: all.test 4 $weirdchars" stdout
98 $FGREP "SKIP: all.test 5 $weirdchars" stdout
99 $FGREP "ERROR: all.test - Bail out! $weirdchars" stdout
100
101 #
102 # Trailing backslashes does not confuse the parser.
103 #
104
105 bs='\'
106
107 cat > all.test <<END
108 1..6
109 ok $bs
110 not ok $bs
111 ok # TODO $bs
112 not ok # TODO $bs
113 ok # SKIP $bs
114 Bail out! $bs
115 END
116
117 run_make -O -e FAIL check
118 count_test_results total=6 pass=1 fail=1 xfail=1 xpass=1 skip=1 error=1
119
120 grep '^PASS: all\.test 1 \\$' stdout
121 grep '^FAIL: all\.test 2 \\$' stdout
122 grep '^XPASS: all\.test 3 # TODO \\$' stdout
123 grep '^XFAIL: all\.test 4 # TODO \\$' stdout
124 grep '^SKIP: all\.test 5 # SKIP \\$' stdout
125 grep '^ERROR: all\.test - Bail out! \\$' stdout
126
127 :