(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
plugin/
diagnostic-test-show-locus-color.c
       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 = ESC[32mESC[KESC[32mmyvarESC[mESC[KESC[01;35mESC[KESC[35mESC[01;35m.ESC[mESC[KESC[34mESC[KESC[34mxESC[mESC[K;
      18             ESC[32mESC[KESC[32m~~~~~ESC[mESC[KESC[01;35mESC[KESC[35mESC[01;35m^ESC[mESC[KESC[34mESC[KESC[34m~ESC[mESC[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 = ESC[32mESC[KESC[32mfirst_function ()ESC[mESC[K ESC[01;35mESC[KESC[35mESC[01;35m+ESC[mESC[K ESC[34mESC[KESC[34msecond_function ()ESC[mESC[K;
      30         ESC[32mESC[KESC[32m~~~~~~~~~~~~~~~~~ESC[mESC[K ESC[01;35mESC[KESC[35mESC[01;35m^ESC[mESC[K ESC[34mESC[KESC[34m~~~~~~~~~~~~~~~~~~ESC[mESC[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 = (ESC[32mESC[KESC[32mfirst_function ()ESC[mESC[K
      44          ESC[32mESC[KESC[32m~~~~~~~~~~~~~~~~~ESC[mESC[K
      45          ESC[01;35mESC[KESC[35mESC[01;35m+ESC[mESC[K ESC[34mESC[KESC[34msecond_function ()ESC[mESC[K);
      46          ESC[01;35mESC[KESC[35mESC[01;35m^ESC[mESC[K ESC[34mESC[KESC[34m~~~~~~~~~~~~~~~~~~ESC[mESC[K
      47          ESC[01;35mESC[KESC[35mESC[01;35m|ESC[mESC[K
      48          ESC[01;35mESC[KESC[35mESC[01;35mlabelESC[mESC[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 = (ESC[32mESC[KESC[32mfirst_function_with_a_very_long_name (lorem, ipsum, dolor, sit, amet,ESC[mESC[K
      70          ESC[32mESC[KESC[32m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ESC[mESC[K
      71          ESC[32mESC[KESC[32m|ESC[mESC[K
      72          ESC[32mESC[KESC[32mlabel 1ESC[mESC[K
      73   ESC[32mESC[KESC[32m                                            consectetur, adipiscing, elit,ESC[mESC[K
      74                                               ESC[32mESC[KESC[32m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ESC[mESC[K
      75   ESC[32mESC[KESC[32m                                            sed, eiusmod, tempor,ESC[mESC[K
      76                                               ESC[32mESC[KESC[32m~~~~~~~~~~~~~~~~~~~~~ESC[mESC[K
      77   ESC[32mESC[KESC[32m                                            incididunt, ut, labore, et,ESC[mESC[K
      78                                               ESC[32mESC[KESC[32m~~~~~~~~~~~~~~~~~~~~~~~~~~~ESC[mESC[K
      79   ESC[32mESC[KESC[32m                                            dolore, magna, aliqua)ESC[mESC[K
      80                                               ESC[32mESC[KESC[32m~~~~~~~~~~~~~~~~~~~~~~ESC[mESC[K
      81          ESC[01;35mESC[KESC[35mESC[01;35m+ESC[mESC[K ESC[34mESC[KESC[34msecond_function_with_a_very_long_name (lorem, ipsum, dolor, sit,
      82  ESC[34m        ESC[01;35mESC[KESC[35mESC[01;35m^ESC[mESC[K ESC[34mESC[KESC[34m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ESC[mESC[K
      83          ESC[01;35mESC[KESC[35mESC[01;35m|ESC[mESC[K ESC[34mESC[KESC[34m|ESC[mESC[K
      84          ESC[01;35mESC[KESC[35mESC[01;35m|ESC[mESC[K ESC[34mESC[KESC[34mlabel 2ESC[mESC[K
      85          ESC[01;35mESC[KESC[35mESC[01;35mlabel 0ESC[mESC[K
      86   ESC[34mESC[KESC[34m                                                amet, consectetur,ESC[mESC[K
      87                                                   ESC[34mESC[KESC[34m~~~~~~~~~~~~~~~~~~ESC[mESC[K
      88   ESC[34mESC[KESC[34m                                                adipiscing, elit, sed,ESC[mESC[K
      89                                                   ESC[34mESC[KESC[34m~~~~~~~~~~~~~~~~~~~~~~ESC[mESC[K
      90   ESC[34mESC[KESC[34m                                                eiusmod, tempor, incididunt,ESC[mESC[K
      91                                                   ESC[34mESC[KESC[34m~~~~~~~~~~~~~~~~~~~~~~~~~~~~ESC[mESC[K
      92   ESC[34mESC[KESC[34m                                                ut, labore, et, dolore,ESC[mESC[K
      93                                                   ESC[34mESC[KESC[34m~~~~~~~~~~~~~~~~~~~~~~~ESC[mESC[K
      94   ESC[34mESC[KESC[34m                                                magna, aliqua)ESC[mESC[K);
      95                                                   ESC[34mESC[KESC[34m~~~~~~~~~~~~~~ESC[mESC[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 = ESC[01;35mESC[KESC[35mESC[01;35m98.6fESC[mESC[K;
     106               ESC[01;35mESC[KESC[35mESC[01;35m^~~~~ESC[mESC[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 = ESC[01;35mESC[KESC[35mESC[01;35mfoo * barESC[mESC[K;
     117               ESC[01;35mESC[KESC[35mESC[01;35m~~~~^~~~~ESC[mESC[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   ESC[32mESC[KESC[32mxESC[mESC[K                                                    = ESC[01;35mESC[KESC[35mESC[01;35mfoo * barESC[mESC[K;
     131   ESC[32mESC[KESC[32m~ESC[mESC[K                                                      ESC[01;35mESC[KESC[35mESC[01;35m~~~~^~~~~ESC[mESC[K
     132   ESC[32mESC[KESC[32m|ESC[mESC[K                                                          ESC[01;35mESC[KESC[35mESC[01;35m|ESC[mESC[K
     133   ESC[32mESC[KESC[32mlabel 1ESC[mESC[K                                                    ESC[01;35mESC[KESC[35mESC[01;35mlabel 0ESC[mESC[K
     134                                                          ESC[32mESC[KESC[32mbar * fooESC[mESC[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 = ESC[01;35mESC[KESC[35mESC[01;35mxESC[mESC[K + ESC[32mESC[KESC[32myESC[mESC[K
     145          ESC[01;35mESC[KESC[35mESC[01;35mAESC[mESC[K   ESC[32mESC[KESC[32mBESC[mESC[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 =>ESC[32mESC[KESC[32m ESC[mESC[Kx)
     157                      ESC[32mESC[KESC[32m2ESC[mESC[K
     158        ESC[01;35mESC[KESC[35mESC[01;35m ESC[mESC[Ky = 5
     159        ESC[01;35mESC[KESC[35mESC[01;35m1ESC[mESC[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] = { ESC[01;35mESC[KESC[35mESC[01;35m0, 1ESC[mESC[K , 2, 3 };
     173                      ESC[01;35mESC[KESC[35mESC[01;35m^~~~ESC[mESC[K
     174                      ESC[32mESC[KESC[32m{ESC[mESC[K   ESC[32mESC[KESC[32m}ESC[mESC[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;ESC[01;35mESC[KESC[35mESC[01;35m;ESC[mESC[K
     187           ESC[01;35mESC[KESC[35mESC[01;35m^ESC[mESC[K
     188           ESC[31mESC[KESC[31m-ESC[mESC[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     ESC[01;35mESC[KESC[35mESC[01;35mgtk_widget_showallESC[mESC[K (dlg);
     201     ESC[01;35mESC[KESC[35mESC[01;35m^~~~~~~~~~~~~~~~~~ESC[mESC[K
     202     ESC[32mESC[KESC[32mgtk_widget_show_allESC[mESC[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  +ESC[32mESC[KESC[32m      break;ESC[mESC[K
     222       ESC[01;35mESC[KESC[35mESC[01;35mcase 'b'ESC[mESC[K:
     223       ESC[01;35mESC[KESC[35mESC[01;35m^~~~~~~~ESC[mESC[K
     224     { dg-end-multiline-output "" } */
     225  #endif
     226  }