1 /* { dg-do compile } */
2 /* { dg-options "-O -fdiagnostics-show-caret" } */
4 /* This is a collection of unittests for diagnostic_show_locus;
5 see the overview in diagnostic_plugin_test_show_locus.c.
7 In particular, note the discussion of why we need a very long line here:
8 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
9 and that we can't use macros in this file. */
11 void test_simple (void)
14 myvar
= myvar
.x
; /* { dg-warning "test" } */
16 /* { dg-begin-multiline-output "" }
19 { dg-end-multiline-output "" } */
23 void test_simple_2 (void)
26 x
= first_function () + second_function (); /* { dg-warning "test" } */
28 /* { dg-begin-multiline-output "" }
29 x = first_function () + second_function ();
30 ~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~
31 { dg-end-multiline-output "" } */
36 void test_multiline (void)
39 x
= (first_function ()
40 + second_function ()); /* { dg-warning "test" } */
42 /* { dg-begin-multiline-output "" }
43 x = (first_function ()
45 + second_function ());
49 { dg-end-multiline-output "" } */
53 void test_many_lines (void)
56 x
= (first_function_with_a_very_long_name (lorem
, ipsum
, dolor
, sit
, amet
,
57 consectetur
, adipiscing
, elit
,
59 incididunt
, ut
, labore
, et
,
60 dolore
, magna
, aliqua
)
61 + second_function_with_a_very_long_name (lorem
, ipsum
, dolor
, sit
, /* { dg-warning "test" } */
63 adipiscing
, elit
, sed
,
64 eiusmod
, tempor
, incididunt
,
65 ut
, labore
, et
, dolore
,
68 /* { dg-begin-multiline-output "" }
69 x = (first_function_with_a_very_long_name (lorem, ipsum, dolor, sit, amet,
70 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73 consectetur, adipiscing, elit,
74 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77 incididunt, ut, labore, et,
78 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
79 dolore, magna, aliqua)
80 ~~~~~~~~~~~~~~~~~~~~~~
81 + second_function_with_a_very_long_name (lorem, ipsum, dolor, sit,
82 ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88 adipiscing, elit, sed,
89 ~~~~~~~~~~~~~~~~~~~~~~
90 eiusmod, tempor, incididunt,
91 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92 ut, labore, et, dolore,
93 ~~~~~~~~~~~~~~~~~~~~~~~
96 { dg-end-multiline-output "" } */
100 void test_richloc_from_proper_range (void)
103 float f
= 98.6f
; /* { dg-warning "test" } */
104 /* { dg-begin-multiline-output "" }
107 { dg-end-multiline-output "" } */
111 void test_caret_within_proper_range (void)
114 float f
= foo
* bar
; /* { dg-warning "17: test" } */
115 /* { dg-begin-multiline-output "" }
118 { dg-end-multiline-output "" } */
122 void test_very_wide_line (void)
125 float x
= foo
* bar
; /* { dg-warning "95: test" } */
126 /* { dg-begin-multiline-output "" }
129 6789012345678901234567890123456789012345678901234567890123456789012345
135 { dg-end-multiline-output "" } */
139 void test_very_wide_line_2 (void)
142 float x
= foo
* bar
; /* { dg-warning "95: test" } */
143 /* { dg-begin-multiline-output "" }
146 6789012345678901234567890123456789012345678901234567890123456789012345
152 { dg-end-multiline-output "" } */
156 void test_multiple_carets (void)
159 x
= x
+ y
/* { dg-warning "8: test" } */
160 /* { dg-begin-multiline-output "" }
163 { dg-end-multiline-output "" } */
167 void test_caret_on_leading_whitespace (void)
171 y
= 5 /* { dg-warning "6: test" } */
172 /* { dg-begin-multiline-output "" }
177 { dg-end-multiline-output "" } */
181 /* Unit test for rendering of insertion fixit hints
182 (example taken from PR 62316). */
184 void test_fixit_insert (void)
187 int a
[2][2] = { 0, 1 , 2, 3 }; /* { dg-warning "insertion hints" } */
188 /* { dg-begin-multiline-output "" }
189 int a[2][2] = { 0, 1 , 2, 3 };
192 { dg-end-multiline-output "" } */
196 /* Unit test for rendering of "remove" fixit hints. */
198 void test_fixit_remove (void)
201 int a
;; /* { dg-warning "example of a removal hint" } */
202 /* { dg-begin-multiline-output "" }
206 { dg-end-multiline-output "" } */
210 /* Unit test for rendering of "replace" fixit hints. */
212 void test_fixit_replace (void)
215 gtk_widget_showall (dlg
); /* { dg-warning "example of a replacement hint" } */
216 /* { dg-begin-multiline-output "" }
217 gtk_widget_showall (dlg);
220 { dg-end-multiline-output "" } */
224 /* Test of "%q+D" format code. */
226 int test_percent_q_plus_d (void)
228 int local
= 0; /* { dg-warning "example of plus in format code" } */
229 /* { dg-begin-multiline-output "" }
232 { dg-end-multiline-output "" } */
236 /* Test of many nested locations and fixits. */
238 void test_many_nested_locations (void)
240 /* { dg-warning "test of 70 locations" }
241 Lorem ipsum dolor sit amet, consectetur adipiscing elit,
242 sed do eiusmod tempor incididunt ut labore et dolore magna
243 aliqua. Ut enim ad minim veniam, quis nostrud exercitation
244 ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
245 aute irure dolor in reprehenderit in voluptate velit esse cillum
246 dolore eu fugiat nulla pariatur. Excepteur sint occaecat
247 cupidatat non proident, sunt in culpa qui officia deserunt
248 mollit anim id est laborum.
250 /* { dg-begin-multiline-output "" }
253 Lorem ipsum dolor sit amet, consectetur adipiscing elit,
254 ^~~~~ ^~~~~ ^~~~~ ^~~ ^~~~ ^~~~~~~~~~~ ^~~~~~~~~~ ^~~~
256 | | | | label label label label
257 label label label label
258 LOREM IPSUM DOLOR SIT AMET CONSECTETUR ADIPISCING ELIT
259 sed do eiusmod tempor incididunt ut labore et dolore magna
260 ^~~ ^~ ^~~~~~~ ^~~~~~ ^~~~~~~~~~ ^~ ^~~~~~ ^~ ^~~~~~ ^~~~~
262 | | | | | | | | label label
263 | | | | | | label label
264 | | label label label label
267 SED DO EIUSMOD TEMPOR INCIDIDUNT UT LABORE ET DOLORE MAGNA
268 aliqua. Ut enim ad minim veniam, quis nostrud exercitation
269 ^~~~~~ ^~ ^~~~ ^~ ^~~~~ ^~~~~~ ^~~~ ^~~~~~~ ^~~~~~~~~~~~
271 | | | | | | | label label
272 | | | | label label label
276 ALIQUA UT ENIM AD MINIM VENIAM QUIS NOSTRUD EXERCITATION
277 ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
278 ^~~~~~~ ^~~~~~~ ^~~~ ^~ ^~~~~~~ ^~ ^~ ^~~~~~~ ^~~~~~~~~ ^~~~
280 | | | | | | | label label label
285 ULLAMCO LABORIS NISI UT ALIQUIP EX EA COMMODO CONSEQUAT DUIS
286 aute irure dolor in reprehenderit in voluptate velit esse cillum
287 ^~~~ ^~~~~ ^~~~~ ^~ ^~~~~~~~~~~~~ ^~ ^~~~~~~~~ ^~~~~ ^~~~ ^~~~~~
289 | | | | | | | | | label
290 | | | | | | label label label
294 AUTE IRURE DOLOR IN REPREHENDERIT IN VOLUPTATE VELIT ESSE CILLUM
295 dolore eu fugiat nulla pariatur. Excepteur sint occaecat
296 ^~~~~~ ^~ ^~~~~~ ^~~~~ ^~~~~~~~ ^~~~~~~~~ ^~~~ ^~~~~~~~
299 | | label label label label label
301 DOLORE EU FUGIAT NULLA PARIATUR EXCEPTEUR SINT OCCAECAT
302 cupidatat non proident, sunt in culpa qui officia deserunt
303 ^~~~~~~~~ ^~~ ^~~~~~~~ ^~~~ ^~ ^~~~~ ^~~ ^~~~~~~ ^~~~~~~~
305 | | | | | | | label label
306 | | | | | label label
310 CUPIDATAT NON PROIDENT SUNT IN CULPA QUI OFFICIA DESERUNT
311 mollit anim id est laborum.
312 ^~~~~~ ^~~~ ^~ ^~~ ^~~~~~~
318 MOLLIT ANIM ID EST LABORUM
319 { dg-end-multiline-output "" } */
322 /* Unit test for rendering of fix-it hints that add new lines. */
324 void test_fixit_insert_newline (void)
331 case 'b': /* { dg-warning "newline insertion" } */
334 /* { dg-begin-multiline-output "" }
339 { dg-end-multiline-output "" } */
343 /* Unit test for mutually-exclusive suggestions. */
345 void test_mutually_exclusive_suggestions (void)
348 original
; /* { dg-warning "warning 1" } */
349 /* { dg-warning "warning 2" "" { target *-*-* } .-1 } */
350 /* { dg-begin-multiline-output "" }
354 { dg-end-multiline-output "" } */
355 /* { dg-begin-multiline-output "" }
359 { dg-end-multiline-output "" } */