| 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 = [32m[Kmyvar[m[K[01;35m[K.[m[K[34m[Kx[m[K; |
| 18 |
[32m[K~~~~~[m[K[01;35m[K^[m[K[34m[K~[m[K |
| 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 = [32m[Kfirst_function ()[m[K [01;35m[K+[m[K [34m[Ksecond_function ()[m[K; |
| 30 |
[32m[K~~~~~~~~~~~~~~~~~[m[K [01;35m[K^[m[K [34m[K~~~~~~~~~~~~~~~~~~[m[K |
| 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 = ([32m[Kfirst_function ()[m[K |
| 44 |
[32m[K~~~~~~~~~~~~~~~~~[m[K |
| 45 |
[01;35m[K+[m[K [34m[Ksecond_function ()[m[K); |
| 46 |
[01;35m[K^[m[K [34m[K~~~~~~~~~~~~~~~~~~[m[K |
| 47 |
[01;35m[K|[m[K |
| 48 |
[01;35m[Klabel[m[K |
| 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 = ([32m[Kfirst_function_with_a_very_long_name (lorem, ipsum, dolor, sit, amet,[m[K |
| 70 |
[32m[K~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[m[K |
| 71 |
[32m[K|[m[K |
| 72 |
[32m[Klabel 1[m[K |
| 73 |
[32m[K consectetur, adipiscing, elit,[m[K |
| 74 |
[32m[K~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[m[K |
| 75 |
[32m[K sed, eiusmod, tempor,[m[K |
| 76 |
[32m[K~~~~~~~~~~~~~~~~~~~~~[m[K |
| 77 |
[32m[K incididunt, ut, labore, et,[m[K |
| 78 |
[32m[K~~~~~~~~~~~~~~~~~~~~~~~~~~~[m[K |
| 79 |
[32m[K dolore, magna, aliqua)[m[K |
| 80 |
[32m[K~~~~~~~~~~~~~~~~~~~~~~[m[K |
| 81 |
[01;35m[K+[m[K [34m[Ksecond_function_with_a_very_long_name (lorem, ipsum, dolor, sit, |
| 82 |
[01;35m[K^[m[K [34m[K~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[m[K |
| 83 |
[01;35m[K|[m[K [34m[K|[m[K |
| 84 |
[01;35m[K|[m[K [34m[Klabel 2[m[K |
| 85 |
[01;35m[Klabel 0[m[K |
| 86 |
[34m[K amet, consectetur,[m[K |
| 87 |
[34m[K~~~~~~~~~~~~~~~~~~[m[K |
| 88 |
[34m[K adipiscing, elit, sed,[m[K |
| 89 |
[34m[K~~~~~~~~~~~~~~~~~~~~~~[m[K |
| 90 |
[34m[K eiusmod, tempor, incididunt,[m[K |
| 91 |
[34m[K~~~~~~~~~~~~~~~~~~~~~~~~~~~~[m[K |
| 92 |
[34m[K ut, labore, et, dolore,[m[K |
| 93 |
[34m[K~~~~~~~~~~~~~~~~~~~~~~~[m[K |
| 94 |
[34m[K magna, aliqua)[m[K); |
| 95 |
[34m[K~~~~~~~~~~~~~~[m[K |
| 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 = [01;35m[K98.6f[m[K; |
| 106 |
[01;35m[K^~~~~[m[K |
| 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 = [01;35m[Kfoo * bar[m[K; |
| 117 |
[01;35m[K~~~~^~~~~[m[K |
| 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 |
[32m[Kx[m[K = [01;35m[Kfoo * bar[m[K; |
| 131 |
[32m[K~[m[K [01;35m[K~~~~^~~~~[m[K |
| 132 |
[32m[K|[m[K [01;35m[K|[m[K |
| 133 |
[32m[Klabel 1[m[K [01;35m[Klabel 0[m[K |
| 134 |
[32m[Kbar * foo[m[K |
| 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 = [01;35m[Kx[m[K + [32m[Ky[m[K |
| 145 |
[01;35m[KA[m[K [32m[KB[m[K |
| 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 =>[32m[K [m[Kx) |
| 157 |
[32m[K2[m[K |
| 158 |
[01;35m[K [m[Ky = 5 |
| 159 |
[01;35m[K1[m[K |
| 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] = { [01;35m[K0, 1[m[K , 2, 3 }; |
| 173 |
[01;35m[K^~~~[m[K |
| 174 |
[32m[K{[m[K [32m[K}[m[K |
| 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;[01;35m[K;[m[K |
| 187 |
[01;35m[K^[m[K |
| 188 |
[31m[K-[m[K |
| 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 |
[01;35m[Kgtk_widget_showall[m[K (dlg); |
| 201 |
[01;35m[K^~~~~~~~~~~~~~~~~~[m[K |
| 202 |
[32m[Kgtk_widget_show_all[m[K |
| 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 |
+[32m[K break;[m[K |
| 222 |
[01;35m[Kcase 'b'[m[K: |
| 223 |
[01;35m[K^~~~~~~~[m[K |
| 224 |
{ dg-end-multiline-output "" } */ |
| 225 |
#endif |
| 226 |
} |