1 # Checking diagnostics. -*- Autotest -*-
3 # Copyright (C) 2019-2021 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
18 AT_BANNER([[Diagnostics.]])
21 # AT_TEST($1: TITLE, $2: GRAMMAR, $3: EXIT-STATUS, $4: OUTPUT-WITH-STYLE,
22 # $5: EXTRA_ENV, $6: SKIP-IF)
23 # -----------------------------------------------------------------------
24 # Run Bison on GRAMMAR with debugging style enabled, and expect
25 # OUTPUT-WITH-STYLE as diagnostics.
29 AT_KEYWORDS([diagnostics])
31 m4_if(m4_index([$1], [Counterexample]), [-1], [], [AT_KEYWORDS([cex])])
33 # We need UTF-8 support for correct screen-width computation of UTF-8
34 # characters. Skip the test if not available.
35 locale=`locale -a | $EGREP '^en_US\.(UTF-8|utf8)$' | sed 1q`
36 AT_SKIP_IF([[test x = x"$locale"]])
41 AT_BISON_OPTION_PUSHDEFS
43 AT_DATA_GRAMMAR([[input.y]], [$2])
45 AT_DATA([experr], [$4])
47 # For some reason, literal ^M in the input are removed and don't end
48 # in `input.y`. So use the two-character ^M represent it, and let
49 # Perl insert real CR characters.
50 if $EGREP ['\^M|\\[0-9][0-9][0-9]'] input.y experr >/dev/null; then
51 AT_PERL_REQUIRE([-pi -e 's{\^M}{\r}g;s{\\(\d{3}|.)}{$v = $[]1; $v =~ /\A\d+\z/ ? chr($v) : $v}ge' input.y experr])
54 AT_CHECK(AT_SET_ENV [LC_ALL="$locale" $5 bison -fcaret --color=debug -Wall,cex input.y], [$3], [], [experr])
56 # When no style, same messages, but without style.
57 # Except for the second display of the counterexample,
58 # which is not displayed at all.
59 AT_PERL_REQUIRE([-pi -e '
60 s{(</?(-|\w)+>)}{ $[]1 eq "<tag>" ? $[]1 : "" }ge;
64 $_ = "" if $example % 2 == 0;
68 # Cannot use AT_BISON_CHECK easily as we need to change the
70 # FIXME: Enhance AT_BISON_CHECK.
71 AT_CHECK(AT_SET_ENV [LC_ALL="$locale" $5 bison -fcaret -Wall,cex input.y], [$3], [], [experr])
74 AT_BISON_OPTION_POPDEFS
91 [[input.y:9.12-14: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
92 9 | %token FOO <warning>FOO</warning> FOO
93 | <warning>^~~</warning>
94 input.y:9.8-10: <note>note:</note> previous declaration
95 9 | %token <note>FOO</note> FOO FOO
97 input.y:9.16-18: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
98 9 | %token FOO FOO <warning>FOO</warning>
99 | <warning>^~~</warning>
100 input.y:9.8-10: <note>note:</note> previous declaration
101 9 | %token <note>FOO</note> FOO FOO
103 input.y:10.8-10: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
104 10 | %token <warning>FOO</warning> FOO FOO
105 | <warning>^~~</warning>
106 input.y:9.8-10: <note>note:</note> previous declaration
107 9 | %token <note>FOO</note> FOO FOO
109 input.y:10.13-15: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
110 10 | %token FOO <warning>FOO</warning> FOO
111 | <warning>^~~</warning>
112 input.y:9.8-10: <note>note:</note> previous declaration
113 9 | %token <note>FOO</note> FOO FOO
115 input.y:10.18-20: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
116 10 | %token FOO FOO <warning>FOO</warning>
117 | <warning>^~~</warning>
118 input.y:9.8-10: <note>note:</note> previous declaration
119 9 | %token <note>FOO</note> FOO FOO
124 ## ------------------------ ##
125 ## Single point locations. ##
126 ## ------------------------ ##
128 # Single point locations (equal boundaries) are troublesome: it's easy
129 # to mess up the opening/closing of style. They come from the parser,
130 # rules with empty rhs. Their position is therefore debatable
131 # (between the previous token and the next one).
133 AT_TEST([[Single point locations]],
145 [[input.y:11.4-5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
146 11 | a: <warning>{}</warning>
147 | <warning>^~</warning>
148 | <fixit-insert>%empty</fixit-insert>
149 input.y:12.3-13.1: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
150 12 | b:<warning>{</warning>
151 | <warning>^</warning>
152 | <fixit-insert>%empty</fixit-insert>
153 input.y:14.3: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
155 | <warning>^</warning>
156 | <fixit-insert>%empty</fixit-insert>
157 input.y:16.2: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
159 | <warning>^</warning>
160 | <fixit-insert>%empty</fixit-insert>
161 input.y:17.3: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
163 | <warning>^</warning>
164 | <fixit-insert>%empty</fixit-insert>
165 input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
170 ## ------------------------------------- ##
171 ## Line is too short, and then you die. ##
172 ## ------------------------------------- ##
174 # We trust the "#line", since that's what allows us to quote the
175 # actual source from which the grammar file was generated. But #line
176 # can also be wrong, and point to a line which is shorter that the bad
177 # one. In which case we can easily forget to close the styling.
179 # Be sure to have #line point to a line long enough to open the
180 # styling, but not enough to close it.
182 AT_TEST([[Line is too short, and then you die]],
183 [[// Beware that there are 9 lines inserted before (including this one).
192 [[input.y:13.8-10: <warning>warning:</warning> symbol foo redeclared [<warning>-Wother</warning>]
193 13 | %token <warning>foo</warning> 123
194 | <warning>^~~</warning>
195 input.y:12.8-10: <note>note:</note> previous declaration
196 12 | %token <note>foo</note> 123123
198 input.y:13.12-17: <error>error:</error> redefining code of token foo
199 13 | %token foo <error>123</error>
200 | <error>^~~~~~</error>
201 input.y:14.8-10: <warning>warning:</warning> symbol foo redeclared [<warning>-Wother</warning>]
203 | <warning>^~~</warning>
204 input.y:12.8-10: <note>note:</note> previous declaration
205 12 | %token <note>foo</note> 123123
210 ## ----------------------- ##
211 ## Zero-width characters. ##
212 ## ----------------------- ##
214 # We used to open twice the styling for characters that have a
215 # zero-width on display (e.g., \005).
217 AT_TEST([[Zero-width characters]],
222 [[input.y:10.8: <error>error:</error> invalid character: '\\005'
223 10 | exp: an<error>\005</error>error.
228 ## -------------------------------------- ##
229 ## Tabulations and multibyte characters. ##
230 ## -------------------------------------- ##
232 # Make sure we treat tabulations as eight spaces, and that multibyte
233 # characters have correct width.
235 AT_TEST([[Tabulations and multibyte characters]],
247 [[input.y:11.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
248 11 | a: <warning>{ }</warning>
249 | <warning>^~~~~~~~~~~~~~</warning>
250 | <fixit-insert>%empty</fixit-insert>
251 input.y:12.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
252 12 | b: <warning>{ }</warning>
253 | <warning>^~~~~~~~~~~~~~</warning>
254 | <fixit-insert>%empty</fixit-insert>
255 input.y:13.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
256 13 | c: <warning>{------------}</warning>
257 | <warning>^~~~~~~~~~~~~~</warning>
258 | <fixit-insert>%empty</fixit-insert>
259 input.y:14.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
260 14 | d: <warning>{éééééééééééé}</warning>
261 | <warning>^~~~~~~~~~~~~~</warning>
262 | <fixit-insert>%empty</fixit-insert>
263 input.y:15.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
264 15 | e: <warning>{ 42 }</warning>
265 | <warning>^~~~~~~~~~~~~~</warning>
266 | <fixit-insert>%empty</fixit-insert>
267 input.y:16.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
268 16 | f: <warning>{ "฿¥$€₦" }</warning>
269 | <warning>^~~~~~~~~~~~~~</warning>
270 | <fixit-insert>%empty</fixit-insert>
271 input.y:17.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
272 17 | g: <warning>{ 🐃 }</warning>
273 | <warning>^~~~~~~~~~~~~~</warning>
274 | <fixit-insert>%empty</fixit-insert>
275 input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
279 # Likewise, but currently not portable to AIX and Cygwin.
280 # https://lists.gnu.org/r/bug-bison/2020-05/msg00050.html
281 # https://lists.gnu.org/r/bug-bison/2020-05/msg00003.html.
282 AT_TEST([[Tabulations and multibyte characters]],
287 [[input.y:10.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
288 10 | e: <warning>{∇⃗×𝐸⃗ = -∂𝐵⃗/∂t}</warning>
289 | <warning>^~~~~~~~~~~~~~</warning>
290 | <fixit-insert>%empty</fixit-insert>
291 input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
292 ]], [], [uname -a | $EGREP -i 'aix|cygwin'])
295 ## --------------- ##
297 ## --------------- ##
299 # Don't try to quote special files.
300 # https://lists.gnu.org/r/bug-bison/2019-04/msg00000.html
301 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90034
303 AT_TEST([[Special files]],
307 #line 1 "/dev/stdout"
311 [[input.y:11.4-5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
312 11 | a: <warning>{}</warning>
313 | <warning>^~</warning>
314 | <fixit-insert>%empty</fixit-insert>
315 /dev/stdout:1.4-5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
316 | <fixit-insert>%empty</fixit-insert>
317 input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
321 ## -------------------- ##
322 ## Complaints from M4. ##
323 ## -------------------- ##
325 # Complaints issued m4 need complete locations (byte and column) for
328 AT_TEST([[Complaints from M4]],
335 [[input.y:9.1-27: <error>error:</error> %define variable 'error1' is not used
336 9 | <error>%define error1 {e}</error>
337 | <error>^~~~~~~~~~~~~~~~~~~~~~~~~~~</error>
338 input.y:10.1-27: <error>error:</error> %define variable 'error2' is not used
339 10 | <error>%define error2 {é}</error>
340 | <error>^~~~~~~~~~~~~~~~~~~~~~~~~~~</error>
344 ## ----------------- ##
345 ## Carriage return. ##
346 ## ----------------- ##
348 # Carriage-return used to count as a newline in the scanner, and not
349 # in diagnostics. Resulting in all kinds of nice bugs.
351 AT_TEST([[Carriage return]],
352 [[^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M
357 [[input.y:10.8-11.0: <error>error:</error> missing '"' at end of line
358 10 | %token <error>"</error>
360 input.y:10.8-11.0: <error>error:</error> expected <expected>character literal</expected> or <expected>identifier</expected> or <expected><tag></expected> before <unexpected>string</unexpected>
361 10 | %token <error>"</error>
370 # Check Windows EOLs.
380 [[input.y:11.9-11: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
381 11 | %token
\r <warning>FOO</warning>
382 | <warning>^~~</warning>
383 input.y:10.9-11: <note>note:</note> previous declaration
384 10 | %token
\r <note>FOO</note>
386 input.y:13.5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
388 | <warning>^</warning>
389 | <fixit-insert>%empty</fixit-insert>
390 input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
399 AT_TEST([[Screen width: 200 columns]],
400 [[%token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
403 exp: ABCDEFGHIJKLMNOPQRSTUVWXYZ
406 [[input.y:9.36-61: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
407 9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
408 | <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
409 input.y:9.8-33: <note>note:</note> previous declaration
410 9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
411 | <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
412 input.y:9.64-89: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
413 9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning> ABCDEFGHIJKLMNOPQRSTUVWXYZ
414 | <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
415 input.y:9.8-33: <note>note:</note> previous declaration
416 9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
417 | <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
418 input.y:9.92-117: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
419 9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning>
420 | <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
421 input.y:9.8-33: <note>note:</note> previous declaration
422 9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
423 | <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
424 input.y:10.56-69: <warning>warning:</warning> deprecated directive: '%error-verbose', use '%define parse.error verbose' [<warning>-Wdeprecated</warning>]
425 10 | <warning>%error-verbose</warning>
426 | <warning>^~~~~~~~~~~~~~</warning>
427 | <fixit-insert>%define parse.error verbose</fixit-insert>
428 input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
432 AT_TEST([[Screen width: 80 columns]],
433 [[%token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
436 exp: ABCDEFGHIJKLMNOPQRSTUVWXYZ
439 [[input.y:9.36-61: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
440 9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning> ABCDEF...
441 | <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
442 input.y:9.8-33: <note>note:</note> previous declaration
443 9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEF...
444 | <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
445 input.y:9.64-89: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
446 9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEF</warning>...
447 | <warning>^~~~~~</warning>
448 input.y:9.8-33: <note>note:</note> previous declaration
449 9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEF...
450 | <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
451 input.y:9.92-117: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
452 9 | ...TUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning>
453 | <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
454 input.y:9.8-33: <note>note:</note> previous declaration
455 9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEF...
456 | <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
457 input.y:10.56-69: <warning>warning:</warning> deprecated directive: '%error-verbose', use '%define parse.error verbose' [<warning>-Wdeprecated</warning>]
458 10 | <warning>%error-verbose</warning>
459 | <warning>^~~~~~~~~~~~~~</warning>
460 | <fixit-insert>%define parse.error verbose</fixit-insert>
461 input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
465 AT_TEST([[Screen width: 60 columns]],
466 [[%token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
469 exp: ABCDEFGHIJKLMNOPQRSTUVWXYZ
472 [[input.y:9.36-61: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
473 9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMN</warning>...
474 | <warning>^~~~~~~~~~~~~~</warning>
475 input.y:9.8-33: <note>note:</note> previous declaration
476 9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMN...
477 | <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
478 input.y:9.64-89: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
479 9 | ...TUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning> ABCDEFGHI...
480 | <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
481 input.y:9.8-33: <note>note:</note> previous declaration
482 9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMN...
483 | <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
484 input.y:9.92-117: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
485 9 | ...TUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning>
486 | <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
487 input.y:9.8-33: <note>note:</note> previous declaration
488 9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMN...
489 | <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
490 input.y:10.56-69: <warning>warning:</warning> deprecated directive: '%error-verbose', use '%define parse.error verbose' [<warning>-Wdeprecated</warning>]
491 10 | ... <warning>%error-verbose</warning>
492 | <warning>^~~~~~~~~~~~~~</warning>
493 | <fixit-insert>%define parse.error verbose</fixit-insert>
494 input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
503 # Don't suggest to fix QUX with QUUX and QUUX with QUX...
504 AT_TEST([[Suggestions]],
510 [[input.y:10.6-8: <error>error:</error> symbol 'QUX' is used, but is not defined as a token and has no rules
511 10 | res: <error>QUX</error> baz
513 input.y:10.10-12: <error>error:</error> symbol 'baz' is used, but is not defined as a token and has no rules; did you mean 'bar'?
514 10 | res: QUX <error>baz</error>
516 | <fixit-insert>bar</fixit-insert>
517 input.y:11.6-9: <error>error:</error> symbol 'QUUX' is used, but is not defined as a token and has no rules
518 11 | bar: <error>QUUX</error>
519 | <error>^~~~</error>
523 ## ----------------- ##
524 ## Counterexamples. ##
525 ## ----------------- ##
527 AT_TEST([[Counterexamples]],
531 : "if" exp "then" exp
532 | "if" exp "then" exp "else" exp
542 [[input.y: <error>error:</error> shift/reduce conflicts: 9 found, 0 expected
543 input.y: <warning>warning:</warning> shift/reduce conflict on token "a" [<warning>-Wcounterexamples</warning>]
544 Example: <cex-0><cex-dot>•</cex-dot> <cex-leaf>"a"</cex-leaf><cex-1></cex-1></cex-0>
546 <cex-0><cex-step>exp</cex-step></cex-0>
547 <cex-0><cex-step>↳ 6: <cex-dot>•</cex-dot><cex-leaf> "a"</cex-leaf><cex-1><cex-step> empty</cex-step></cex-1></cex-step></cex-0>
548 <cex-1><cex-step> ↳ 6: ε</cex-step></cex-1>
549 Example: <cex-0><cex-1><cex-dot>•</cex-dot></cex-1> <cex-leaf>"a"</cex-leaf></cex-0>
551 <cex-0><cex-step>exp</cex-step></cex-0>
552 <cex-0><cex-step>↳ 5: <cex-1><cex-step>empty</cex-step></cex-1><cex-leaf> "a"</cex-leaf></cex-step></cex-0>
553 <cex-1><cex-step> ↳ 7: ε<cex-dot> •</cex-dot></cex-step></cex-1>
554 input.y: <warning>warning:</warning> shift/reduce conflict on token "a" [<warning>-Wcounterexamples</warning>]
555 Example: <cex-0><cex-dot>•</cex-dot> <cex-leaf>"a"</cex-leaf><cex-1></cex-1></cex-0>
557 <cex-0><cex-step>exp</cex-step></cex-0>
558 <cex-0><cex-step>↳ 6: <cex-dot>•</cex-dot><cex-leaf> "a"</cex-leaf><cex-1><cex-step> empty</cex-step></cex-1></cex-step></cex-0>
559 <cex-1><cex-step> ↳ 6: ε</cex-step></cex-1>
560 Example: <cex-0><cex-1><cex-dot>•</cex-dot></cex-1> <cex-leaf>"a"</cex-leaf></cex-0>
562 <cex-0><cex-step>exp</cex-step></cex-0>
563 <cex-0><cex-step>↳ 5: <cex-1><cex-step>empty</cex-step></cex-1><cex-leaf> "a"</cex-leaf></cex-step></cex-0>
564 <cex-1><cex-step> ↳ 7: ε<cex-dot> •</cex-dot></cex-step></cex-1>
565 input.y: <warning>warning:</warning> shift/reduce conflict on token "a" [<warning>-Wcounterexamples</warning>]
566 Example: <cex-0><cex-dot>•</cex-dot> <cex-leaf>"a"</cex-leaf><cex-1></cex-1></cex-0>
568 <cex-0><cex-step>exp</cex-step></cex-0>
569 <cex-0><cex-step>↳ 6: <cex-dot>•</cex-dot><cex-leaf> "a"</cex-leaf><cex-1><cex-step> empty</cex-step></cex-1></cex-step></cex-0>
570 <cex-1><cex-step> ↳ 6: ε</cex-step></cex-1>
571 Example: <cex-0><cex-1><cex-dot>•</cex-dot></cex-1> <cex-leaf>"a"</cex-leaf></cex-0>
573 <cex-0><cex-step>exp</cex-step></cex-0>
574 <cex-0><cex-step>↳ 5: <cex-1><cex-step>empty</cex-step></cex-1><cex-leaf> "a"</cex-leaf></cex-step></cex-0>
575 <cex-1><cex-step> ↳ 7: ε<cex-dot> •</cex-dot></cex-step></cex-1>
576 input.y: <warning>warning:</warning> shift/reduce conflict on token "a" [<warning>-Wcounterexamples</warning>]
577 Example: <cex-0><cex-dot>•</cex-dot> <cex-leaf>"a"</cex-leaf><cex-1></cex-1></cex-0>
579 <cex-0><cex-step>exp</cex-step></cex-0>
580 <cex-0><cex-step>↳ 6: <cex-dot>•</cex-dot><cex-leaf> "a"</cex-leaf><cex-1><cex-step> empty</cex-step></cex-1></cex-step></cex-0>
581 <cex-1><cex-step> ↳ 6: ε</cex-step></cex-1>
582 Example: <cex-0><cex-1><cex-dot>•</cex-dot></cex-1> <cex-leaf>"a"</cex-leaf></cex-0>
584 <cex-0><cex-step>exp</cex-step></cex-0>
585 <cex-0><cex-step>↳ 5: <cex-1><cex-step>empty</cex-step></cex-1><cex-leaf> "a"</cex-leaf></cex-step></cex-0>
586 <cex-1><cex-step> ↳ 7: ε<cex-dot> •</cex-dot></cex-step></cex-1>
587 input.y: <warning>warning:</warning> shift/reduce conflict on token "+" [<warning>-Wcounterexamples</warning>]
588 Example: <cex-0><cex-leaf>exp</cex-leaf> <cex-leaf>"+"</cex-leaf><cex-1> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-1></cex-0>
590 <cex-0><cex-step>exp</cex-step></cex-0>
591 <cex-0><cex-step>↳ 3: <cex-leaf>exp</cex-leaf><cex-leaf> "+"</cex-leaf><cex-1><cex-step> exp</cex-step></cex-1></cex-step></cex-0>
592 <cex-1><cex-step> ↳ 3: <cex-leaf>exp</cex-leaf><cex-dot> •</cex-dot><cex-leaf> "+"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-1>
593 Example: <cex-0><cex-1><cex-leaf>exp</cex-leaf> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot></cex-1> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-0>
595 <cex-0><cex-step>exp</cex-step></cex-0>
596 <cex-0><cex-step>↳ 3: <cex-1><cex-step>exp</cex-step></cex-1><cex-leaf> "+"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-0>
597 <cex-1><cex-step> ↳ 3: <cex-leaf>exp</cex-leaf><cex-leaf> "+"</cex-leaf><cex-leaf> exp</cex-leaf><cex-dot> •</cex-dot></cex-step></cex-1>
598 input.y: <warning>warning:</warning> shift/reduce conflict on token "else" [<warning>-Wcounterexamples</warning>]
599 Example: <cex-0><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf><cex-1> <cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"else"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-1></cex-0>
601 <cex-0><cex-step>exp</cex-step></cex-0>
602 <cex-0><cex-step>↳ 1: <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-1><cex-step> exp</cex-step></cex-1></cex-step></cex-0>
603 <cex-1><cex-step> ↳ 2: <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-leaf> exp</cex-leaf><cex-dot> •</cex-dot><cex-leaf> "else"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-1>
604 Example: <cex-0><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf><cex-1> <cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot></cex-1> <cex-leaf>"else"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-0>
606 <cex-0><cex-step>exp</cex-step></cex-0>
607 <cex-0><cex-step>↳ 2: <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-1><cex-step> exp</cex-step></cex-1><cex-leaf> "else"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-0>
608 <cex-1><cex-step> ↳ 1: <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-leaf> exp</cex-leaf><cex-dot> •</cex-dot></cex-step></cex-1>
609 input.y: <warning>warning:</warning> shift/reduce conflict on token "+" [<warning>-Wcounterexamples</warning>]
610 Example: <cex-0><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf><cex-1> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-1></cex-0>
612 <cex-0><cex-step>exp</cex-step></cex-0>
613 <cex-0><cex-step>↳ 1: <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-1><cex-step> exp</cex-step></cex-1></cex-step></cex-0>
614 <cex-1><cex-step> ↳ 3: <cex-leaf>exp</cex-leaf><cex-dot> •</cex-dot><cex-leaf> "+"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-1>
615 Example: <cex-0><cex-1><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot></cex-1> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-0>
617 <cex-0><cex-step>exp</cex-step></cex-0>
618 <cex-0><cex-step>↳ 3: <cex-1><cex-step>exp</cex-step></cex-1><cex-leaf> "+"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-0>
619 <cex-1><cex-step> ↳ 1: <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-leaf> exp</cex-leaf><cex-dot> •</cex-dot></cex-step></cex-1>
620 input.y: <warning>warning:</warning> shift/reduce conflict on token "a" [<warning>-Wcounterexamples</warning>]
621 Example: <cex-0><cex-dot>•</cex-dot> <cex-leaf>"a"</cex-leaf><cex-1></cex-1></cex-0>
623 <cex-0><cex-step>exp</cex-step></cex-0>
624 <cex-0><cex-step>↳ 6: <cex-dot>•</cex-dot><cex-leaf> "a"</cex-leaf><cex-1><cex-step> empty</cex-step></cex-1></cex-step></cex-0>
625 <cex-1><cex-step> ↳ 6: ε</cex-step></cex-1>
626 Example: <cex-0><cex-1><cex-dot>•</cex-dot></cex-1> <cex-leaf>"a"</cex-leaf></cex-0>
628 <cex-0><cex-step>exp</cex-step></cex-0>
629 <cex-0><cex-step>↳ 5: <cex-1><cex-step>empty</cex-step></cex-1><cex-leaf> "a"</cex-leaf></cex-step></cex-0>
630 <cex-1><cex-step> ↳ 7: ε<cex-dot> •</cex-dot></cex-step></cex-1>
631 input.y: <warning>warning:</warning> shift/reduce conflict on token "+" [<warning>-Wcounterexamples</warning>]
632 Example: <cex-0><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"else"</cex-leaf><cex-1> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-1></cex-0>
634 <cex-0><cex-step>exp</cex-step></cex-0>
635 <cex-0><cex-step>↳ 2: <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "else"</cex-leaf><cex-1><cex-step> exp</cex-step></cex-1></cex-step></cex-0>
636 <cex-1><cex-step> ↳ 3: <cex-leaf>exp</cex-leaf><cex-dot> •</cex-dot><cex-leaf> "+"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-1>
637 Example: <cex-0><cex-1><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"else"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot></cex-1> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-0>
639 <cex-0><cex-step>exp</cex-step></cex-0>
640 <cex-0><cex-step>↳ 3: <cex-1><cex-step>exp</cex-step></cex-1><cex-leaf> "+"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-0>
641 <cex-1><cex-step> ↳ 2: <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "else"</cex-leaf><cex-leaf> exp</cex-leaf><cex-dot> •</cex-dot></cex-step></cex-1>
645 AT_TEST([[Deep Counterexamples]],
648 exp: x1 e1 foo1 x1 | y1 e2 bar1 y1
671 [[input.y:30.4: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
673 | <warning>^</warning>
674 | <fixit-insert>%empty</fixit-insert>
675 input.y:31.4: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
677 | <warning>^</warning>
678 | <fixit-insert>%empty</fixit-insert>
679 input.y: <error>error:</error> reduce/reduce conflicts: 1 found, 0 expected
680 input.y: <warning>warning:</warning> reduce/reduce conflict on token "X" [<warning>-Wcounterexamples</warning>]
681 Example: <cex-0><cex-1><cex-2><cex-3><cex-leaf>"X"</cex-leaf> <cex-dot>•</cex-dot></cex-3></cex-2></cex-1><cex-4></cex-4><cex-5><cex-6><cex-7><cex-8><cex-9><cex-10> <cex-leaf>"X"</cex-leaf></cex-10></cex-9></cex-8><cex-11> <cex-leaf>"quuux"</cex-leaf></cex-11></cex-7></cex-6></cex-5><cex-12><cex-13><cex-14> <cex-leaf>"X"</cex-leaf></cex-14></cex-13></cex-12></cex-0>
682 First reduce derivation
683 <cex-0><cex-step>exp</cex-step></cex-0>
684 <cex-0><cex-step>↳ 1: <cex-1><cex-step>x1</cex-step></cex-1><cex-4><cex-step> e1</cex-step></cex-4><cex-5><cex-step> foo1</cex-step></cex-5><cex-12><cex-step> x1</cex-step></cex-12></cex-step></cex-0>
685 <cex-1><cex-step> ↳ 11: <cex-2><cex-step>x2</cex-step></cex-2></cex-step></cex-1><cex-4><cex-step> ↳ 1: ε</cex-step></cex-4><cex-5><cex-step> ↳ 3: <cex-6><cex-step>foo2</cex-step></cex-6></cex-step></cex-5><cex-12><cex-step> ↳ 11: <cex-13><cex-step>x2</cex-step></cex-13></cex-step></cex-12>
686 <cex-2><cex-step> ↳ 12: <cex-3><cex-step>x3</cex-step></cex-3></cex-step></cex-2><cex-6><cex-step> ↳ 4: <cex-7><cex-step>foo3</cex-step></cex-7></cex-step></cex-6><cex-13><cex-step> ↳ 12: <cex-14><cex-step>x3</cex-step></cex-14></cex-step></cex-13>
687 <cex-3><cex-step> ↳ 13: <cex-leaf>"X"</cex-leaf><cex-dot> •</cex-dot></cex-step></cex-3><cex-7><cex-step> ↳ 5: <cex-8><cex-step>x1</cex-step></cex-8><cex-11><cex-step> foo4</cex-step></cex-11></cex-step></cex-7><cex-14><cex-step> ↳ 13: <cex-leaf>"X"</cex-leaf></cex-step></cex-14>
688 <cex-8><cex-step> ↳ 11: <cex-9><cex-step>x2</cex-step></cex-9></cex-step></cex-8><cex-11><cex-step> ↳ 6: <cex-leaf>"quuux"</cex-leaf></cex-step></cex-11>
689 <cex-9><cex-step> ↳ 12: <cex-10><cex-step>x3</cex-step></cex-10></cex-step></cex-9>
690 <cex-10><cex-step> ↳ 13: <cex-leaf>"X"</cex-leaf></cex-step></cex-10>
691 Example: <cex-0><cex-1><cex-2><cex-3><cex-leaf>"X"</cex-leaf> <cex-dot>•</cex-dot></cex-3></cex-2></cex-1><cex-4></cex-4><cex-5><cex-6><cex-7><cex-8><cex-9><cex-10> <cex-leaf>"X"</cex-leaf></cex-10></cex-9></cex-8><cex-11> <cex-leaf>"quuux"</cex-leaf></cex-11></cex-7></cex-6></cex-5><cex-12><cex-13><cex-14> <cex-leaf>"X"</cex-leaf></cex-14></cex-13></cex-12></cex-0>
692 Second reduce derivation
693 <cex-0><cex-step>exp</cex-step></cex-0>
694 <cex-0><cex-step>↳ 2: <cex-1><cex-step>y1</cex-step></cex-1><cex-4><cex-step> e2</cex-step></cex-4><cex-5><cex-step> bar1</cex-step></cex-5><cex-12><cex-step> y1</cex-step></cex-12></cex-step></cex-0>
695 <cex-1><cex-step> ↳ 14: <cex-2><cex-step>y2</cex-step></cex-2></cex-step></cex-1><cex-4><cex-step> ↳ 2: ε</cex-step></cex-4><cex-5><cex-step> ↳ 7: <cex-6><cex-step>bar2</cex-step></cex-6></cex-step></cex-5><cex-12><cex-step> ↳ 14: <cex-13><cex-step>y2</cex-step></cex-13></cex-step></cex-12>
696 <cex-2><cex-step> ↳ 15: <cex-3><cex-step>y3</cex-step></cex-3></cex-step></cex-2><cex-6><cex-step> ↳ 8: <cex-7><cex-step>bar3</cex-step></cex-7></cex-step></cex-6><cex-13><cex-step> ↳ 15: <cex-14><cex-step>y3</cex-step></cex-14></cex-step></cex-13>
697 <cex-3><cex-step> ↳ 16: <cex-leaf>"X"</cex-leaf><cex-dot> •</cex-dot></cex-step></cex-3><cex-7><cex-step> ↳ 9: <cex-8><cex-step>y1</cex-step></cex-8><cex-11><cex-step> bar4</cex-step></cex-11></cex-step></cex-7><cex-14><cex-step> ↳ 16: <cex-leaf>"X"</cex-leaf></cex-step></cex-14>
698 <cex-8><cex-step> ↳ 14: <cex-9><cex-step>y2</cex-step></cex-9></cex-step></cex-8><cex-11><cex-step> ↳ 10: <cex-leaf>"quuux"</cex-leaf></cex-step></cex-11>
699 <cex-9><cex-step> ↳ 15: <cex-10><cex-step>y3</cex-step></cex-10></cex-step></cex-9>
700 <cex-10><cex-step> ↳ 16: <cex-leaf>"X"</cex-leaf></cex-step></cex-10>
701 input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
709 ## -------------------------------------- ##
710 ## Indentation with message suppression. ##
711 ## -------------------------------------- ##
713 AT_SETUP([[Indentation with message suppression]])
715 # https://lists.gnu.org/r/bug-bison/2019-08/msg00002.html
725 AT_BISON_CHECK([[-fcaret -Wno-other input.y]], [0], [],
726 [[input.y:2.1-12: warning: deprecated directive: '%pure-parser', use '%define api.pure' [-Wdeprecated]
730 input.y:3.1-14: warning: deprecated directive: '%error-verbose', use '%define parse.error verbose' [-Wdeprecated]
733 | %define parse.error verbose