+
+## ------------------------ ##
+## Bad character literals. ##
+## ------------------------ ##
+
+# Bison used to accept character literals that were empty or contained
+# too many characters.
+
+# FIXME: AT_DATA or some variant of AT_DATA may eventually permit
+# the final newline to be omitted. See the threads starting at
+# <http://lists.gnu.org/archive/html/bison-patches/2009-07/msg00019.html>.
+
+AT_SETUP([[Bad character literals]])
+
+AT_DATA([empty.y],
+[[%%
+start: '';
+start: '
+]])
+AT_CHECK([[$PERL -e "print 'start: \'';" >> empty.y || exit 77]])
+
+AT_BISON_CHECK([empty.y], [1], [],
+[[empty.y:2.8-9: warning: empty character literal
+empty.y:3.8-4.0: warning: empty character literal
+empty.y:3.8-4.0: error: missing "'" at end of line
+empty.y:4.8: warning: empty character literal
+empty.y:4.8: error: missing "'" at end of file
+]])
+
+AT_DATA([two.y],
+[[%%
+start: 'ab';
+start: 'ab
+]])
+AT_CHECK([[$PERL -e "print 'start: \'ab';" >> two.y || exit 77]])
+
+AT_BISON_CHECK([two.y], [1], [],
+[[two.y:2.8-11: warning: extra characters in character literal
+two.y:3.8-4.0: warning: extra characters in character literal
+two.y:3.8-4.0: error: missing "'" at end of line
+two.y:4.8-10: warning: extra characters in character literal
+two.y:4.8-10: error: missing "'" at end of file
+]])
+
+AT_DATA([three.y],
+[[%%
+start: 'abc';
+start: 'abc
+]])
+AT_CHECK([[$PERL -e "print 'start: \'abc';" >> three.y || exit 77]])
+
+AT_BISON_CHECK([three.y], [1], [],
+[[three.y:2.8-12: warning: extra characters in character literal
+three.y:3.8-4.0: warning: extra characters in character literal
+three.y:3.8-4.0: error: missing "'" at end of line
+three.y:4.8-11: warning: extra characters in character literal
+three.y:4.8-11: error: missing "'" at end of file
+]])
+
+AT_CLEANUP
+
+## ------------------------- ##
+## Bad escapes in literals. ##
+## ------------------------- ##
+
+AT_SETUP([[Bad escapes in literals]])
+
+AT_DATA([input.y],
+[[%%
+start: '\777' '\0' '\xfff' '\x0'
+ '\uffff' '\u0000' '\Uffffffff' '\U00000000'
+ '\ ' '\A';
+]])
+
+# It is not easy to create special characters, we cannot even trust tr.
+# Beside we cannot even expect "echo '\0'" to output two characters
+# (well three with \n): at least Bash 3.2 converts the two-character
+# sequence "\0" into a single NUL character.
+AT_CHECK([[$PERL -e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y \
+ || exit 77]])
+
+AT_BISON_CHECK([input.y], [1], [],
+[[input.y:2.9-12: error: invalid number after \-escape: 777
+input.y:2.8-13: warning: empty character literal
+input.y:2.16-17: error: invalid number after \-escape: 0
+input.y:2.15-18: warning: empty character literal
+input.y:2.21-25: error: invalid number after \-escape: xfff
+input.y:2.20-26: warning: empty character literal
+input.y:2.29-31: error: invalid number after \-escape: x0
+input.y:2.28-32: warning: empty character literal
+input.y:3.9-14: error: invalid number after \-escape: uffff
+input.y:3.8-15: warning: empty character literal
+input.y:3.18-23: error: invalid number after \-escape: u0000
+input.y:3.17-24: warning: empty character literal
+input.y:3.27-36: error: invalid number after \-escape: Uffffffff
+input.y:3.26-37: warning: empty character literal
+input.y:3.40-49: error: invalid number after \-escape: U00000000
+input.y:3.39-50: warning: empty character literal
+input.y:4.9-10: error: invalid character after \-escape: ' '
+input.y:4.8-11: warning: empty character literal
+input.y:4.14-15: error: invalid character after \-escape: A
+input.y:4.13-16: warning: empty character literal
+input.y:5.9-16: error: invalid character after \-escape: \t
+input.y:5.17: error: invalid character after \-escape: \f
+input.y:5.18: error: invalid character after \-escape: \0
+input.y:5.19: error: invalid character after \-escape: \001
+]])
+
+AT_CLEANUP
+
+## ------------------------- ##
+## LAC: Errors for %define. ##
+## ------------------------- ##
+
+AT_SETUP([[LAC: Errors for %define]])
+
+AT_DATA([[input.y]],
+[[%%
+start: ;
+]])
+
+# parse.lac.* options are useless if LAC isn't actually activated.
+AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]],
+ [[1]], [],
+[[<command line>:1: error: %define variable 'parse.lac.es-capacity-initial' is not used
+]])
+AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]],
+ [[1]], [],
+[[<command line>:1: error: %define variable 'parse.lac.memory-trace' is not used
+]])
+
+AT_CLEANUP
+
+## --------------------------------------------- ##
+## -Werror is not affected by -Wnone and -Wall. ##
+## --------------------------------------------- ##
+
+AT_SETUP([[-Werror is not affected by -Wnone and -Wall]])
+
+AT_DATA([[input.y]],
+[[%%
+foo-bar: ;
+]])
+
+# -Werror is not enabled by -Wall or equivalent.
+AT_BISON_CHECK([[-Wall input.y]], [[0]], [[]],
+[[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
+]])
+AT_BISON_CHECK([[-W input.y]], [[0]], [[]],
+[[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
+]])
+AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]],
+[[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
+]])
+
+# -Werror is not disabled by -Wnone or equivalent.
+AT_BISON_CHECK([[-Werror,none,yacc input.y]], [[1]], [[]], [[stderr]])
+AT_CHECK([[sed 's/^.*bison:/bison:/' stderr]], [[0]],
+[[bison: warnings being treated as errors
+input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
+]])
+[mv stderr experr]
+AT_BISON_CHECK([[-Werror,no-all,yacc input.y]], [[1]], [[]], [[experr]])
+
+AT_CLEANUP
+
+
+## ------------------------------------------------------ ##
+## %name-prefix and %define api.prefix are incompatible. ##
+## ------------------------------------------------------ ##
+
+AT_SETUP([[%name-prefix and %define api.prefix are incompatible]])
+
+# AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
+# --------------------------------------------
+m4_pushdef([AT_TEST],
+[AT_DATA([[input.y]],
+[[$1
+%%
+exp:;
+]])
+AT_BISON_CHECK([[$2 input.y]], [[1]], [[]],
+[[$3: error: '%name-prefix' and '%define api.prefix' cannot be used together
+]])
+])
+
+AT_TEST([%define api.prefix foo %name-prefix "bar"], [], [input.y:1.9-18])
+AT_TEST([], [-Dapi.prefix=foo -p bar], [<command line>:1])
+AT_TEST([%name-prefix "bar"], [-Dapi.prefix=foo], [<command line>:1])
+AT_TEST([%define api.prefix foo], [-p bar], [input.y:1.9-18])
+
+m4_popdef([AT_TEST])
+
+AT_CLEANUP
+
+
+## -------------- ##
+## Stray $ or @. ##
+## -------------- ##
+
+AT_SETUP([[Stray $ or @]])
+
+# Give %printer and %destructor "<*> exp TOK" instead of "<*>" to
+# check that the warnings are reported once, not three times.
+
+AT_DATA_GRAMMAR([[input.y]],
+[[%token TOK
+%destructor { $%; @%; } <*> exp TOK;
+%initial-action { $%; @%; };
+%printer { $%; @%; } <*> exp TOK;
+%%
+exp: TOK { $%; @%; $$ = $1; };
+]])
+
+AT_BISON_CHECK([[input.y]], 0, [],
+[[input.y:10.19: warning: stray '$'
+input.y:10.23: warning: stray '@'
+input.y:11.19: warning: stray '$'
+input.y:11.23: warning: stray '@'
+input.y:12.19: warning: stray '$'
+input.y:12.23: warning: stray '@'
+input.y:14.19: warning: stray '$'
+input.y:14.23: warning: stray '@'
+]])
+
+AT_CLEANUP
+
+
+
+## ---------------- ##
+## Code injection. ##
+## ---------------- ##
+
+
+AT_SETUP([[Code injection]])
+
+m4_pattern_allow([^m4_errprintn$])
+
+# AT_TEST([MACRO])
+# ----------------
+# Try to have MACRO be run by bison.
+m4_pushdef([AT_TEST],
+[AT_DATA([[input.y]],
+[[%type <$1(DEAD %type)> exp
+%token <$1(DEAD %token)> a
+%initial-action
+{
+ $$;
+ $<$1(DEAD %initial-action)>$
+};
+%printer
+{
+ $$
+ $<$1(DEAD %printer)>$
+} <> <*>;
+%lex-param
+{
+ $1(DEAD %lex-param)
+};
+%parse-param
+{
+ $1(DEAD %parse-param)
+};
+%%
+exp:
+ a a[last]
+ {
+ $$;
+ $][1;
+ $<$1(DEAD action 1)>$
+ $<$1(DEAD action 2)>1
+ $<$1(DEAD action 3)>last
+ $<$1(DEAD action 4)>0
+ ;
+ };
+]])
+
+# FIXME: Provide a means to iterate over all the skeletons.
+AT_BISON_CHECK([[-d input.y]])
+AT_BISON_CHECK([[-d -S glr.c input.y]])
+AT_BISON_CHECK([[-d -S lalr1.cc input.y]])
+AT_BISON_CHECK([[-d -S glr.cc input.y]])
+AT_BISON_CHECK([[ -S lalr1.java input.y]])
+])
+
+AT_TEST([m4_errprintn])
+AT_TEST([@:>@m4_errprintn])
+
+m4_popdef([AT_TEST])
+
+AT_CLEANUP