# Mostly test that we are robust to mistakes.
+## ---------------- ##
+## Invalid inputs. ##
+## ---------------- ##
+
+AT_SETUP([Invalid inputs])
+
+AT_DATA([input.y],
+[[\000\001\002\377?
+%%
+?
+default: 'a' }
+%&
+%a-does-not-exist
+%-
+%{
+]])
+AT_CHECK([[$PERL -pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y || exit 77]])
+
+AT_BISON_CHECK([input.y], [1], [],
+[[input.y:1.1: invalid character: '\0'
+input.y:1.1: invalid character: '\001'
+input.y:1.1: invalid character: '\002'
+input.y:1.1: invalid character: '\377'
+input.y:1.2: invalid character: '?'
+input.y:3.1: invalid character: '?'
+input.y:4.14: invalid character: '}'
+input.y:5.1: invalid character: '%'
+input.y:5.2: invalid character: '&'
+input.y:6.1-17: invalid directive: '%a-does-not-exist'
+input.y:7.1: invalid character: '%'
+input.y:7.2: invalid character: '-'
+input.y:8.1-9.0: missing '%}' at end of file
+input.y:8.1-9.0: syntax error, unexpected %{...%}
+]])
+
+AT_CLEANUP
+
+
+AT_SETUP([Invalid inputs with {}])
+
+# We used to SEGV here. See
+# http://lists.gnu.org/archive/html/bug-bison/2005-07/msg00053.html
+
+AT_DATA([input.y],
+[[
+%destructor
+%initial-action
+%lex-param
+%parse-param
+%printer
+%union
+]])
+
+AT_BISON_CHECK([input.y], [1], [],
+[[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...}
+]])
+
+AT_CLEANUP
+
+
+
## ------------ ##
## Invalid $n. ##
## ------------ ##
# _AT_UNUSED_VALUES_DECLARATIONS()
-# --------------------------------------------
+# --------------------------------
# Generate the token, type, and destructor
# declarations for the unused values tests.
#include <stdio.h>
#include <stdlib.h>
+#include <assert.h>
%}
/* %{ and %} can be here too. */
#output "; /* "
*/
static size_t toknum;
- if (! (toknum < sizeof input))
- abort ();
+ assert (toknum < sizeof input);
yylval = value_as_yystype (input[toknum]);
return input[toknum++];
}
start: '';
start: '
]])
-AT_CHECK([[perl -e "print 'start: \'';" >> empty.y || exit 77]])
+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
start: 'ab';
start: 'ab
]])
-AT_CHECK([[perl -e "print 'start: \'ab';" >> two.y || exit 77]])
+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
start: 'abc';
start: 'abc
]])
-AT_CHECK([[perl -e "print 'start: \'abc';" >> three.y || exit 77]])
+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
# 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 \
+AT_CHECK([[$PERL -e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y \
|| exit 77]])
AT_BISON_CHECK([input.y], [1], [],
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: '%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
+
+
+## -------------- ##
+## 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