diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2020-03-07 09:57:03 +0100 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2020-03-07 10:01:52 +0100 |
commit | e21ff47f5d0b64da693a47b7dd200a1a44a5bbeb (patch) | |
tree | f792615e3df02d4d8e136c22b0e7a712b5e7f581 /tests | |
parent | b82b387da9b637a10edc97632435d53f5d340ba8 (diff) | |
download | bison-e21ff47f5d0b64da693a47b7dd200a1a44a5bbeb.tar.gz |
diagnostics: be sure to close the styling when lines are too short
bar.y:4.12-17: <error>error:</error> redefining user token number of foo
- 4 | %token foo <error>123
+ 4 | %token foo <error>123</error>
| <error>^~~~~~</error>
* src/location.c (location_caret): Be sure to close.
* tests/diagnostics.at (Line is too short, and then you die): New.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/diagnostics.at | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/tests/diagnostics.at b/tests/diagnostics.at index b0b5ee3e..cbf56b77 100644 --- a/tests/diagnostics.at +++ b/tests/diagnostics.at @@ -152,6 +152,47 @@ input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option ]]) + +## ------------------------------------- ## +## Line is too short, and then you die. ## +## ------------------------------------- ## + +# We trust the "#line", since that's what allows us to quote the +# actual source from which the gramar file was generated. But #line +# can also be wrong, and point to a line which is shorter that the bad +# one. In which case we can easily forget to close the styling. +# +# Be sure to have #line point to a line long enough to open the +# styling, but not enough to close it. + +AT_TEST([[Line is too short, and then you die]], +[[// Beware that there are 9 lines inserted before (including this one). +#line 12 +%token foo 123 +%token foo 123123 +%token foo 123 +%% +exp: +]], +[1], +[[input.y:13.8-10: <warning>warning:</warning> symbol foo redeclared [<warning>-Wother</warning>] + 13 | %token <warning>foo</warning> 123 + | <warning>^~~</warning> +input.y:12.8-10: previous declaration + 12 | %token <note>foo</note> 123123 + | <note>^~~</note> +input.y:13.12-17: <error>error:</error> redefining user token number of foo + 13 | %token foo <error>123</error> + | <error>^~~~~~</error> +input.y:14.8-10: <warning>warning:</warning> symbol foo redeclared [<warning>-Wother</warning>] + 14 | %% + | <warning>^~~</warning> +input.y:12.8-10: previous declaration + 12 | %token <note>foo</note> 123123 + | <note>^~~</note> +]]) + + ## -------------------------------------- ## ## Tabulations and multibyte characters. ## ## -------------------------------------- ## @@ -262,7 +303,7 @@ input.y:10.1-27: <error>error:</error> %define variable 'error2' is not used ## ----------------- ## # Carriage-return used to count as a newline in the scanner, and not -# in diagnostics. Resulting in all sort of nice bugs. +# in diagnostics. Resulting in all kinds of nice bugs. AT_TEST([[Carriage return]], [[^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 |