]>
Commit | Line | Data |
---|---|---|
9b2d0677 | 1 | # Checking the output filenames. -*- Autotest -*- |
6c35d22c | 2 | # Copyright (C) 2002 Free Software Foundation, Inc. |
9b2d0677 AD |
3 | |
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 2, or (at your option) | |
7 | # any later version. | |
8 | ||
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | ||
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
17 | # 02111-1307, USA. | |
18 | ||
19 | AT_BANNER([[Input Processing.]]) | |
20 | ||
21 | # Mostly test that we are robust to mistakes. | |
22 | ||
6c35d22c | 23 | |
9b2d0677 AD |
24 | ## ------------ ## |
25 | ## Invalid $n. ## | |
26 | ## ------------ ## | |
27 | ||
9b2d0677 AD |
28 | AT_SETUP([Invalid $n]) |
29 | ||
30 | AT_DATA([input.y], | |
31 | [[%% | |
bfcf1f3a | 32 | exp: { $$ = $1 ; }; |
9b2d0677 AD |
33 | ]]) |
34 | ||
35 | AT_CHECK([bison input.y], [1], [], | |
c4d720cd | 36 | [[input.y:2.6-14: invalid value: `$1' |
9b2d0677 AD |
37 | ]]) |
38 | ||
39 | AT_CLEANUP | |
40 | ||
41 | ||
42 | ## ------------ ## | |
43 | ## Invalid @n. ## | |
44 | ## ------------ ## | |
45 | ||
9b2d0677 AD |
46 | AT_SETUP([Invalid @n]) |
47 | ||
48 | AT_DATA([input.y], | |
49 | [[%% | |
bfcf1f3a | 50 | exp: { @$ = @1 ; }; |
9b2d0677 AD |
51 | ]]) |
52 | ||
53 | AT_CHECK([bison input.y], [1], [], | |
c4d720cd | 54 | [[input.y:2.6-14: invalid value: `@1' |
9b2d0677 AD |
55 | ]]) |
56 | ||
57 | AT_CLEANUP | |
9af3fbce AD |
58 | |
59 | ||
60 | ## -------------- ## | |
e776192e | 61 | ## Type Clashes. ## |
9af3fbce AD |
62 | ## -------------- ## |
63 | ||
e776192e | 64 | AT_SETUP([Type Clashes]) |
9af3fbce AD |
65 | |
66 | AT_DATA([input.y], | |
67 | [[%token foo | |
68 | %type <bar> exp | |
69 | %% | |
70 | exp: foo {} foo | |
71 | | foo | |
72 | | /* Empty. */ | |
73 | ; | |
74 | ]]) | |
75 | ||
76 | AT_CHECK([bison input.y], [1], [], | |
baa00b7f PE |
77 | [[input.y:4.4-15: type clash on default action: <bar> != <> |
78 | input.y:5.4-8: type clash on default action: <bar> != <> | |
e776192e | 79 | input.y:6.4: empty rule for typed nonterminal, and no action |
9af3fbce AD |
80 | ]]) |
81 | ||
82 | AT_CLEANUP | |
5a08f1ce AD |
83 | |
84 | ||
85 | ||
86 | ## ----------------------- ## | |
87 | ## Torturing the Scanner. ## | |
88 | ## ----------------------- ## | |
89 | ||
90 | # Be sure to compile and run, so that the C compiler checks what | |
91 | # we do. | |
92 | ||
93 | AT_SETUP([Torturing the Scanner]) | |
94 | ||
95 | AT_DATA([input.y], | |
96 | [[%{ | |
97 | /* This is seen in GCC: a %{ and %} in middle of a comment. */ | |
98 | const char *foo = "So %{ and %} can be here too."; | |
99 | ||
206fe6a5 PE |
100 | #ifdef __STDC__ |
101 | /\ | |
102 | * A comment with backslash-newlines in it. %{ %} *\ | |
103 | \ | |
104 | / | |
105 | ||
106 | char str[] = "\\ | |
107 | " A string with backslash-newlines in it %{ %} \\ | |
108 | ""; | |
109 | ||
110 | char apostrophe = '\\ | |
111 | \ | |
112 | '\ | |
113 | '; | |
114 | #endif | |
115 | ||
5a08f1ce AD |
116 | #include <stdio.h> |
117 | %} | |
118 | /* %{ and %} can be here too. */ | |
119 | ||
120 | %{ | |
121 | /* Exercise pre-prologue dependency to %union. */ | |
122 | typedef int value_t; | |
123 | %} | |
124 | ||
125 | /* Exercise M4 quoting: '@:>@@:>@', 0. */ | |
126 | ||
127 | /* Also exercise %union. */ | |
128 | %union | |
129 | { | |
130 | value_t ival; /* A comment to exercise an old bug. */ | |
131 | }; | |
132 | ||
133 | ||
134 | /* Exercise post-prologue dependency to %union. */ | |
135 | %{ | |
136 | static YYSTYPE value_t_as_yystype (value_t val); | |
137 | ||
138 | /* Exercise quotes in declarations. */ | |
139 | char quote[] = "@:>@@:>@,"; | |
140 | %} | |
141 | ||
142 | %{ | |
143 | static void yyerror (const char *s); | |
144 | static int yylex (void); | |
145 | %} | |
146 | ||
206fe6a5 | 147 | %type <ival> '@<:@' |
5a08f1ce AD |
148 | |
149 | /* Exercise quotes in strings. */ | |
206fe6a5 | 150 | %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x0\0" |
5a08f1ce AD |
151 | |
152 | %% | |
206fe6a5 PE |
153 | /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */ |
154 | exp: '@<:@' '\1' '\x000000000000000000000000000000000000000000000000002' | |
5a08f1ce AD |
155 | { |
156 | /* Exercise quotes in braces. */ | |
157 | char tmp[] = "@<:@%c@:>@,\n"; | |
158 | printf (tmp, $1); | |
159 | } | |
160 | ; | |
161 | %% | |
206fe6a5 | 162 | /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */ |
5a08f1ce AD |
163 | |
164 | static YYSTYPE | |
165 | value_t_as_yystype (value_t val) | |
166 | { | |
167 | YYSTYPE res; | |
168 | res.ival = val; | |
169 | return res; | |
170 | } | |
171 | ||
172 | static int | |
173 | yylex (void) | |
174 | { | |
206fe6a5 | 175 | static const char *input = "@<:@\1\2"; |
5a08f1ce AD |
176 | yylval = value_t_as_yystype (*input); |
177 | return *input++; | |
178 | } | |
179 | ||
180 | static void | |
181 | yyerror (const char *msg) | |
182 | { | |
183 | fprintf (stderr, "%s\n", msg); | |
184 | } | |
185 | ]]) | |
186 | ||
187 | AT_DATA([main.c], | |
188 | [[typedef int value_t; | |
189 | #include "input.h" | |
190 | ||
191 | int yyparse (void); | |
192 | ||
193 | int | |
194 | main (void) | |
195 | { | |
196 | return yyparse (); | |
197 | } | |
198 | ]]) | |
199 | ||
b56471a6 | 200 | AT_CHECK([bison -d -v -o input.c input.y]) |
1154cced AD |
201 | AT_COMPILE([input], [input.c main.c]) |
202 | AT_PARSER_CHECK([./input], 0, | |
206fe6a5 | 203 | [[[@<:@], |
5a08f1ce AD |
204 | ]]) |
205 | ||
206 | AT_CLEANUP |