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