+# Run `calc' on INPUT and expect no STDOUT nor STDERR.
+#
+# If BISON-OPTIONS contains `%debug' but not `%glr-parser', then
+#
+# NUM-STDERR-LINES is the number of expected lines on stderr.
+# Currently this is ignored, though, since the output format is fluctuating.
+#
+# We don't count GLR's traces yet, since its traces are somewhat
+# different from LALR's.
+m4_define([_AT_CHECK_CALC],
+[AT_DATA([[input]],
+[[$2
+]])
+AT_PARSER_CHECK([./calc input], 0, [], [stderr])
+])
+
+
+# _AT_CHECK_CALC_ERROR(BISON-OPTIONS, EXIT-STATUS, INPUT,
+# [NUM-STDERR-LINES],
+# [VERBOSE-AND-LOCATED-ERROR-MESSAGE])
+# ---------------------------------------------------------
+# Run `calc' on INPUT, and expect a `syntax error' message.
+#
+# If INPUT starts with a slash, it is used as absolute input file name,
+# otherwise as contents.
+#
+# NUM-STDERR-LINES is the number of expected lines on stderr.
+# Currently this is ignored, though, since the output format is fluctuating.
+#
+# If BISON-OPTIONS contains `%location', then make sure the ERROR-LOCATION
+# is correctly output on stderr.
+#
+# If BISON-OPTIONS contains `%error-verbose', then make sure the
+# IF-YYERROR-VERBOSE message is properly output after `syntax error, '
+# on STDERR.
+#
+# If BISON-OPTIONS contains `%debug' but not `%glr', then NUM-STDERR-LINES
+# is the number of expected lines on stderr.
+m4_define([_AT_CHECK_CALC_ERROR],
+[m4_bmatch([$3], [^/],
+ [AT_PARSER_CHECK([./calc $3], $2, [], [stderr])],
+ [AT_DATA([[input]],
+[[$3
+]])
+AT_PARSER_CHECK([./calc input], $2, [], [stderr])])
+
+# Normalize the observed and expected error messages, depending upon the
+# options.
+# 1. Remove the traces from observed.
+sed '/^Starting/d
+/^Entering/d
+/^Stack/d
+/^Reading/d
+/^Reducing/d
+/^Return/d
+/^Shifting/d
+/^state/d
+/^Cleanup:/d
+/^Error:/d
+/^Next/d
+/^Now/d
+/^Discarding/d
+/ \$[[0-9$]]* = /d
+/^yydestructor:/d' stderr >at-stderr
+mv at-stderr stderr
+# 2. Create the reference error message.
+AT_DATA([[expout]],
+[$5
+])
+# 3. If locations are not used, remove them.
+AT_YYERROR_SEES_LOC_IF([],
+[[sed 's/^[-0-9.]*: //' expout >at-expout
+mv at-expout expout]])
+# 4. If error-verbose is not used, strip the`, unexpected....' part.
+m4_bmatch([$1], [%error-verbose], [],
+[[sed 's/syntax error, .*$/syntax error/' expout >at-expout
+mv at-expout expout]])
+# 5. Check
+AT_CHECK([cat stderr], 0, [expout])
+])
+
+
+# AT_CHECK_CALC([BISON-OPTIONS, [EXPECTED-TO-FAIL]])
+# --------------------------------------------------