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