1 |
# -*- Autoconf -*- |
# Checking the output filenames. -*- Autotest -*- |
2 |
|
# Copyright 2000, 2001 Free Software Foundation, Inc. |
3 |
|
|
4 |
cat <<EOF |
# 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 |
Simple Calculator. |
# the Free Software Foundation; either version 2, or (at your option) |
7 |
|
# any later version. |
8 |
EOF |
|
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, write to the Free Software |
16 |
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
17 |
|
# 02111-1307, USA. |
18 |
|
|
19 |
|
AT_BANNER([[Simple Calculator.]]) |
20 |
|
|
21 |
## ---------------------------------------------------- ## |
## ---------------------------------------------------- ## |
22 |
## Compile the grammar described in the documentation. ## |
## Compile the grammar described in the documentation. ## |
34 |
# some occurrences of `$1' etc. which will be interpreted by m4. So |
# some occurrences of `$1' etc. which will be interpreted by m4. So |
35 |
# you should call it with $1, $2, and $3 as arguments, which is what |
# you should call it with $1, $2, and $3 as arguments, which is what |
36 |
# AT_DATA_CALC_Y does. |
# AT_DATA_CALC_Y does. |
37 |
AT_DEFINE([_AT_DATA_CALC_Y], |
m4_define([_AT_DATA_CALC_Y], |
38 |
[ifelse([$1$2$3], |
[m4_if([$1$2$3], $[1]$[2]$[3], [], |
39 |
$[1]$[2]$[3], [], |
[m4_fatal([$0: Invalid arguments: $@])])dnl |
|
[errprint([$0: Invalid arguments: $@ |
|
|
])m4exit(1)])dnl |
|
40 |
AT_DATA([calc.y], |
AT_DATA([calc.y], |
41 |
[[/* Infix notation calculator--calc */ |
[[/* Infix notation calculator--calc */ |
42 |
|
|
43 |
%{ |
%{ |
44 |
#include <config.h> |
#include <config.h> |
45 |
|
/* We don't need a perfect malloc for these tests. */ |
46 |
|
#undef malloc |
47 |
#include <stdio.h> |
#include <stdio.h> |
48 |
|
|
49 |
#if STDC_HEADERS |
#if STDC_HEADERS |
222 |
} |
} |
223 |
|
|
224 |
int |
int |
225 |
main (int argn, const char **argv) |
main (int argc, const char **argv) |
226 |
{ |
{ |
227 |
if (argn == 2) |
yyin = NULL; |
228 |
|
|
229 |
|
if (argc == 2) |
230 |
yyin = fopen (argv[1], "r"); |
yyin = fopen (argv[1], "r"); |
231 |
else |
else |
232 |
yyin = stdin; |
yyin = stdin; |
233 |
|
|
234 |
if (!stdin) |
if (!yyin) |
235 |
{ |
{ |
236 |
perror (argv[1]); |
perror (argv[1]); |
237 |
exit (1); |
exit (1); |
254 |
# AT_DATA_CALC_Y([BISON-OPTIONS]) |
# AT_DATA_CALC_Y([BISON-OPTIONS]) |
255 |
# ------------------------------- |
# ------------------------------- |
256 |
# Produce `calc.y'. |
# Produce `calc.y'. |
257 |
AT_DEFINE([AT_DATA_CALC_Y], |
m4_define([AT_DATA_CALC_Y], |
258 |
[_AT_DATA_CALC_Y($[1], $[2], $[3], |
[_AT_DATA_CALC_Y($[1], $[2], $[3], |
259 |
[ifelse(regexp([$1], [--yyerror-verbose]), |
[m4_match([$1], [--yyerror-verbose], |
260 |
[-1], [], |
[[#define YYERROR_VERBOSE 1]])])]) |
|
[[#define YYERROR_VERBOSE 1]])])]) |
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
# _AT_CHECK_CALC(BISON-OPTIONS, INPUT) |
# _AT_CHECK_CALC(BISON-OPTIONS, INPUT, [NUM-STDERR-LINES = 0]) |
265 |
# ------------------------------------ |
# ------------------------------------------------------------ |
266 |
# Run `calc' on INPUT and expect no STDOUT nor STDERR. |
# Run `calc' on INPUT and expect no STDOUT nor STDERR. |
267 |
# If `--debug' is passed to bison, discard all the debugging traces |
# |
268 |
# preserving only the `parse errors'. Note that since there should be |
# If BISON-OPTIONS contains `--debug', then NUM-STDERR-LINES is the number |
269 |
# none, the `grep' will fail with exit status 1. |
# of expected lines on stderr. |
270 |
AT_DEFINE([_AT_CHECK_CALC], |
m4_define([_AT_CHECK_CALC], |
271 |
[ifelse(regexp([$1], [--debug]), |
[AT_DATA([[input]], |
272 |
[-1], |
[[$2 |
273 |
[AT_CHECK([echo "$2" | calc], |
]]) |
274 |
[0], [], [])], |
AT_CHECK([calc input], 0, [], [stderr])dnl |
275 |
[AT_CHECK([echo "$2" | calc 2>&1 >/dev/null | grep 'parse error' >&2], |
AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0, |
276 |
[1], [], [])])]) |
[m4_match([$1], [--debug], |
277 |
|
[$3], [0]) |
278 |
|
]) |
279 |
|
]) |
280 |
|
|
281 |
|
|
282 |
# _AT_CHECK_CALC_ERROR(BISON-OPTIONS, INPUT, |
# _AT_CHECK_CALC_ERROR(BISON-OPTIONS, INPUT, [NUM-DEBUG-LINES], |
283 |
# [ERROR-LOCATION], [IF-YYERROR-VERBOSE]) |
# [ERROR-LOCATION], [IF-YYERROR-VERBOSE]) |
284 |
# ------------------------------------------------------------ |
# ------------------------------------------------------------ |
285 |
# Run `calc' on INPUT, and expect STDERR. |
# Run `calc' on INPUT, and expect a `parse error' message. |
286 |
AT_DEFINE([_AT_CHECK_CALC_ERROR], |
# |
287 |
[AT_CHECK([echo "$2" | calc 2>&1 >/dev/null | grep 'parse error' >&2], 0, |
# If BISON-OPTIONS contains `--location', then make sure the ERROR-LOCATION |
288 |
[], |
# is correctly output on stderr. |
289 |
[ifelse(regexp([$1], [--location]), |
# |
290 |
[-1], [], [$3: ])[]dnl |
# If BISON-OPTIONS contains `--yyerror-verbose', then make sure the |
291 |
|
# IF-YYERROR-VERBOSE message is properly output after `parse error, ' |
292 |
|
# on STDERR. |
293 |
|
# |
294 |
|
# If BISON-OPTIONS contains `--debug', then NUM-STDERR-LINES is the number |
295 |
|
# of expected lines on stderr. |
296 |
|
m4_define([_AT_CHECK_CALC_ERROR], |
297 |
|
[AT_DATA([[input]], |
298 |
|
[[$2 |
299 |
|
]]) |
300 |
|
|
301 |
|
AT_CHECK([calc input], 0, [], [stderr]) |
302 |
|
|
303 |
|
|
304 |
|
AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0, |
305 |
|
[m4_match([$1], [--debug], |
306 |
|
[$3], [1]) |
307 |
|
]) |
308 |
|
|
309 |
|
egrep -v '^((Start|Enter|Read|Reduc|Shift)ing|state|Error:) ' stderr >at-stderr |
310 |
|
mv at-stderr stderr |
311 |
|
|
312 |
|
AT_CHECK([cat stderr], 0, |
313 |
|
[m4_match([$1], [--location], [$4: ])[]dnl |
314 |
parse error[]dnl |
parse error[]dnl |
315 |
ifelse(regexp([$1], [--yyerror-verbose]), |
m4_match([$1], [--yyerror-verbose], [, $5])[]dnl |
316 |
[-1], [], [$4])[]dnl |
|
317 |
|
]) |
318 |
|
|
319 |
])]) |
]) |
320 |
|
|
321 |
|
|
322 |
# AT_CHECK_CALC([BISON-OPTIONS], [PARSER-EXPECTED-STDERR]) |
# AT_CHECK_CALC([BISON-OPTIONS], [PARSER-EXPECTED-STDERR]) |
323 |
# -------------------------------------------------------- |
# -------------------------------------------------------- |
324 |
# Start a testing chunk which compiles `calc' grammar with |
# Start a testing chunk which compiles `calc' grammar with |
325 |
# BISON-OPTIONS, and performs several tests over the parser. |
# BISON-OPTIONS, and performs several tests over the parser. |
326 |
AT_DEFINE([AT_CHECK_CALC], |
m4_define([AT_CHECK_CALC], |
327 |
[# We use integers to avoid dependencies upon the precision of doubles. |
[# We use integers to avoid dependencies upon the precision of doubles. |
328 |
AT_SETUP([Calculator $1]) |
AT_SETUP([Calculator $1]) |
329 |
|
|
330 |
AT_DATA_CALC_Y([$1]) |
AT_DATA_CALC_Y([$1]) |
331 |
|
|
332 |
# Specify the output files to avoid problems on different file systems. |
# Specify the output files to avoid problems on different file systems. |
333 |
AT_CHECK([bison calc.y -o calc.c patsubst([$1], [--yyerror-verbose])], |
AT_CHECK([bison calc.y -o calc.c m4_patsubst([$1], [--yyerror-verbose])], |
334 |
[0], [], []) |
[0], [], []) |
335 |
AT_CHECK([$CC $CFLAGS $CPPFLAGS calc.c -o calc], 0, [], []) |
AT_CHECK([$CC $CFLAGS $CPPFLAGS calc.c -o calc], 0, [], []) |
336 |
|
|
348 |
1 - (2 - 3) = 2 |
1 - (2 - 3) = 2 |
349 |
|
|
350 |
2^2^3 = 256 |
2^2^3 = 256 |
351 |
(2^2)^3 = 64], [$2]) |
(2^2)^3 = 64], [491]) |
352 |
|
|
353 |
# Some parse errors. |
# Some parse errors. |
354 |
_AT_CHECK_CALC_ERROR([$1], [+1], |
_AT_CHECK_CALC_ERROR([$1], [+1], [8], |
355 |
[1.0:1.1], |
[1.0:1.1], |
356 |
[, unexpected `'+'']) |
[unexpected `'+'']) |
357 |
_AT_CHECK_CALC_ERROR([$1], [1//2], |
_AT_CHECK_CALC_ERROR([$1], [1//2], [17], |
358 |
[1.2:1.3], |
[1.2:1.3], |
359 |
[, unexpected `'/'', expecting `NUM' or `'-'' or `'('']) |
[unexpected `'/'', expecting `NUM' or `'-'' or `'('']) |
360 |
_AT_CHECK_CALC_ERROR([$1], [error], |
_AT_CHECK_CALC_ERROR([$1], [error], [8], |
361 |
[1.0:1.1], |
[1.0:1.1], |
362 |
[, unexpected `$undefined.']) |
[unexpected `$undefined.']) |
363 |
_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], |
_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], [23], |
364 |
[1.6:1.7], |
[1.6:1.7], |
365 |
[, unexpected `'='']) |
[unexpected `'='']) |
366 |
_AT_CHECK_CALC_ERROR([$1], |
_AT_CHECK_CALC_ERROR([$1], |
367 |
[ |
[ |
368 |
+1], |
+1], |
369 |
|
[16], |
370 |
[2.0:2.1], |
[2.0:2.1], |
371 |
[, unexpected `'+'']) |
[unexpected `'+'']) |
372 |
|
|
373 |
AT_CLEANUP(calc calc.c calc.h calc.output) |
AT_CLEANUP(calc calc.c calc.h calc.output) |
374 |
])# AT_CHECK_CALC |
])# AT_CHECK_CALC |