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 ());
47 { dg-end-multiline-output "" } */
51 void test_many_lines (void)
54 x
= (first_function_with_a_very_long_name (lorem
, ipsum
, dolor
, sit
, amet
,
55 consectetur
, adipiscing
, elit
,
57 incididunt
, ut
, labore
, et
,
58 dolore
, magna
, aliqua
)
59 + second_function_with_a_very_long_name (lorem
, ipsum
, dolor
, sit
, /* { dg-warning "test" } */
61 adipiscing
, elit
, sed
,
62 eiusmod
, tempor
, incididunt
,
63 ut
, labore
, et
, dolore
,
66 /* { dg-begin-multiline-output "" }
67 x = (first_function_with_a_very_long_name (lorem, ipsum, dolor, sit, amet,
68 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 consectetur, adipiscing, elit,
70 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73 incididunt, ut, labore, et,
74 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
75 dolore, magna, aliqua)
76 ~~~~~~~~~~~~~~~~~~~~~~
77 + second_function_with_a_very_long_name (lorem, ipsum, dolor, sit,
78 ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81 adipiscing, elit, sed,
82 ~~~~~~~~~~~~~~~~~~~~~~
83 eiusmod, tempor, incididunt,
84 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85 ut, labore, et, dolore,
86 ~~~~~~~~~~~~~~~~~~~~~~~
89 { dg-end-multiline-output "" } */
93 void test_richloc_from_proper_range (void)
96 float f
= 98.6f
; /* { dg-warning "test" } */
97 /* { dg-begin-multiline-output "" }
100 { dg-end-multiline-output "" } */
104 void test_caret_within_proper_range (void)
107 float f
= foo
* bar
; /* { dg-warning "17: test" } */
108 /* { dg-begin-multiline-output "" }
111 { dg-end-multiline-output "" } */
115 void test_very_wide_line (void)
118 float f
= foo
* bar
; /* { dg-warning "95: test" } */
119 /* { dg-begin-multiline-output "" }
122 6789012345678901234567890123456789012345678901234567890123456789012345
125 { dg-end-multiline-output "" } */
129 void test_multiple_carets (void)
132 x
= x
+ y
/* { dg-warning "8: test" } */
133 /* { dg-begin-multiline-output "" }
136 { dg-end-multiline-output "" } */
140 void test_caret_on_leading_whitespace (void)
144 y
= 5 /* { dg-warning "6: test" } */
145 /* { dg-begin-multiline-output "" }
150 { dg-end-multiline-output "" } */
154 /* Unit test for rendering of insertion fixit hints
155 (example taken from PR 62316). */
157 void test_fixit_insert (void)
160 int a
[2][2] = { 0, 1 , 2, 3 }; /* { dg-warning "insertion hints" } */
161 /* { dg-begin-multiline-output "" }
162 int a[2][2] = { 0, 1 , 2, 3 };
165 { dg-end-multiline-output "" } */
169 /* Unit test for rendering of "remove" fixit hints. */
171 void test_fixit_remove (void)
174 int a
;; /* { dg-warning "example of a removal hint" } */
175 /* { dg-begin-multiline-output "" }
179 { dg-end-multiline-output "" } */
183 /* Unit test for rendering of "replace" fixit hints. */
185 void test_fixit_replace (void)
188 gtk_widget_showall (dlg
); /* { dg-warning "example of a replacement hint" } */
189 /* { dg-begin-multiline-output "" }
190 gtk_widget_showall (dlg);
193 { dg-end-multiline-output "" } */
197 /* Test of "%q+D" format code. */
199 int test_percent_q_plus_d (void)
201 int local
= 0; /* { dg-warning "example of plus in format code" } */
202 /* { dg-begin-multiline-output "" }
205 { dg-end-multiline-output "" } */
209 /* Test of many nested locations and fixits. */
211 void test_many_nested_locations (void)
213 /* { dg-warning "test of 70 locations" }
214 Lorem ipsum dolor sit amet, consectetur adipiscing elit,
215 sed do eiusmod tempor incididunt ut labore et dolore magna
216 aliqua. Ut enim ad minim veniam, quis nostrud exercitation
217 ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
218 aute irure dolor in reprehenderit in voluptate velit esse cillum
219 dolore eu fugiat nulla pariatur. Excepteur sint occaecat
220 cupidatat non proident, sunt in culpa qui officia deserunt
221 mollit anim id est laborum.
223 /* { dg-begin-multiline-output "" }
226 Lorem ipsum dolor sit amet, consectetur adipiscing elit,
227 ^~~~~ ^~~~~ ^~~~~ ^~~ ^~~~ ^~~~~~~~~~~ ^~~~~~~~~~ ^~~~
228 LOREM IPSUM DOLOR SIT AMET CONSECTETUR ADIPISCING ELIT
229 sed do eiusmod tempor incididunt ut labore et dolore magna
230 ^~~ ^~ ^~~~~~~ ^~~~~~ ^~~~~~~~~~ ^~ ^~~~~~ ^~ ^~~~~~ ^~~~~
231 SED DO EIUSMOD TEMPOR INCIDIDUNT UT LABORE ET DOLORE MAGNA
232 aliqua. Ut enim ad minim veniam, quis nostrud exercitation
233 ^~~~~~ ^~ ^~~~ ^~ ^~~~~ ^~~~~~ ^~~~ ^~~~~~~ ^~~~~~~~~~~~
234 ALIQUA UT ENIM AD MINIM VENIAM QUIS NOSTRUD EXERCITATION
235 ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
236 ^~~~~~~ ^~~~~~~ ^~~~ ^~ ^~~~~~~ ^~ ^~ ^~~~~~~ ^~~~~~~~~ ^~~~
237 ULLAMCO LABORIS NISI UT ALIQUIP EX EA COMMODO CONSEQUAT DUIS
238 aute irure dolor in reprehenderit in voluptate velit esse cillum
239 ^~~~ ^~~~~ ^~~~~ ^~ ^~~~~~~~~~~~~ ^~ ^~~~~~~~~ ^~~~~ ^~~~ ^~~~~~
240 AUTE IRURE DOLOR IN REPREHENDERIT IN VOLUPTATE VELIT ESSE CILLUM
241 dolore eu fugiat nulla pariatur. Excepteur sint occaecat
242 ^~~~~~ ^~ ^~~~~~ ^~~~~ ^~~~~~~~ ^~~~~~~~~ ^~~~ ^~~~~~~~
243 DOLORE EU FUGIAT NULLA PARIATUR EXCEPTEUR SINT OCCAECAT
244 cupidatat non proident, sunt in culpa qui officia deserunt
245 ^~~~~~~~~ ^~~ ^~~~~~~~ ^~~~ ^~ ^~~~~ ^~~ ^~~~~~~ ^~~~~~~~
246 CUPIDATAT NON PROIDENT SUNT IN CULPA QUI OFFICIA DESERUNT
247 mollit anim id est laborum.
248 ^~~~~~ ^~~~ ^~ ^~~ ^~~~~~~
249 MOLLIT ANIM ID EST LABORUM
250 { dg-end-multiline-output "" } */
253 /* Unit test for rendering of fix-it hints that add new lines. */
255 void test_fixit_insert_newline (void)
262 case 'b': /* { dg-warning "newline insertion" } */
265 /* { dg-begin-multiline-output "" }
269 { dg-end-multiline-output "" } */
273 /* Unit test for mutually-exclusive suggestions. */
275 void test_mutually_exclusive_suggestions (void)
278 original
; /* { dg-warning "warning 1" } */
279 /* { dg-warning "warning 2" "" { target *-*-* } .-1 } */
280 /* { dg-begin-multiline-output "" }
284 { dg-end-multiline-output "" } */
285 /* { dg-begin-multiline-output "" }
289 { dg-end-multiline-output "" } */