Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcovr reports 0% branches taken in html report when there are no branches in the code #149

Closed
austinglaser opened this issue Sep 16, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@austinglaser
Copy link

commented Sep 16, 2016

Use-case:

main.c:

int main(void)
{
    int x = 0;

    x++;
    x--;

    return x;
}

Compile and run:

$ gcc -fprofile-arcs -ftest-coverage -O0 main.c -o program
$ ./program

Generate html report:

$ gcovr -r . --html -o coverage.html

Generates this output:

coverage

Tool Version: (Installed through apt on kubuntu 16.04)

$ gcovr --version
gcovr 3.2

Copyright (2013) Sandia Corporation. Under the terms of Contract 
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
retains certain rights in this software.

(raw coverage.html):

<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <title>Head</title>
  <style media="screen" type="text/css">

    body
    {
      color: #000000;
      background-color: #FFFFFF;
    }

    /* Link formats: use maroon w/underlines */
    a:link
    {
      color: navy;
      text-decoration: underline;
    }
    a:visited
    {
      color: maroon;
      text-decoration: underline;
    }
    a:active
    {
      color: navy;
      text-decoration: underline;
    }

    /*** TD formats ***/
    td
    {
      font-family: sans-serif;
    }                                                                                                                                                                                                                                                                         
    td.title                                                                                                                                                                                                                                                                  
    {                                                                                                                                                                                                                                                                         
      text-align: center;                                                                                                                                                                                                                                                     
      padding-bottom: 10px;                                                                                                                                                                                                                                                   
      font-size: 20pt;                                                                                                                                                                                                                                                        
      font-weight: bold;                                                                                                                                                                                                                                                      
    }                                                                                                                                                                                                                                                                         

    /* TD Header Information */                                                                                                                                                                                                                                               
    td.headerName                                                                                                                                                                                                                                                             
    {                                                                                                                                                                                                                                                                         
      text-align: right;                                                                                                                                                                                                                                                      
      color: black;                                                                                                                                                                                                                                                           
      padding-right: 6px;                                                                                                                                                                                                                                                     
      font-weight: bold;                                                                                                                                                                                                                                                      
      vertical-align: top;                                                                                                                                                                                                                                                    
      white-space: nowrap;                                                                                                                                                                                                                                                    
    }                                                                                                                                                                                                                                                                         
    td.headerValue                                                                                                                                                                                                                                                            
    {                                                                                                                                                                                                                                                                         
      text-align: left;                                                                                                                                                                                                                                                       
      color: blue;                                                                                                                                                                                                                                                            
      font-weight: bold;                                                                                                                                                                                                                                                      
      white-space: nowrap;                                                                                                                                                                                                                                                    
    }                                                                                                                                                                                                                                                                         
    td.headerTableEntry                                                                                                                                                                                                                                                       
    {                                                                                                                                                                                                                                                                         
      text-align: right;                                                                                                                                                                                                                                                      
      color: black;                                                                                                                                                                                                                                                           
      font-weight: bold;                                                                                                                                                                                                                                                      
      white-space: nowrap;                                                                                                                                                                                                                                                    
      padding-left: 12px;                                                                                                                                                                                                                                                     
      padding-right: 4px;                                                                                                                                                                                                                                                     
      background-color: LightBlue;                                                                                                                                                                                                                                            
    }                                                                                                                                                                                                                                                                         
    td.headerValueLeg                                                                                                                                                                                                                                                         
    {                                                                                                                                                                                                                                                                         
      text-align: left;                                                                                                                                                                                                                                                       
      color: black;                                                                                                                                                                                                                                                           
      font-size: 80%;                                                                                                                                                                                                                                                         
      white-space: nowrap;
      padding-left: 10px;
      padding-right: 10px;
      padding-top: 2px;
    }

    /* Color of horizontal ruler */
    td.hr
    {
      background-color: navy;
      height:3px;
    }
    /* Footer format */
    td.footer
    {
      text-align: center;
      padding-top: 3px;
      font-family: sans-serif;
    }

    /* Coverage Table */    

    td.coverTableHead
    {
      text-align: center;
      color: white;
      background-color: SteelBlue;
      font-family: sans-serif;
      font-size: 120%;
      white-space: nowrap;
      padding-left: 4px;
      padding-right: 4px;
    }
    td.coverFile
    {
      text-align: left;
      padding-left: 10px;
      padding-right: 20px; 
      color: black;
      background-color: LightBlue;
      font-family: monospace;
      font-weight: bold;
      font-size: 110%;
    }
    td.coverBar
    {
      padding-left: 10px;
      padding-right: 10px;
      background-color: LightBlue;
    }
    td.coverBarOutline
    {
      background-color: white;
    }
    td.coverValue
    {
      padding-top: 2px;
      text-align: right;
      padding-left: 10px;
      padding-right: 10px;
      font-family: sans-serif;
      white-space: nowrap;
      font-weight: bold;
    }

    /* Link Details */
    a.detail:link
    {
      color: #B8D0FF;
      font-size:80%;
    }
    a.detail:visited
    {
      color: #B8D0FF;
      font-size:80%;
    }
    a.detail:active
    {
      color: #FFFFFF;
      font-size:80%;
    }

    .graphcont{
        color:#000;
        font-weight:700;
        float:left
    }

    .graph{
        float:left;
        background-color: white;
        position:relative;
        width:280px;
        padding:0
    }

    .graph .bar{
        display:block;
        position:relative;
        border:black 1px solid;
        text-align:center;
        color:#fff;
        height:10px;
        font-family:Arial,Helvetica,sans-serif;
        font-size:12px;
        line-height:1.9em
    }

    .graph .bar span{
        position:absolute;
        left:1em
    } 

    td.coveredLine,
    span.coveredLine
    {
        background-color: LightGreen!important;
    }

    td.uncoveredLine,
    span.uncoveredLine
    {
        background-color: LightPink!important;
    }

    .linecount
    {
        border-right: 1px gray solid;
        background-color: lightgray;
    }

    .src 
    {
        padding-left: 12px;
    }

    .srcHeader
    {
        font-family: monospace; 
        font-weight: bold;
    }

    pre 
    {
        height : 15px;
        margin-top: 0;
        margin-bottom: 0;
    }

    .lineno
    {
        background-color: #EFE383;
        border-right: 1px solid #BBB15F;
    }

  </style>
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">GCC Code Coverage Report</td></tr>
    <tr><td class="hr"></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerName">Directory:</td>
            <td width="35%" class="headerValue">.</td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerValue" style="text-align:right;">Exec</td>
            <td width="10%" class="headerValue" style="text-align:right;">Total</td>
            <td width="15%" class="headerValue" style="text-align:right;">Coverage</td>
          </tr>
          <tr>
            <td class="headerName">Date:</td>
            <td class="headerValue">2016-09-16</td>
            <td></td>
            <td class="headerName">Lines:</td>
            <td class="headerTableEntry">5</td>
            <td class="headerTableEntry">5</td>
            <td class="headerTableEntry" style="background-color:LightGreen">100.0 %</td>
          </tr>
          <tr>
            <td class="headerName">Legend:</td>
            <td class="headerValueLeg">
              <span style="background-color:LightPink">low: &lt; 75.0 %</span>
              <span style="background-color:#FFFF55">medium: &gt;= 75.0 %</span>
              <span style="background-color:LightGreen">high: &gt;= 90.0 %</span>
            </td>
            <td></td>
            <td class="headerName">Branches:</td>
            <td class="headerTableEntry">0</td>
            <td class="headerTableEntry">0</td>
            <td class="headerTableEntry" style="background-color:LightPink">0.0 %</td>
          </tr>
        </table>
      </td>
    </tr>

    <tr><td class="hr"></td></tr>
  </table>

  <center>
  <table width="80%" cellpadding=1 cellspacing=1 border=0>
    <tr>
      <td width="44%"><br></td>
      <td width="8%"></td>
      <td width="8%"></td>
      <td width="8%"></td>
      <td width="8%"></td>
      <td width="8%"></td>
    </tr>
    <tr>
      <td class="coverTableHead">File</td>
      <td class="coverTableHead" colspan=3>Lines</td>
      <td class="coverTableHead" colspan=2>Branches</td>
    </tr>


    <tr>
      <td class="coverFile" >main.c</td>
      <td class="coverBar" align="center" >
        <table border=0 cellspacing=0 cellpadding=1><tr><td class="coverBarOutline">
                <div class="graph"><strong class="bar" style="width:100.0%; background-color:green"></strong></div>
                </td></tr></table>
      </td>
      <td class="CoverValue" style="font-weight:bold; background-color:LightGreen;">100.0&nbsp;%</td>
      <td class="CoverValue" style="font-weight:bold; background-color:LightGreen;">5 / 5</td>
      <td class="CoverValue" style="background-color:LightGreen;">100.0&nbsp;%</td>
      <td class="CoverValue" style="background-color:LightGreen;">0 / 0</td>
    </tr>


    <tr>
      <td width="44%"><br></td>
      <td width="8%"></td>
      <td width="8%"></td>
      <td width="8%"></td>
      <td width="8%"></td>
      <td width="8%"></td>
    </tr>
  </table>
  </center>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="hr"><td></tr>
    <tr><td class="footer">Generated by: <a href="http://gcovr.com">GCOVR (Version 3.2)</a></td></tr>
  </table>
  <br>

</body>

</html>
@austinglaser

This comment has been minimized.

Copy link
Author

commented Sep 16, 2016

Confirmed the same behavior with a fresh clone of the git repository

@latk

This comment has been minimized.

Copy link
Member

commented Jan 15, 2018

Thank you for reporting this issue and for the excellent bug report!

I'm closing this issue as a duplicate of #105 where a potential fix has been suggested.

@latk latk closed this Jan 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.