X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/b506d9bfcb9e96d07264a43da7bdf136329dbc86..505ece51710209eb4aba50166f8f7ddc57d0562b:/tests/input.at diff --git a/tests/input.at b/tests/input.at index 86a955dc..cd0dd6ac 100644 --- a/tests/input.at +++ b/tests/input.at @@ -20,6 +20,63 @@ 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-2: error: invalid characters: '\0\001\002\377?' +input.y:3.1: error: invalid character: '?' +input.y:4.14: error: invalid character: '}' +input.y:5.1: error: invalid character: '%' +input.y:5.2: error: invalid character: '&' +input.y:6.1-17: error: invalid directive: '%a-does-not-exist' +input.y:7.1: error: invalid character: '%' +input.y:7.2: error: invalid character: '-' +input.y:8.1-9.0: error: missing '%}' at end of file +input.y:8.1-9.0: error: 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: error: syntax error, unexpected %initial-action, expecting {...} +]]) + +AT_CLEANUP + + + ## ------------ ## ## Invalid $n. ## ## ------------ ## @@ -756,6 +813,25 @@ input.y:19.13-20.0: error: missing '}' at end of file input.y:20.1: error: syntax error, unexpected end of file ]]) +AT_BISON_CHECK([-fcaret -o input.c input.y], 1, [], +[[input.y:1.10-2.0: error: missing '"' at end of line + %token A "a + ^^ +input.y:4.10-5.0: error: missing "'" at end of line + %token C '1 + ^^ +input.y:14.11-15.0: error: missing "'" at end of line + %type 'a + ^^ +input.y:16.11-17.0: error: missing '"' at end of line + %type "a + ^^ +input.y:19.13-20.0: error: missing '}' at end of file + %destructor { free ($$) + ^^^^^^^^^^^ +input.y:20.1: error: syntax error, unexpected end of file +]]) + AT_CLEANUP @@ -985,6 +1061,18 @@ start: ; ]]) AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [], [[input-dg.y:1.9-11: error: %define variable 'var' redefined +:1: previous definition +]]) + +AT_DATA([[input-dg.y]], +[[%define var "gram" +%% +start: ; +]]) +AT_BISON_CHECK([[-fcaret -Dvar=cmd-d input-dg.y]], [[1]], [], +[[input-dg.y:1.9-11: error: %define variable 'var' redefined + %define var "gram" + ^^^ :2: previous definition ]]) @@ -993,8 +1081,8 @@ AT_DATA([[input-unused.y]], start: ; ]]) AT_BISON_CHECK([[-Dunused-d -Funused-f input-unused.y]], [[1]], [], -[[:2: error: %define variable 'unused-d' is not used -:3: error: %define variable 'unused-f' is not used +[[:1: error: %define variable 'unused-d' is not used +:2: error: %define variable 'unused-f' is not used ]]) AT_CLEANUP @@ -1195,7 +1283,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 @@ -1210,7 +1298,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 @@ -1225,7 +1313,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 @@ -1254,7 +1342,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], [], @@ -1300,11 +1388,11 @@ start: ; # parse.lac.* options are useless if LAC isn't actually activated. AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]], [[1]], [], -[[:2: error: %define variable 'parse.lac.es-capacity-initial' is not used +[[:1: error: %define variable 'parse.lac.es-capacity-initial' is not used ]]) AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]], [[1]], [], -[[:2: error: %define variable 'parse.lac.memory-trace' is not used +[[:1: error: %define variable 'parse.lac.memory-trace' is not used ]]) AT_CLEANUP @@ -1363,8 +1451,8 @@ AT_BISON_CHECK([[$2 input.y]], [[1]], [[]], ]) AT_TEST([%define api.prefix foo %name-prefix "bar"], [], [input.y:1.9-18]) -AT_TEST([], [-Dapi.prefix=foo -p bar], [:2]) -AT_TEST([%name-prefix "bar"], [-Dapi.prefix=foo], [:2]) +AT_TEST([], [-Dapi.prefix=foo -p bar], [:1]) +AT_TEST([%name-prefix "bar"], [-Dapi.prefix=foo], [:1]) AT_TEST([%define api.prefix foo], [-p bar], [input.y:1.9-18]) m4_popdef([AT_TEST])