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