-# Run `calc' on INPUT, and expect STDERR.
-AT_DEFINE([_AT_CHECK_CALC_ERROR],
-[AT_CHECK([echo "$2" | calc 2>&1 >/dev/null | grep 'parse error' >&2], 0,
- [],
-[ifelse(regexp([$1], [--location]),
- [-1], [], [$3: ])[]dnl
+# Run `calc' on INPUT, and expect a `parse error' message.
+#
+# If INPUT starts with a slash, it is used as absolute input file name,
+# otherwise as contents.
+#
+# If BISON-OPTIONS contains `--location', then make sure the ERROR-LOCATION
+# is correctly output on stderr.
+#
+# If BISON-OPTIONS contains `--yyerror-verbose', then make sure the
+# IF-YYERROR-VERBOSE message is properly output after `parse error, '
+# on STDERR.
+#
+# If BISON-OPTIONS contains `--debug', then NUM-STDERR-LINES is the number
+# of expected lines on stderr.
+m4_define([_AT_CHECK_CALC_ERROR],
+[m4_bmatch([$2], [^/],
+ [AT_CHECK([calc $2], 0, [], [stderr])],
+ [AT_DATA([[input]],
+[[$2
+]])
+AT_CHECK([calc input], 0, [], [stderr])])
+
+
+AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0,
+ [m4_bmatch([$1], [--debug],
+ [$3], [1])
+])
+
+egrep -v '^((Start|Enter|Read|Reduc|Shift)ing|state|Error:) ' stderr >at-stderr
+mv at-stderr stderr
+
+AT_CHECK([cat stderr], 0,
+[m4_bmatch([$1], [--location], [$4: ])[]dnl