+
+## ------------------------ ##
+## 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([-fcaret empty.y], [1], [],
+[[empty.y:2.8-9: warning: empty character literal [-Wother]
+ start: '';
+ ^^
+empty.y:3.8-4.0: error: missing "'" at end of line
+ start: '
+ ^
+empty.y:3.8-4.0: warning: empty character literal [-Wother]
+ start: '
+ ^
+empty.y:4.8: error: missing "'" at end of file
+ start: '
+ ^
+empty.y:4.8: warning: empty character literal [-Wother]
+ start: '
+ ^
+]])
+
+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 [-Wother]
+two.y:3.8-4.0: error: missing "'" at end of line
+two.y:3.8-4.0: warning: extra characters in character literal [-Wother]
+two.y:4.8-10: error: missing "'" at end of file
+two.y:4.8-10: warning: extra characters in character literal [-Wother]
+]])
+
+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 [-Wother]
+three.y:3.8-4.0: error: missing "'" at end of line
+three.y:3.8-4.0: warning: extra characters in character literal [-Wother]
+three.y:4.8-11: error: missing "'" at end of file
+three.y:4.8-11: warning: extra characters in character literal [-Wother]
+]])
+
+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 [-Wother]
+input.y:2.16-17: error: invalid number after \-escape: 0
+input.y:2.15-18: warning: empty character literal [-Wother]
+input.y:2.21-25: error: invalid number after \-escape: xfff
+input.y:2.20-26: warning: empty character literal [-Wother]
+input.y:2.29-31: error: invalid number after \-escape: x0
+input.y:2.28-32: warning: empty character literal [-Wother]
+input.y:3.9-14: error: invalid number after \-escape: uffff
+input.y:3.8-15: warning: empty character literal [-Wother]
+input.y:3.18-23: error: invalid number after \-escape: u0000
+input.y:3.17-24: warning: empty character literal [-Wother]
+input.y:3.27-36: error: invalid number after \-escape: Uffffffff
+input.y:3.26-37: warning: empty character literal [-Wother]
+input.y:3.40-49: error: invalid number after \-escape: U00000000
+input.y:3.39-50: warning: empty character literal [-Wother]
+input.y:4.9-10: error: invalid character after \-escape: ' '
+input.y:4.8-11: warning: empty character literal [-Wother]
+input.y:4.14-15: error: invalid character after \-escape: A
+input.y:4.13-16: warning: empty character literal [-Wother]
+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: %empty;
+]])
+
+# 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>:2: error: %define variable 'parse.lac.es-capacity-initial' is not used
+]])
+AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]],
+ [[1]], [],
+[[<command line>:2: error: %define variable 'parse.lac.memory-trace' is not used
+]])
+
+AT_CLEANUP
+
+## ---------------------- ##
+## -Werror combinations. ##
+## ---------------------- ##
+
+AT_SETUP([[-Werror combinations]])
+
+AT_DATA([[input.y]],
+[[%%
+a: '0' { $$ = $; };
+]])
+
+# -Werror is not enabled by -Wall or equivalent.
+AT_BISON_CHECK([[-Wall input.y]], [[0]], [[]],
+[[input.y:2.15: warning: stray '$' [-Wother]
+]])
+AT_BISON_CHECK([[-W input.y]], [[0]], [[]],
+[[input.y:2.15: warning: stray '$' [-Wother]
+]])
+AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]],
+[[input.y:2.15: warning: stray '$' [-Wother]
+]])
+
+# -Werror is not disabled by -Wnone or equivalent.
+AT_BISON_CHECK([[-Werror,none,other input.y]], [[1]], [[]],
+[[input.y:2.15: error: stray '$' [-Werror=other]
+]])
+AT_BISON_CHECK([[-Werror,no-all,other input.y]], [[1]], [[]],
+[[input.y:2.15: error: stray '$' [-Werror=other]
+]])
+
+# Check that -Wno-error keeps warnings enabled, but non fatal.
+AT_BISON_CHECK([[-Werror -Wno-error=other input.y]], [[0]], [[]],
+[[input.y:2.15: warning: stray '$' [-Wother]
+]])
+
+AT_BISON_CHECK([[-Wno-error=other -Werror input.y]], [[0]], [[]],
+[[input.y:2.15: warning: stray '$' [-Wother]
+]])
+
+AT_BISON_CHECK([[-Werror=other -Wno-other input.y]], [[0]], [[]],
+[[]])
+
+AT_CLEANUP
+
+
+## ------------------------------------------------------ ##
+## %name-prefix and %define api.prefix are incompatible. ##
+## ------------------------------------------------------ ##
+
+AT_SETUP([[%name-prefix and api.prefix are incompatible]])
+
+# AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
+# --------------------------------------------
+m4_pushdef([AT_TEST],
+[AT_DATA([[input.y]],
+[[$1
+%%
+exp: %empty;
+]])
+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>:2])
+AT_TEST([%name-prefix "bar"], [-Dapi.prefix={foo}], [<command line>:2])
+AT_TEST([%define api.prefix {foo}], [-p bar], [input.y:1.9-18])
+
+m4_popdef([AT_TEST])
+
+AT_CLEANUP
+
+
+## ----------------------- ##
+## Redefined %union name. ##
+## ----------------------- ##
+
+AT_SETUP([[Redefined %union name]])
+
+# AT_TEST(DIRECTIVES, ERROR)
+# --------------------------
+m4_pushdef([AT_TEST],
+[AT_DATA([[input.y]],
+[$1
+%%
+exp: %empty;
+])
+
+AT_BISON_CHECK([[input.y]], [[1]], [[]],
+[$2])
+])
+
+AT_TEST([[%union foo {};
+%union {};
+%union foo {};
+%define api.value.union.name foo]],
+[[input.y:3.8-10: error: %define variable 'api.value.union.name' redefined
+input.y:1.8-10: previous definition
+input.y:4.9-28: error: %define variable 'api.value.union.name' redefined
+input.y:3.8-10: previous definition
+]])
+
+AT_TEST([[%define api.value.union.name {foo}]],
+[[input.y:1.9-28: error: %define variable 'api.value.union.name' requires keyword values
+input.y:1.9-28: error: %define variable 'api.value.union.name' is not used
+]])
+
+AT_TEST([[%define api.value.union.name "foo"]],
+[[input.y:1.9-28: error: %define variable 'api.value.union.name' requires keyword values
+input.y:1.9-28: error: %define variable 'api.value.union.name' is not used
+]])
+
+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]],
+[[%type <TYPE> exp
+%token <TYPE> TOK TOK2
+%destructor { $%; @%; } <*> exp TOK;
+%initial-action { $%; @%; };
+%printer { $%; @%; } <*> exp TOK;
+%{ $ @ %} // Should not warn.
+%%
+exp: TOK { $%; @%; $$ = $1; };
+%%
+$ @ // Should not warn.
+]])
+
+AT_BISON_CHECK([[-Wall input.y]], 0, [],
+[[input.y:11.19: warning: stray '$' [-Wother]
+input.y:11.23: warning: stray '@' [-Wother]
+input.y:12.19: warning: stray '$' [-Wother]
+input.y:12.23: warning: stray '@' [-Wother]
+input.y:13.19: warning: stray '$' [-Wother]
+input.y:13.23: warning: stray '@' [-Wother]
+input.y:16.19: warning: stray '$' [-Wother]
+input.y:16.23: warning: stray '@' [-Wother]
+]])
+
+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
+%token b
+%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[name] b
+ {
+ $$;
+ $][1;
+ $<$1(DEAD action 1)>$
+ $<$1(DEAD action 2)>1
+ $<$1(DEAD action 3)>name
+ $<$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
+
+##----------------------- ##
+## Deprecated directives. ##
+## ---------------------- ##
+
+AT_SETUP([[Deprecated directives]])
+
+AT_KEYWORDS([[deprec]])
+
+AT_DATA_GRAMMAR([[input.y]],
+[[
+%default_prec
+%error_verbose
+%expect_rr 0
+%file-prefix = "foo"
+%file-prefix
+ =
+"bar"
+%fixed-output_files
+%fixed_output-files
+%fixed-output-files
+%name-prefix= "foo"
+%no-default_prec
+%no_default-prec
+%no_lines
+%output = "foo"
+%pure_parser
+%token_table
+%glr-parser
+%% exp : '0'
+]])
+
+AT_BISON_CHECK([[input.y]], [[0]], [[]],
+[[input.y:10.1-13: warning: deprecated directive: '%default_prec', use '%default-prec' [-Wdeprecated]
+input.y:11.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
+input.y:12.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
+input.y:13.1-14: warning: deprecated directive: '%file-prefix =', use '%file-prefix' [-Wdeprecated]
+input.y:14.1-15.2: warning: deprecated directive: '%file-prefix\n =', use '%file-prefix' [-Wdeprecated]
+input.y:17.1-19: warning: deprecated directive: '%fixed-output_files', use '%fixed-output-files' [-Wdeprecated]
+input.y:18.1-19: warning: deprecated directive: '%fixed_output-files', use '%fixed-output-files' [-Wdeprecated]
+input.y:20.1-13: warning: deprecated directive: '%name-prefix=', use '%name-prefix' [-Wdeprecated]
+input.y:21.1-16: warning: deprecated directive: '%no-default_prec', use '%no-default-prec' [-Wdeprecated]
+input.y:22.1-16: warning: deprecated directive: '%no_default-prec', use '%no-default-prec' [-Wdeprecated]
+input.y:23.1-9: warning: deprecated directive: '%no_lines', use '%no-lines' [-Wdeprecated]
+input.y:24.1-9: warning: deprecated directive: '%output =', use '%output' [-Wdeprecated]
+input.y:25.1-12: warning: deprecated directive: '%pure_parser', use '%pure-parser' [-Wdeprecated]
+input.y:26.1-12: warning: deprecated directive: '%token_table', use '%token-table' [-Wdeprecated]
+]])
+
+AT_CLEANUP
+
+## ---------------------------- ##
+## Unput's effect on locations. ##
+## ---------------------------- ##
+dnl When the scanner detects a deprecated construct, it unputs the correct
+dnl version, but it should *not* have any impact on the scanner cursor. If it
+dnl does, the locations of directives on the same line become erroneous.
+
+AT_SETUP([[Unput's effect on locations]])
+
+AT_KEYWORDS([[deprec]])
+
+AT_DATA_GRAMMAR([[input.y]],
+[[
+%glr-parser
+%expect_rr 42 %expect_rr 42
+ %expect_rr 42
+%error_verbose %error_verbose
+ %error_verbose
+%% exp: '0'
+]])
+
+AT_BISON_CHECK([[input.y]], [[1]], [[]],
+[[input.y:11.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
+input.y:11.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
+input.y:12.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
+input.y:13.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
+input.y:13.16-29: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
+input.y:13.11-21: error: %define variable 'parse.error' redefined
+input.y:13-6: previous definition
+input.y:14.16-29: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
+input.y:14.11-21: error: %define variable 'parse.error' redefined
+input.y:13.11-21: previous definition
+]])
+
+AT_CLEANUP
+
+##--------------------------- ##
+## Non-deprecated directives. ##
+## -------------------------- ##
+
+AT_SETUP([[Non-deprecated directives]])
+
+AT_KEYWORDS([[deprec]])
+
+AT_DATA_GRAMMAR([[input.y]],
+[[
+%default-prec
+%error-verbose
+%expect-rr 42
+%file-prefix "foo"
+%file-prefix
+"bar"
+%fixed-output-files
+%name-prefix "foo"
+%no-default-prec
+%no-lines
+%output "foo"
+%pure-parser
+%token-table
+%% exp : '0'
+]])
+
+AT_BISON_CHECK([[input.y]], [[0]], [[]],
+[[input.y: warning: %expect-rr applies only to GLR parsers [-Wother]
+]])
+
+AT_CLEANUP