ylwrap: preserve subdirectories in "#line" munging
[platform/upstream/automake.git] / t / tap-log.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 #  - log file creation
19 #  - log file removal
20 #  - stdout and stderr of a script go in its log file
21 #  - TEST_SUITE_LOG redefinition, at either automake or make time
22 #  - VERBOSE environment variable support
23 # Keep in sync with 'test-log.test'.
24
25 am_parallel_tests=yes
26 . ./defs || Exit 1
27
28 cat > Makefile.am << 'END'
29 TESTS = pass.test skip.test xfail.test fail.test xpass.test error.test
30 TEST_SUITE_LOG = global.log
31 END
32
33 . "$am_testauxdir"/tap-setup.sh || fatal_ "sourcing tap-setup.sh"
34
35 # Custom markers, for use in grepping checks.
36 cmarker=::: # comment marker
37 pmarker=%%% # plain maker
38
39 cat > pass.test <<END
40 #! /bin/sh -e
41 echo 1..1
42 echo   "$pmarker pass $pmarker" >&2
43 echo "# $cmarker pass $cmarker" >&2
44 echo "ok 1"
45 END
46
47 cat > skip.test <<END
48 #! /bin/sh -e
49 echo 1..1
50 echo   "$pmarker skip $pmarker"
51 echo "# $cmarker skip $cmarker"
52 echo "ok 1 # SKIP"
53 END
54
55 cat > xfail.test <<END
56 #! /bin/sh -e
57 echo 1..1
58 echo   "$pmarker xfail $pmarker" >&2
59 echo "# $cmarker xfail $cmarker" >&2
60 echo "not ok 1 # TODO"
61 END
62
63 cat > fail.test <<END
64 #! /bin/sh -e
65 echo 1..1
66 echo   "$pmarker fail $pmarker"
67 echo "# $cmarker fail $cmarker"
68 echo "not ok 1"
69 END
70
71 cat > xpass.test <<END
72 #! /bin/sh -e
73 echo 1..1
74 echo   "$pmarker xpass $pmarker" >&2
75 echo "# $cmarker xpass $cmarker" >&2
76 echo "ok 1 # TODO"
77 END
78
79 cat > error.test <<END
80 #! /bin/sh -e
81 echo 1..1
82 echo   "$pmarker error $pmarker"
83 echo "# $cmarker error $cmarker"
84 echo 'Bail out!'
85 END
86
87 chmod a+x *.test
88
89 TEST_SUITE_LOG=my.log $MAKE -e check && Exit 1
90 ls -l # For debugging.
91 test ! -f test-suite.log
92 test ! -f global.log
93 test -f my.log
94 st=0
95 for result in pass fail xfail xpass skip error; do
96   cat $result.log # For debugging.
97   $FGREP "$pmarker $result $pmarker" $result.log || st=1
98   $FGREP "$cmarker $result $cmarker" $result.log || st=1
99 done
100 test $st -eq 0 || Exit 1
101 cat my.log # For debugging.
102 for result in xfail fail xpass skip error; do
103   cat $result.log # For debugging.
104   $FGREP "$pmarker $result $pmarker" my.log || st=1
105   $FGREP "$cmarker $result $cmarker" my.log || st=1
106 done
107 test `$FGREP -c "$pmarker" my.log` -eq 5
108 test `$FGREP -c "$cmarker" my.log` -eq 5
109
110 # Passed test scripts shouldn't be mentioned in the global log.
111 $EGREP '(^pass|[^x]pass)\.test' my.log && Exit 1
112 # But failing (expectedly or not) and skipped ones should.
113 $FGREP 'xfail.test' my.log
114 $FGREP 'skip.test' my.log
115 $FGREP 'fail.test' my.log
116 $FGREP 'xpass.test' my.log
117 $FGREP 'error.test' my.log
118
119 touch error2.log test-suite.log global.log
120 TEST_SUITE_LOG=my.log $MAKE -e mostlyclean
121 ls -l # For debugging.
122 test ! -f my.log
123 test ! -f pass.log
124 test ! -f fail.log
125 test ! -f xfail.log
126 test ! -f xpass.log
127 test ! -f skip.log
128 test ! -f error.log
129 # "make mostlyclean" shouldn't remove unrelated log files.
130 test -f error2.log
131 test -f test-suite.log
132 test -f global.log
133
134 rm -f *.log
135
136 VERBOSE=yes $MAKE check >stdout && { cat stdout; Exit 1; }
137 cat stdout
138 cat global.log
139 test ! -f my.log
140 test ! -f test-suite.log
141 # Check that VERBOSE causes the global testsuite log to be
142 # emitted on stdout.
143 out=`cat stdout`
144 log=`cat global.log`
145 case $out in *"$log"*) ;; *) Exit 1;; esac
146
147 touch error2.log test-suite.log my.log
148 $MAKE clean
149 ls -l # For debugging.
150 test ! -f global.log
151 test ! -f pass.log
152 test ! -f fail.log
153 test ! -f xfail.log
154 test ! -f xpass.log
155 test ! -f skip.log
156 test ! -f error.log
157 # "make clean" shouldn't remove unrelated log files.
158 test -f error2.log
159 test -f test-suite.log
160 test -f my.log
161
162 rm -f *.log
163
164 :