(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
plugin/
diagnostic-test-show-locus-generate-patch.c
       1  /* { dg-do compile } */
       2  /* { dg-options "-O -fdiagnostics-generate-patch" } */
       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  /* Unit test for rendering of insertion fixit hints
      12     (example taken from PR 62316).  */
      13  
      14  void test_fixit_insert (void)
      15  {
      16  #if 0
      17     int a[2][2] = { 0, 1 , 2, 3 }; /* { dg-warning "insertion hints" } */
      18  #endif
      19  }
      20  
      21  /* Unit test for rendering of "remove" fixit hints.  */
      22  
      23  void test_fixit_remove (void)
      24  {
      25  #if 0
      26    int a;; /* { dg-warning "example of a removal hint" } */
      27  #endif
      28  }
      29  
      30  /* Unit test for rendering of "replace" fixit hints.  */
      31  
      32  void test_fixit_replace (void)
      33  {
      34  #if 0
      35    gtk_widget_showall (dlg); /* { dg-warning "example of a replacement hint" } */
      36  #endif
      37  }
      38  
      39  /* Unit test for rendering of fix-it hints that add new lines.  */
      40  
      41  void test_fixit_insert_newline (void)
      42  {
      43  #if 0
      44    switch (op)
      45      {
      46      case 'a':
      47        x = a;
      48      case 'b': /* { dg-warning "newline insertion" } */
      49        x = b;
      50      }
      51  #endif
      52  }
      53  
      54  /* Unit test for mutually-exclusive suggestions.  */
      55  
      56  void test_mutually_exclusive_suggestions (void)
      57  {
      58  #if 0
      59    original; /* { dg-warning "warning 1" } */
      60  /* { dg-warning "warning 2" "" { target *-*-* } .-1 } */
      61  /* We should not print the mutually-incompatible fix-it hints within
      62     the generated patch; they are not listed in the big expected
      63     multiline output below.  */
      64  #endif
      65  }
      66  
      67  /* Unit tests for add_fixit_insert_formatted.  */
      68  
      69  void test_add_fixit_insert_formatted_single_line (void)
      70  {
      71    {}
      72  }
      73  
      74  void test_add_fixit_insert_formatted_multiline (void)
      75  {
      76    if (1)
      77      {
      78      }
      79  }
      80  
      81  
      82  /* Verify the output from -fdiagnostics-generate-patch.
      83     We expect a header, containing the filename.  This is the absolute path,
      84     so we can only capture it via regexps.  */
      85  
      86  /* { dg-regexp "\\-\\-\\- .*" } */
      87  /* { dg-regexp "\\+\\+\\+ .*" } */
      88  
      89  /* Next, we expect the diff itself.  */
      90  /* { dg-begin-multiline-output "" }
      91  @@ -14,7 +14,7 @@
      92   void test_fixit_insert (void)
      93   {
      94   #if 0
      95  -   int a[2][2] = { 0, 1 , 2, 3 };
      96  +   int a[2][2] = { {0, 1} , 2, 3 };
      97   #endif
      98   }
      99   
     100  @@ -23,7 +23,7 @@
     101   void test_fixit_remove (void)
     102   {
     103   #if 0
     104  -  int a;;
     105  +  int a;
     106   #endif
     107   }
     108   
     109  @@ -32,7 +32,7 @@
     110   void test_fixit_replace (void)
     111   {
     112   #if 0
     113  -  gtk_widget_showall (dlg);
     114  +  gtk_widget_show_all (dlg);
     115   #endif
     116   }
     117   
     118  @@ -45,6 +45,7 @@
     119       {
     120       case 'a':
     121         x = a;
     122  +      break;
     123       case 'b':
     124         x = b;
     125       }
     126  @@ -68,7 +69,7 @@
     127   
     128   void test_add_fixit_insert_formatted_single_line (void)
     129   {
     130  -  {}
     131  +  {INSERTED-CONTENT}
     132   }
     133   
     134   void test_add_fixit_insert_formatted_multiline (void)
     135  @@ -76,6 +77,7 @@
     136     if (1)
     137       {
     138       }
     139  +  INSERTED-CONTENT
     140   }
     141   
     142   
     143     { dg-end-multiline-output "" } */