Merge branch 'rmch'
[platform/upstream/automake.git] / t / tap-diagnostic.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 # TAP support:
18 #  - diagnostic messages (TAP lines with leading "#")
19 #  - flags '--comments' and '--no-comments' of the TAP test driver
20
21 am_parallel_tests=yes
22 . ./defs || Exit 1
23
24 . "$am_testauxdir"/tap-setup.sh || fatal_ "sourcing tap-setup.sh"
25
26 metacharacters=\''"\$!&()[]<>#;^?*'
27
28 cat > all.test <<END
29 1..4
30 # Hi! I'm a comment.
31 # Tests begin.
32 ok 1
33 not ok 2 - foo # TODO
34 ok 3 - bar # SKIP
35 # Tests end.
36 ok - zardoz
37 # Shell metacharacters here: $metacharacters
38 .# Leading characters before "#", not a TAP diagnostic line.
39 x # Leading characters before "#", not a TAP diagnostic line.
40  # Leading whitespace before "#", not a TAP diagnostic line.
41 ${tab}# Leading whitespace before "#", not a TAP diagnostic line.
42  ${tab}  # Leading whitespace before "#", not a TAP diagnostic line.
43 END
44
45 cat > exp <<END
46 # all.test: Hi! I'm a comment.
47 # all.test: Tests begin.
48 PASS: all.test 1
49 XFAIL: all.test 2 - foo # TODO
50 SKIP: all.test 3 - bar # SKIP
51 # all.test: Tests end.
52 PASS: all.test 4 - zardoz
53 # all.test: Shell metacharacters here: $metacharacters
54 END
55
56 $MAKE check >stdout || { cat stdout; Exit 1; }
57 cat stdout
58 $EGREP -i "#.*all\\.test|a comment|(Tests|Shell) " stdout && Exit 1
59 count_test_results total=4 pass=2 fail=0 xpass=0 xfail=1 skip=1 error=0
60
61 echo 'AM_TEST_LOG_DRIVER_FLAGS = --comments' >> Makefile
62 $MAKE check >stdout || { cat stdout; Exit 1; }
63 cat stdout
64 $FGREP ' all.test' stdout > got
65 cat exp
66 cat got
67 diff exp got
68 count_test_results total=4 pass=2 fail=0 xpass=0 xfail=1 skip=1 error=0
69
70 TEST_LOG_DRIVER_FLAGS="--no-comments" $MAKE -e check >stdout \
71   || { cat stdout; Exit 1; }
72 cat stdout
73 $EGREP -i "#.*all\\.test|a comment|(Tests|Shell) " stdout && Exit 1
74 count_test_results total=4 pass=2 fail=0 xpass=0 xfail=1 skip=1 error=0
75
76 # The "#"-prepended lines here shouldn't be parsed as test results.
77 cat > all.test <<END
78 1..1
79 ok
80 # ok
81 #ok
82 # not ok
83 #not ok
84 # Bail out!
85 #Bail out!
86 # SKIP
87 #SKIP
88 # TODO
89 #TODO
90 END
91
92 $MAKE check >stdout || { cat stdout; Exit 1; }
93 cat stdout
94 count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
95
96 # Diagnostic without leading whitespace, or with extra leading whitespace,
97 # is ok.  Be laxer in the grepping checks, to allow for whitespace
98 # normalization by the TAP driver.
99
100 ws="[ $tab]"
101 ws0p="${ws}*"
102 ws1p="${ws}${ws0p}"
103
104 cat > all.test <<END
105 1..1
106 ok 1
107 #foo
108 #bar${tab}
109 #   zardoz  ${tab}
110 #  ${tab} ${tab}${tab}foo  bar${tab}baz  ${tab}
111 END
112
113 $MAKE check >stdout || { cat stdout; Exit 1; }
114 cat stdout
115 count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
116
117 grep "^# all.test:${ws0p}foo$" stdout
118 grep "^# all.test:${ws0p}bar${ws0p}$" stdout
119 grep "^# all.test:${ws1p}zardoz${ws0p}$" stdout
120 grep "^# all.test:${ws1p}foo  bar${tab}baz${ws0p}$" stdout
121
122 test `grep -c '^# all\.test:' stdout` -eq 4
123
124 :