LCOV - code coverage report
Current view: top level - gcc/diagnostics - selftest-source-printing.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 3 3
Test Date: 2025-09-20 13:40:47 Functions: - 0 0
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Support for selftests involving diagnostic_show_locus.
       2                 :             :    Copyright (C) 1999-2025 Free Software Foundation, Inc.
       3                 :             : 
       4                 :             : This file is part of GCC.
       5                 :             : 
       6                 :             : GCC is free software; you can redistribute it and/or modify it under
       7                 :             : the terms of the GNU General Public License as published by the Free
       8                 :             : Software Foundation; either version 3, or (at your option) any later
       9                 :             : version.
      10                 :             : 
      11                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14                 :             : for more details.
      15                 :             : 
      16                 :             : You should have received a copy of the GNU General Public License
      17                 :             : along with GCC; see the file COPYING3.  If not see
      18                 :             : <http://www.gnu.org/licenses/>.  */
      19                 :             : 
      20                 :             : #ifndef GCC_DIAGNOSTICS_SELFTEST_SOURCE_PRINTING_H
      21                 :             : #define GCC_DIAGNOSTICS_SELFTEST_SOURCE_PRINTING_H
      22                 :             : 
      23                 :             : #include "selftest.h"
      24                 :             : #include "diagnostics/file-cache.h"
      25                 :             : 
      26                 :             : /* The selftest code should entirely disappear in a production
      27                 :             :    configuration, hence we guard all of it with #if CHECKING_P.  */
      28                 :             : 
      29                 :             : #if CHECKING_P
      30                 :             : 
      31                 :             : namespace diagnostics {
      32                 :             : namespace selftest {
      33                 :             : 
      34                 :             : /* RAII class for use in selftests involving diagnostic_show_locus.
      35                 :             : 
      36                 :             :    Manages creating and cleaning up the following:
      37                 :             :    - writing out a temporary .c file containing CONTENT
      38                 :             :    - temporarily override the global "line_table" (using CASE_) and
      39                 :             :      push a line_map starting at the first line of the temporary file
      40                 :             :    - provide a file_cache.  */
      41                 :             : 
      42                 :             : struct source_printing_fixture
      43                 :             : {
      44                 :             :   source_printing_fixture (const ::selftest::line_table_case &case_,
      45                 :             :                            const char *content);
      46                 :             : 
      47                 :         544 :   const char *get_filename () const
      48                 :             :   {
      49                 :         544 :     return m_tmp_source_file.get_filename ();
      50                 :             :   }
      51                 :             : 
      52                 :             :   const char *m_content;
      53                 :             :   ::selftest::temp_source_file m_tmp_source_file;
      54                 :             :   ::selftest::line_table_test m_ltt;
      55                 :             :   file_cache m_fc;
      56                 :             : };
      57                 :             : 
      58                 :             : /* Fixture for one-liner tests exercising multibyte awareness.  For
      59                 :             :    simplicity we stick to using two multibyte characters in the test, U+1F602
      60                 :             :    == "\xf0\x9f\x98\x82", which uses 4 bytes and 2 display columns, and U+03C0
      61                 :             :    == "\xcf\x80", which uses 2 bytes and 1 display column.
      62                 :             : 
      63                 :             :    This works with the following 1-line source file:
      64                 :             : 
      65                 :             :      .0000000001111111111222222   display
      66                 :             :      .1234567890123456789012345   columns
      67                 :             :      "SS_foo = P_bar.SS_fieldP;\n"
      68                 :             :      .0000000111111111222222223   byte
      69                 :             :      .1356789012456789134567891   columns
      70                 :             : 
      71                 :             :    Here SS represents the two display columns for the U+1F602 emoji and
      72                 :             :    P represents the one display column for the U+03C0 pi symbol.  */
      73                 :             : 
      74                 :         288 : struct source_printing_fixture_one_liner_utf8
      75                 :             :   : public source_printing_fixture
      76                 :             : {
      77                 :             :   source_printing_fixture_one_liner_utf8 (const ::selftest::line_table_case &case_);
      78                 :             : };
      79                 :             : 
      80                 :             : } // namespace diagnostics::selftest
      81                 :             : } // namespace diagnostics
      82                 :             : 
      83                 :             : #endif /* #if CHECKING_P */
      84                 :             : 
      85                 :             : #endif /* GCC_DIAGNOSTICS_SELFTEST_SOURCE_PRINTING_H */
        

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.