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

New command "show-coverage" #424

Merged
merged 7 commits into from
Mar 26, 2020
Merged

New command "show-coverage" #424

merged 7 commits into from
Mar 26, 2020

Conversation

caiosba
Copy link
Contributor

@caiosba caiosba commented Mar 10, 2020

We wanted to show the coverage results easily in our Travis job output log, and we had two parallel jobs, one with the unit tests and the other one with the functional tests. We use the sum-coverage command to combine those two into a single coverage file.

This PR adds a new command show-coverage which parses that single coverage file and outputs the coverage information, for example, coverage percentage, number of covered lines, total number of lines, number of missing lines and which lines from which files are not covered. Example output:

Coverage: 99.55% (10531/10579 lines covered, 48 missing)
Uncovered lines by file:
lib/check_config.rb: 4, 5
app/controllers/concerns/twitter_authentication.rb: 6, 8, 10

@CLAassistant
Copy link

CLAassistant commented Mar 10, 2020

CLA assistant check
All committers have signed the CLA.

@efueger
Copy link
Member

efueger commented Mar 10, 2020

Hi @caiosba - thanks for the PR. I've just put this in the queue for our engineers to review. 👌

json.Unmarshal([]byte(string(dat)), &result)
line_counts := result["line_counts"].(map[string]interface{})
header := "Coverage: %.2f%% (%d/%d lines covered, %d missing)"
fmt.Println(fmt.Sprintf(header, result["covered_percent"], int(line_counts["covered"].(float64)), int(line_counts["total"].(float64)), int(line_counts["missed"].(float64))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The body of this function is a bit dense. Do you mind extracting a few new functions to smooth out the read?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@filipesperandio filipesperandio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea.
Gotta see whats going on with the CI, but this seems good.

Comment on lines 56 to 67
if getLineCount(result, "missed") > 0 {

fmt.Println("Uncovered lines by file:")
files := result["source_files"].([]interface{})

for _, file_obj := range files {
file := file_obj.(map[string]interface{})
if file["covered_percent"].(float64) < 100 {
printUncoveredLinesFromFile(file)
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about another one here? 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another one what? 😁

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function!
I would say something like printUncoveredLines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, makes sense... done! :)

@efueger
Copy link
Member

efueger commented Mar 25, 2020

Looks like both sets of tests failed:

image

@caiosba
Copy link
Contributor Author

caiosba commented Mar 25, 2020

Looks like both sets of tests failed:

image

I can't see which part of my code would trigger this failure... can I be sure it's working for the main branch? BTW the failure I see is that the double quotes are escaped.

@caiosba
Copy link
Contributor Author

caiosba commented Mar 25, 2020

I'll try to run the tests locally to see.

@caiosba
Copy link
Contributor Author

caiosba commented Mar 25, 2020

I was able to reproduce the test failure by running them in the circleci/golang:latest Docker image, and the same test fails on master as well. But I just fixed it in this PR's branch.

@filipesperandio
Copy link
Contributor

@caiosba thanks for looking into it, wasn't finding the time to dig.
Yeah, looks like the underlying dependencies got in the way and the fix seems fine. 👍

@filipesperandio filipesperandio merged commit 79bdc00 into codeclimate:master Mar 26, 2020
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

Successfully merging this pull request may close these issues.

None yet

4 participants