]> git.saurik.com Git - bison.git/blame - tests/atgeneral.m4
* src/output.c: Formatting changes.
[bison.git] / tests / atgeneral.m4
CommitLineData
e79137ac
AD
1divert(-1) -*- shell-script -*-
2# `m4' macros used in building test suites.
3# Copyright (C) 2000 Free Software Foundation, Inc.
4
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2, or (at your option)
8# any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18# 02111-1307, USA.
19
20# This script is part of Autotest. Unlimited permission to copy,
21# distribute and modify the testing scripts that are the output of
22# that Autotest script is given. You need not follow the terms of the
23# GNU General Public License when using or distributing such scripts,
24# even though portions of the text of Autotest appear in them. The
25# GNU General Public License (GPL) does govern all other use of the
26# material that constitutes the Autotest.
27#
28# Certain portions of the Autotest source text are designed to be
29# copied (in certain cases, depending on the input) into the output of
30# Autotest. We call these the "data" portions. The rest of the
31# Autotest source text consists of comments plus executable code that
32# decides which of the data portions to output in any given case. We
33# call these comments and executable code the "non-data" portions.
34# Autotest never copies any of the non-data portions into its output.
35#
36# This special exception to the GPL applies to versions of Autotest
37# released by the Free Software Foundation. When you make and
38# distribute a modified version of Autotest, you may extend this
39# special exception to the GPL to apply to your modified version as
40# well, *unless* your modified version has the potential to copy into
41# its output some of the text that was the non-data portion of the
42# version that you started with. (In other words, unless your change
43# moves or copies text from the non-data portions to the data
44# portions.) If your modification has such potential, you must delete
45# any notice of this special exception to the GPL from your modified
46# version.
47
48changequote([, ])
49
50define(AT_DEFINE, defn([define]))
51define(AT_EVAL, defn([eval]))
52define(AT_FORMAT, defn([format]))
53define(AT_INCLUDE, defn([include]))
54define(AT_SHIFT, defn([shift]))
55define(AT_UNDEFINE, defn([undefine]))
56
57undefine([define])
58undefine([eval])
59undefine([format])
60undefine([include])
61undefine([shift])
62undefine([undefine])
63
64# AT_CASE(SWITCH, VAL1, IF-VAL1, VAL2, IF-VAL2, ..., DEFAULT)
65
66# m4 equivalent of
67# switch (SWITCH)
68# {
69# case VAL1:
70# IF-VAL1;
71# break;
72# case VAL2:
73# IF-VAL2;
74# break;
75# ...
76# default:
77# DEFAULT;
78# break;
79# }.
80# All the values are optional, and the macro is robust to active
81# symbols properly quoted.
82AT_DEFINE(AT_CASE,
83[ifelse([$#], 0, [],
84 [$#], 1, [],
85 [$#], 2, [$2],
86 [$1], [$2], [$3],
87 [AT_CASE([$1], AT_SHIFT(AT_SHIFT(AT_SHIFT($@))))])])
88
89
90# Use of diversions:
91# 0 - overall initialization; for each test group: skipping and cleanups;
92# 1 - for each test group: proper code, to reinsert between cleanups;
93# 2 - overall wrap up: generation of debugging scripts and statistics.
94
95
96# AT_LINE
97
98# Return the current file sans directory, a colon, and the current line.
99
100AT_DEFINE(AT_LINE,
101[patsubst(__file__, ^.*/\(.*\), \1):__line__])
102
103# AT_INIT(PROGRAM)
104
105# Begin testing suite, using PROGRAM to check version. The search path
106# should be already preset so the proper executable will be selected.
107
108AT_DEFINE(AT_INIT,
109[AT_DEFINE(AT_ordinal, 0)
110. ./atconfig
111# Snippet (3
112
113at_usage="Usage: [$]0 [OPTION]...
114
115 -e Abort the full suite and inhibit normal clean up if a test fails
116 -n Do not redirect stdout and stderr and do not test their contents
117 -s Inhibit verbosity while generating or executing debugging scripts
118 -v Force more detailed output, default for debugging scripts unless -s
119 -x Have the shell to trace command execution; also implies option -n"
120
121while test [$][#] -gt 0; do
122 case "[$]1" in
123 --help) echo "$at_usage"; exit 0 ;;
124 --version) echo "[$]0 ($at_package) $at_version"; exit 0 ;;
125 -e) at_stop_on_error=1; shift ;;
126 -n) at_no_redirs=1; shift ;;
127 -s) at_verbose=; at_silent=1; shift ;;
128 -v) at_verbose=1; at_silent=; shift ;;
129 -x) at_traceon='set -vx'; at_traceoff='set +vx'; at_no_redirs=1; shift ;;
130 *) echo 1>&2 "Try \`[$]0 --help' for more information."; exit 1 ;;
131 esac
132done
133
134
135# To check whether a test succeeded or not, we compare an expected
136# output with a reference. In the testing suite, we just need `cmp'
137# but in debugging scripts, we want more information, so we prefer
138# `diff -u'. Nonetheless we will use `diff' only, because in DOS
139# environments, `diff' considers that two files are equal included
140# when there are only differences on the coding of new lines. `cmp'
141# does not.
142#
143# Finally, not all the `diff' support `-u', and some, like Tru64, even
144# refuse to `diff' /dev/null.
145: >empty
146
147if diff -u empty empty >/dev/null 2>&1; then
148 at_diff='diff -u'
149else
150 at_diff='diff'
151fi
152
153
154
155# Each generated debugging script, containing a single test group, cleans
156# up files at the beginning only, not at the end. This is so we can repeat
157# the script many times and browse left over files. To cope with such left
158# over files, the full test suite cleans up both before and after test groups.
159# Snippet )3
160
161if test -n "`$1 --version | sed -n s/$at_package.*$at_version/OK/p`"; then
162 at_banner="Testing suite for $at_package, version $at_version"
163 at_dashes=`echo $at_banner | sed s/./=/g`
164 echo "$at_dashes"
165 echo "$at_banner"
166 echo "$at_dashes"
167else
168 echo '======================================================='
169 echo 'ERROR: Not using the proper version, no tests performed'
170 echo '======================================================='
171 exit 1
172fi
173
174# Remove any debugging script resulting from a previous run.
175rm -f debug-*.sh
176
177at_failed_list=
178at_ignore_count=0
179divert(2)[]dnl
180
181# Wrap up the testing suite with summary statistics.
182
183rm -f at-check-line
184at_fail_count=0
185if test -z "$at_failed_list"; then
186 if test "$at_ignore_count" = 0; then
187 at_banner="All $at_test_count tests were successful"
188 else
189 at_banner="All $at_test_count tests were successful ($at_ignore_count ignored)"
190 fi
191else
192 echo
193 echo $at_n "Writing \`debug-NN.sh' scripts, NN =$at_c"
194 for at_group in $at_failed_list; do
195 echo $at_n " $at_group$at_c"
196 ( echo '#!/bin/sh'
197 sed -n '/^[#] Snippet (1/,/^[#] Snippet )1/p' atconfig
198 test -z "$at_silent" && echo 'at_verbose=1'
199 sed -n '/^[#] Snippet (2/,/^[#] Snippet )2/p' atconfig
200 sed -n "/^[#] Snippet (3/,/^[#] Snippet )3/p" [$]0
201 sed -n "/^[#] Snippet (c$at_group(/,/^[#] Snippet )c$at_group)/p" [$]0
202 at_desc="`sed -n \
203 '/^[#] Snippet (d'$at_group'(/,/^[#] Snippet )d'$at_group')/p' [$]0 \
204 | sed -n '2s/^[#] //p'`"
205 echo 'if test -n "$at_verbose"; then'
206 echo ' at_banner="[$]0: '$at_desc'"'
207 echo ' at_dashes=`echo $at_banner | sed s/./=/g`'
208 echo ' echo'
209 echo ' echo "$at_dashes"'
210 echo ' echo "$at_banner"'
211 echo ' echo "$at_dashes"'
212 echo 'fi'
213 echo
214 sed -n "/^[#] Snippet (d$at_group(/,/^[#] Snippet )d$at_group)/p" [$]0
215 sed -n "/^[#] Snippet (s$at_group(/,/^[#] Snippet )s$at_group)/p" [$]0
216 echo 'exit 0'
217 ) | grep -v '^[#] Snippet' > debug-$at_group.sh
218 chmod +x debug-$at_group.sh
219 at_fail_count=`expr $at_fail_count + 1`
220 done
221 echo ', done'
222 if test -n "$at_stop_on_error"; then
223 at_banner='ERROR: One of the tests failed, inhibiting subsequent tests'
224 else
225 at_banner="ERROR: Suite unsuccessful, $at_fail_count of $at_test_count tests failed"
226 fi
227fi
228at_dashes=`echo $at_banner | sed s/./=/g`
229echo
230echo "$at_dashes"
231echo "$at_banner"
232echo "$at_dashes"
233
234if test -n "$at_failed_list"; then
235 if test -z "$at_silent"; then
236 echo
237 echo 'When reporting failed tests to maintainers, do not merely list test'
238 echo 'numbers, as the numbering changes between releases and pretests.'
239 echo 'Be careful to give at least all the information you got about them.'
240 echo 'You may investigate any problem if you feel able to do so, in which'
241 echo 'case the generated debugging scripts provide good starting points.'
242 echo "Go on and modify them at will. \`./debug-NN --help' gives usage"
243 echo 'information. Now, failed tests will be executed again, verbosely.'
244 for at_group in $at_failed_list; do
245 ./debug-$at_group.sh
246 done
247 fi
248 exit 1
249fi
250
251exit 0
252divert[]dnl
253])
254
255# AT_SETUP(DESCRIPTION)
256
257# Start a group of related tests, all to be executed in the same subshell.
258# The group is testing what DESCRIPTION says.
259
260AT_DEFINE(AT_SETUP,
261[AT_DEFINE([AT_ordinal], AT_EVAL(AT_ordinal + 1))
262pushdef([AT_group_description], [$1])
263pushdef([AT_data_files], )
264pushdef([AT_data_expout], )
265pushdef([AT_data_experr], )
266if test -z "$at_stop_on_error" || test -z "$at_failed_list"; then
267divert(1)[]dnl
268 echo AT_LINE > at-check-line
269 if test -n "$at_verbose"; then
270 echo 'testing AT_group_description'
271 echo $at_n " $at_c"
272 fi
273 echo $at_n "substr(AT_ordinal. $srcdir/AT_LINE , 0, 30)[]$at_c"
274 if test -z "$at_skip_mode"; then
275 (
276[#] Snippet (d[]AT_ordinal[](
277[#] Testing AT_group_description
278[#] Snippet )d[]AT_ordinal[])
279[#] Snippet (s[]AT_ordinal[](
280[#] starting from `AT_LINE'.
281$at_traceon
282])
283
284
285# AT_CLEANUP(FILES)
286
287# Complete a group of related tests, recursively remove those FILES
288# created within the test. There is no need to list stdout, stderr,
289# nor files created with AT_DATA.
290
291AT_DEFINE(AT_CLEANUP,
292$at_traceoff
293[[#] Snippet )s[]AT_ordinal[])
294 )
295 case [$]? in
296 0) echo ok
297 ;;
298 77) echo "ignored near \``cat at-check-line`'"
299 at_ignore_count=`expr $at_ignore_count + 1`
300 ;;
301 *) echo "FAILED near \``cat at-check-line`'"
302 at_failed_list="$at_failed_list AT_ordinal"
303 ;;
304 esac
305 else
306 echo 'ignored (skipped)'
307 at_ignore_count=`expr $at_ignore_count + 1`
308 fi
309 at_test_count=AT_ordinal
310 if test -z "$at_stop_on_error" || test -z "$at_failed_list"; then
311divert(0)[]dnl
312[#] Snippet (c[]AT_ordinal[](
313
314rm ifelse([AT_data_files$1], , [-f], [-rf[]AT_data_files[]ifelse($1, , , [ $1])]) stdout stderr[]AT_data_expout[]AT_data_experr
315[#] Snippet )c[]AT_ordinal[])
316undivert(1)[]dnl
317 rm ifelse([AT_data_files$1], , [-f], [-rf[]AT_data_files[]ifelse($1, , , [ $1])]) stdout stderr[]AT_data_expout[]AT_data_experr
318 fi
319fi
320popdef([AT_data_experr])
321popdef([AT_data_expout])
322popdef([AT_data_files])
323popdef([AT_group_description])])
324
325
326# AT_DATA(FILE, CONTENTS)
327
328# Initialize an input data FILE with given CONTENTS, which should end with
329# an end of line.
330# This macro is not robust to active symbols in CONTENTS *on purpose*.
331# If you don't want CONTENT to be evaluated, quote it twice.
332
333AT_DEFINE(AT_DATA,
334[AT_DEFINE([AT_data_files], AT_data_files[ ]$1)
335cat > $1 <<'EOF'
336$2[]EOF
337])
338
339
340# AT_CHECK(COMMANDS, [STATUS], STDOUT, STDERR)
341
342# Execute a test by performing given shell COMMANDS. These commands
343# should normally exit with STATUS, while producing expected STDOUT and
344# STDERR contents. The special word `expout' for STDOUT means that file
345# `expout' contents has been set to the expected stdout. The special word
346# `experr' for STDERR means that file `experr' contents has been set to
347# the expected stderr.
348# STATUS is not checked if it is empty.
349# STDOUT and STDERR can be the special value `ignore', in which case
350# their content is not checked.
351
352AT_DEFINE(AT_CHECK,
353[$at_traceoff
354test -n "$at_verbose" \
355 && echo "$srcdir/AT_LINE: testing..."
356echo AT_LINE > at-check-line
357test -z "$at_no_redirs" && exec 5>&1 6>&2 1>stdout 2>stderr
358$at_traceon
359$1
360ifelse([$2],,,
361[at_status=$?
362if test $at_status != $2; then
363dnl Maybe there was an important message to read before it died.
364 test -n "$at_verbose" && test -z "$at_no_redirs" && cat stderr >&6
365dnl Exit with the same code, at least to preserve 77.
366 exit $at_status
367fi
368])dnl
369$at_traceoff
370if test -z "$at_no_redirs"; then
371 exec 1>&5 2>&6
372 AT_CASE([$3],
373 ignore, [test -n "$at_verbose" && cat stdout;:],
374 expout, [AT_DEFINE([AT_data_expout], [ expout])dnl
375$at_diff expout stdout || exit 1],
376 [], [$at_diff empty stdout || exit 1],
377 [echo $at_n "patsubst([$3], [\([\"`$]\)], \\\1)$at_c" | $at_diff - stdout || exit 1])
378 AT_CASE([$4],
379 ignore, [test -n "$at_verbose" && cat stderr;:],
380 experr, [AT_DEFINE([AT_data_experr], [ experr])dnl
381$at_diff experr stderr || exit 1],
382 [], [$at_diff empty stderr || exit 1],
383 [echo $at_n "patsubst([$4], [\([\"`$]\)], \\\1)$at_c" | $at_diff - stderr || exit 1])
384fi
385$at_traceon
386])
387
388divert(0)dnl