X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/32ae07efde7db078d48e95f29778e2227b0cf01b..5a000c51f7ca10071adea389cb32885a92dd852f:/tests/input.at diff --git a/tests/input.at b/tests/input.at index 836ff6d6..2848562d 100644 --- a/tests/input.at +++ b/tests/input.at @@ -20,6 +20,67 @@ AT_BANNER([[Input Processing.]]) # 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. ## ## ------------ ## @@ -1194,7 +1255,7 @@ AT_DATA([empty.y], 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 @@ -1209,7 +1270,7 @@ AT_DATA([two.y], 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 @@ -1224,7 +1285,7 @@ AT_DATA([three.y], 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 @@ -1253,7 +1314,7 @@ start: '\777' '\0' '\xfff' '\x0' # 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], [], @@ -1369,3 +1430,100 @@ 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