1 /* { dg-do compile } */
2 /* { dg-options "-O -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" } */
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 
test_simple(void)11 void test_simple (void)
12 {
13 #if 0
14   myvar = myvar.x; /* { dg-warning "test" } */
15 
16 /* { dg-begin-multiline-output "" }
17    14 |   myvar = myvar.x;
18       |           ~~~~~^~
19    { dg-end-multiline-output "" } */
20 #endif
21 }
22 
test_multiline(void)23 void test_multiline (void)
24 {
25 #if 0
26   x = (first_function ()
27        + second_function ()); /* { dg-warning "test" } */
28 
29 /* { dg-begin-multiline-output "" }
30    26 |   x = (first_function ()
31       |        ~~~~~~~~~~~~~~~~~
32    27 |        + second_function ());
33       |        ^ ~~~~~~~~~~~~~~~~~~
34       |        |
35       |        label
36    { dg-end-multiline-output "" } */
37 #endif
38 }
39 
test_very_wide_line(void)40 void test_very_wide_line (void)
41 {
42 #if 0
43                                                                                 float f = foo * bar; /* { dg-warning "95: test" } */
44 /* { dg-begin-multiline-output "" }
45       |        0         0         0         0         0         1         1
46       |        5         6         7         8         9         0         1
47       | 3456789012345678901234567890123456789012345678901234567890123456789012
48    43 |                                       float f = foo * bar;
49       |                                                 ~~~~^~~~~
50       |                                                     |
51       |                                                     label 0
52       |                                                 bar * foo
53    { dg-end-multiline-output "" } */
54 #endif
55 }
56 
57 /* Unit test for rendering of insertion fixit hints
58    (example taken from PR 62316).  */
59 
test_fixit_insert(void)60 void test_fixit_insert (void)
61 {
62 #if 0
63    int a[2][2] = { 0, 1 , 2, 3 }; /* { dg-warning "insertion hints" } */
64 /* { dg-begin-multiline-output "" }
65    63 |    int a[2][2] = { 0, 1 , 2, 3 };
66       |                    ^~~~
67       |                    {   }
68    { dg-end-multiline-output "" } */
69 #endif
70 }
71 
72 /* Unit test for rendering of "remove" fixit hints.  */
73 
test_fixit_remove(void)74 void test_fixit_remove (void)
75 {
76 #if 0
77   int a;; /* { dg-warning "example of a removal hint" } */
78 /* { dg-begin-multiline-output "" }
79    77 |   int a;;
80       |         ^
81       |         -
82    { dg-end-multiline-output "" } */
83 #endif
84 }
85 
86 /* Unit test for rendering of "replace" fixit hints.  */
87 
test_fixit_replace(void)88 void test_fixit_replace (void)
89 {
90 #if 0
91   gtk_widget_showall (dlg); /* { dg-warning "example of a replacement hint" } */
92 /* { dg-begin-multiline-output "" }
93    91 |   gtk_widget_showall (dlg);
94       |   ^~~~~~~~~~~~~~~~~~
95       |   gtk_widget_show_all
96    { dg-end-multiline-output "" } */
97 #endif
98 }
99 
100 
101 /* Unit test for rendering of fix-it hints that add new lines.  */
102 
test_fixit_insert_newline(void)103 void test_fixit_insert_newline (void)
104 {
105 #if 0
106   switch (op)
107     {
108     case 'a':
109       x = a;
110     case 'b':  /* { dg-warning "newline insertion" } */
111       x = b;
112     }
113 /* { dg-begin-multiline-output "" }
114   109 |       x = a;
115   +++ |+      break;
116   110 |     case 'b':
117       |     ^~~~~~~~
118    { dg-end-multiline-output "" } */
119 #endif
120 }
121