tests: remove too-brittle test tap-realtime.sh
[platform/upstream/automake.git] / t / test-log.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 # Check parallel-tests features:
18 #  - log file creation
19 #  - log file removal
20 #  - stdout and stderr of a test 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 'tap-log.sh'.
24
25 . test-init.sh
26
27 cat >> configure.ac <<END
28 AC_OUTPUT
29 END
30
31 cat > Makefile.am << 'END'
32 TESTS = pass.test skip.test xfail.test fail.test xpass.test error.test
33 XFAIL_TESTS = xpass.test xfail.test
34 TEST_SUITE_LOG = global.log
35 END
36
37 # Custom markers, for use in grepping checks.
38 cmarker=::: # comment marker
39 pmarker=%%% # plain maker
40
41 cat > pass.test <<END
42 #! /bin/sh
43 echo   "$pmarker pass $pmarker" >&2
44 echo "# $cmarker pass $cmarker" >&2
45 exit 0
46 END
47
48 cat > skip.test <<END
49 #! /bin/sh
50 echo   "$pmarker skip $pmarker"
51 echo "# $cmarker skip $cmarker"
52 exit 77
53 END
54
55 cat > xfail.test <<END
56 #! /bin/sh
57 echo   "$pmarker xfail $pmarker" >&2
58 echo "# $cmarker xfail $cmarker" >&2
59 exit 1
60 END
61
62 cat > fail.test <<END
63 #! /bin/sh
64 echo   "$pmarker fail $pmarker"
65 echo "# $cmarker fail $cmarker"
66 exit 1
67 END
68
69 cat > xpass.test <<END
70 #! /bin/sh
71 echo   "$pmarker xpass $pmarker" >&2
72 echo "# $cmarker xpass $cmarker" >&2
73 exit 0
74 END
75
76 cat > error.test <<END
77 #! /bin/sh
78 echo   "$pmarker error $pmarker"
79 echo "# $cmarker error $cmarker"
80 exit 99
81 END
82
83 chmod a+x *.test
84
85 $ACLOCAL
86 $AUTOCONF
87 $AUTOMAKE -a
88
89 ./configure
90
91 run_make -e FAIL TEST_SUITE_LOG=my.log check
92 ls -l # For debugging.
93 test ! -e test-suite.log
94 test ! -e global.log
95 test -f my.log
96 st=0
97 for result in pass fail xfail xpass skip error; do
98   cat $result.log # For debugging.
99   $FGREP "$pmarker $result $pmarker" $result.log || st=1
100   $FGREP "$cmarker $result $cmarker" $result.log || st=1
101 done
102 test $st -eq 0 || exit 1
103 cat my.log # For debugging.
104 for result in xfail fail xpass skip error; do
105   cat $result.log # For debugging.
106   $FGREP "$pmarker $result $pmarker" my.log || st=1
107   $FGREP "$cmarker $result $cmarker" my.log || st=1
108 done
109 test $($FGREP -c "$pmarker" my.log) -eq 5
110 test $($FGREP -c "$cmarker" my.log) -eq 5
111
112 have_rst_section ()
113 {
114   eqeq=$(echo "$1" | sed 's/./=/g')
115   # Assume $1 contains no RE metacharacters.
116   sed -n "/^$1$/,/^$eqeq$/p" $2 > got
117   (echo "$1" && echo "$eqeq") > exp
118   cat exp
119   cat got
120   diff exp got
121 }
122
123 # Passed test scripts shouldn't be mentioned in the global log.
124 $EGREP ':.*[^x]pass' my.log && exit 1
125 # But failing (expectedly or not) and skipped ones should.
126 have_rst_section 'SKIP: skip'   my.log
127 have_rst_section 'FAIL: fail'   my.log
128 have_rst_section 'XFAIL: xfail' my.log
129 have_rst_section 'XPASS: xpass' my.log
130 have_rst_section 'ERROR: error' my.log
131
132 touch error2.log test-suite.log global.log
133 run_make TEST_SUITE_LOG=my.log mostlyclean
134 ls -l # For debugging.
135 test ! -e my.log
136 test ! -e pass.log
137 test ! -e fail.log
138 test ! -e xfail.log
139 test ! -e xpass.log
140 test ! -e skip.log
141 test ! -e error.log
142 # "make mostlyclean" shouldn't remove unrelated log files.
143 test -f error2.log
144 test -f test-suite.log
145 test -f global.log
146
147 rm -f *.log
148
149 run_make -O -e FAIL check VERBOSE=yes
150 cat global.log
151 test ! -e my.log
152 test ! -e test-suite.log
153 # Check that VERBOSE causes the global testsuite log to be
154 # emitted on stdout.
155 out=$(cat stdout)
156 log=$(cat global.log)
157 case $out in *"$log"*) ;; *) exit 1;; esac
158
159 touch error2.log test-suite.log my.log
160 $MAKE clean
161 ls -l # For debugging.
162 test ! -e global.log
163 test ! -e pass.log
164 test ! -e fail.log
165 test ! -e xfail.log
166 test ! -e xpass.log
167 test ! -e skip.log
168 test ! -e error.log
169 # "make clean" shouldn't remove unrelated log files.
170 test -f error2.log
171 test -f test-suite.log
172 test -f my.log
173
174 rm -f *.log
175
176 :