Debian Codegraph @

gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-O -fdiagnostics-show-caret -fplugin-arg-diagnostic_plugin_test_show_locus-color" } */
3
4 /* This is a collection of unittests for diagnostic_show_locus;
5 see the overview in diagnostic_plugin_test_show_locus.c.
6
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. */
10
11 void test_simple (void)
12 {
13 #if 0
14 myvar = myvar.x; /* { dg-warning "test" } */
15
16 /* { dg-begin-multiline-output "" }
17 myvar = myvar.x;
18 ~~~~~^~
19 { dg-end-multiline-output "" } */
20 #endif
21 }
22
23 void test_simple_2 (void)
24 {
25 #if 0
26 x = first_function () + second_function (); /* { dg-warning "test" } */
27
28 /* { dg-begin-multiline-output "" }
29 x = first_function () + second_function ();
30 ~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~
31 { dg-end-multiline-output "" } */
32 #endif
33 }
34
35
36 void test_multiline (void)
37 {
38 #if 0
39 x = (first_function ()
40 + second_function ()); /* { dg-warning "test" } */
41
42 /* { dg-begin-multiline-output "" }
43 x = (first_function ()
44 ~~~~~~~~~~~~~~~~~
45 + second_function ());
46 ^ ~~~~~~~~~~~~~~~~~~
47 |
48 label
49 { dg-end-multiline-output "" } */
50 #endif
51 }
52
53 void test_many_lines (void)
54 {
55 #if 0
56 x = (first_function_with_a_very_long_name (lorem, ipsum, dolor, sit, amet,
57 consectetur, adipiscing, elit,
58 sed, eiusmod, tempor,
59 incididunt, ut, labore, et,
60 dolore, magna, aliqua)
61 + second_function_with_a_very_long_name (lorem, ipsum, dolor, sit, /* { dg-warning "test" } */
62 amet, consectetur,
63 adipiscing, elit, sed,
64 eiusmod, tempor, incididunt,
65 ut, labore, et, dolore,
66 magna, aliqua));
67
68 /* { dg-begin-multiline-output "" }
69 x = (first_function_with_a_very_long_name (lorem, ipsum, dolor, sit, amet,
70 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71 |
72 label 1
73  consectetur, adipiscing, elit,
74 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75  sed, eiusmod, tempor,
76 ~~~~~~~~~~~~~~~~~~~~~
77  incididunt, ut, labore, et,
78 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
79  dolore, magna, aliqua)
80 ~~~~~~~~~~~~~~~~~~~~~~
81 + second_function_with_a_very_long_name (lorem, ipsum, dolor, sit,
82 ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83 | |
84 | label 2
85 label 0
86  amet, consectetur,
87 ~~~~~~~~~~~~~~~~~~
88  adipiscing, elit, sed,
89 ~~~~~~~~~~~~~~~~~~~~~~
90  eiusmod, tempor, incididunt,
91 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92  ut, labore, et, dolore,
93 ~~~~~~~~~~~~~~~~~~~~~~~
94  magna, aliqua));
95 ~~~~~~~~~~~~~~
96 { dg-end-multiline-output "" } */
97 #endif
98 }
99
100 void test_richloc_from_proper_range (void)
101 {
102 #if 0
103 float f = 98.6f; /* { dg-warning "test" } */
104 /* { dg-begin-multiline-output "" }
105 float f = 98.6f;
106 ^~~~~
107 { dg-end-multiline-output "" } */
108 #endif
109 }
110
111 void test_caret_within_proper_range (void)
112 {
113 #if 0
114 float f = foo * bar; /* { dg-warning "17: test" } */
115 /* { dg-begin-multiline-output "" }
116 float f = foo * bar;
117 ~~~~^~~~~
118 { dg-end-multiline-output "" } */
119 #endif
120 }
121
122 void test_very_wide_line (void)
123 {
124 #if 0
125 float x = foo * bar; /* { dg-warning "95: test" } */
126 /* { dg-begin-multiline-output "" }
127 0 0 0 0 0 0 1
128 4 5 6 7 8 9 0
129 6789012345678901234567890123456789012345678901234567890123456789012345
130 x = foo * bar;
131 ~ ~~~~^~~~~
132 | |
133 label 1 label 0
134 bar * foo
135 { dg-end-multiline-output "" } */
136 #endif
137 }
138
139 void test_multiple_carets (void)
140 {
141 #if 0
142 x = x + y /* { dg-warning "8: test" } */
143 /* { dg-begin-multiline-output "" }
144 x = x + y
145 A B
146 { dg-end-multiline-output "" } */
147 #endif
148 }
149
150 void test_caret_on_leading_whitespace (void)
151 {
152 #if 0
153 ASSOCIATE (y => x)
154 y = 5 /* { dg-warning "6: test" } */
155 /* { dg-begin-multiline-output "" }
156 ASSOCIATE (y => x)
157 2
158  y = 5
159 1
160 { dg-end-multiline-output "" } */
161 #endif
162 }
163
164 /* Unit test for rendering of insertion fixit hints
165 (example taken from PR 62316). */
166
167 void test_fixit_insert (void)
168 {
169 #if 0
170 int a[2][2] = { 0, 1 , 2, 3 }; /* { dg-warning "insertion hints" } */
171 /* { dg-begin-multiline-output "" }
172 int a[2][2] = { 0, 1 , 2, 3 };
173 ^~~~
174 { }
175 { dg-end-multiline-output "" } */
176 #endif
177 }
178
179 /* Unit test for rendering of "remove" fixit hints. */
180
181 void test_fixit_remove (void)
182 {
183 #if 0
184 int a;; /* { dg-warning "example of a removal hint" } */
185 /* { dg-begin-multiline-output "" }
186 int a;;
187 ^
188 -
189 { dg-end-multiline-output "" } */
190 #endif
191 }
192
193 /* Unit test for rendering of "replace" fixit hints. */
194
195 void test_fixit_replace (void)
196 {
197 #if 0
198 gtk_widget_showall (dlg); /* { dg-warning "example of a replacement hint" } */
199 /* { dg-begin-multiline-output "" }
200 gtk_widget_showall (dlg);
201 ^~~~~~~~~~~~~~~~~~
202 gtk_widget_show_all
203 { dg-end-multiline-output "" } */
204 #endif
205 }
206
207 /* Unit test for rendering of fix-it hints that add new lines. */
208
209 void test_fixit_insert_newline (void)
210 {
211 #if 0
212 switch (op)
213 {
214 case 'a':
215 x = a;
216 case 'b': /* { dg-warning "newline insertion" } */
217 x = b;
218 }
219 /* { dg-begin-multiline-output "" }
220 x = a;
221 + break;
222 case 'b':
223 ^~~~~~~~
224 { dg-end-multiline-output "" } */
225 #endif
226 }