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

Incorrect visualization of code coverage report for Golang #479

Closed
georgethebeatle opened this issue Dec 2, 2021 · 3 comments
Closed

Incorrect visualization of code coverage report for Golang #479

georgethebeatle opened this issue Dec 2, 2021 · 3 comments
Assignees

Comments

@georgethebeatle
Copy link
Contributor

Hello there,

My team has set up code coverage reporting for our project. It is a golang project and we are generating cover.out files in the gocov format. We noticed some weird looking files in our report

I am also attaching a screenshot of the relevant section in case the report is changed by future builds:
Screenshot 2021-12-01 at 17 06 32

There are a couple of things to be noted there:

  • line 39 looks like it is not a statement, while actially it is
  • line 47 is reported as covered, but line 48 is reported as not covered, which is impossible, because they are two adjacent lines in the same conditional statement - they should either be both covered or both not covered
  • line 43 and line 50 both consist of a closing brace ({). Line 50 is displayed as a statement that is not covered, while line 43 is displayed as a non-statement, which is inconsistent.

We took a look at our raw cover.out file, which is in gocov format and it looks fine to us. Here is a screenshot of the same section of the code as displayed by the html report generated by go tool cover -html=cover.out:
Screenshot 2021-12-02 at 15 00 05

As you can see none of the above mentioned anomalies are present, meaning that the cover.out file is generated correctly.

We went a bit further and converted the raw file to the codeclimate format using the latest test reporter. Here is the relevant section of the json file:

    {
      "blob_id": "89e3dca239b3cb84a3a439033582a5c5782dcddd",
      "coverage": "[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,3,null,null,null,null,null,null,3,3,3,3,3,null,null,1,1,1,null,null,null,3,3,0,0,0,null,null,3,3,null,null,3,3,3,null,null,1,null,null,3]",
      "covered_percent": 85.71428571428571,
      "covered_strength": 2.1904761904761907,
      "line_counts": {
        "missed": 3,
        "covered": 18,
        "total": 21
      },
      "name": "api/apis/job_handler.go"
    },

We interpreted the coverage key of that json a a bitmap, each element corresponding to a line, where null is not a statement and a number means that the line is a statement and represents how many times the statement is visited. This interpretation aligned perfectly with the first screenshot above and confirmed our suspicion that the test reporter is not formatting the cover.out correctly.

Here is the full cover.out file for more detailed information:
cover.out.txt

danail-branekov added a commit to eirini-forks/test-reporter that referenced this issue Dec 3, 2021
Fixes issue codeclimate#479

The formatter used to assume that the number of statements always equals
the number of lines in a block. This is not true when there are blank
lines for example. This change colours by line number rather than by
statement.

Co-authored-by: Georgi Sabev <georgethebeatle@gmail.com>
Co-authored-by: Danail Branekov <danailster@gmail.com>
danail-branekov added a commit to cloudfoundry/korifi that referenced this issue Dec 3, 2021
It fixes the following issue:
codeclimate/test-reporter#479

Co-authored-by: Georgi Sabev <georgethebeatle@gmail.com>
danail-branekov added a commit to cloudfoundry/korifi that referenced this issue Dec 3, 2021
It fixes the following issue:
codeclimate/test-reporter#479

Co-authored-by: Georgi Sabev <georgethebeatle@gmail.com>
@georgethebeatle
Copy link
Contributor Author

We opened a PR that fixes this issue

@f-moya
Copy link
Contributor

f-moya commented Dec 3, 2021

@georgethebeatle will be looking at this next week 👍🏼

f-moya pushed a commit that referenced this issue Dec 6, 2021
Fixes issue #479

The formatter used to assume that the number of statements always equals
the number of lines in a block. This is not true when there are blank
lines for example. This change colours by line number rather than by
statement.

Co-authored-by: Georgi Sabev <georgethebeatle@gmail.com>
Co-authored-by: Danail Branekov <danailster@gmail.com>

Co-authored-by: Danail Branekov <danailster@gmail.com>
@georgethebeatle
Copy link
Contributor Author

This issue has been addressed by PR #480, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants