-
Notifications
You must be signed in to change notification settings - Fork 76
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
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
16cbf02
Adding a "show-coverage" command that parses a coverage file and oupu…
caiosba 9e507b9
Fixing indentation
caiosba a957965
Better code organization
caiosba 67814db
Extracting one more function
caiosba 7461510
Just to trigger tests again since they are passing locally
caiosba 52b42a3
Merge branch 'master' of https://github.com/codeclimate/test-reporter
caiosba 65010d7
Fixing test (that also happens on master)
caiosba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"io/ioutil" | ||
"encoding/json" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var showCoverageCmd = &cobra.Command{ | ||
Use: "show-coverage", | ||
Short: "Show coverage results in standard output", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
return errors.New("you must pass in one file with the coverage results") | ||
} | ||
|
||
dat, err := ioutil.ReadFile(args[0]) | ||
if err != nil { | ||
return errors.New("could not open input file") | ||
} | ||
|
||
var result map[string]interface{} | ||
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)))) | ||
if int(line_counts["missed"].(float64)) > 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 { | ||
var uncovered_lines []int | ||
var values []interface{} | ||
json.Unmarshal([]byte(file["coverage"].(string)), &values) | ||
for i, value := range values { | ||
if value != nil && int(value.(float64)) == 0 { | ||
uncovered_lines = append(uncovered_lines, i + 1) | ||
} | ||
} | ||
uncovered_lines_str := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(uncovered_lines)), ", "), "[]") | ||
fmt.Println(fmt.Sprintf("%s: %s", file["name"], uncovered_lines_str)) | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(showCoverageCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
% CC-TEST-REPORTER-SHOW-COVERAGE(1) User Manuals | ||
% Meedan <hello@meedan.com> | ||
% March 2020 | ||
|
||
# PROLOG | ||
|
||
This is a sub-command of **cc-test-reporter**(1). | ||
|
||
# SYNOPSIS | ||
|
||
**cc-test-reporter-show-coverage** FILE | ||
|
||
# DESCRIPTION | ||
|
||
Show the coverage results from a Code Climate coverage JSON file. | ||
|
||
# OPTIONS | ||
|
||
## FILE | ||
|
||
Input file. Must be a valid Code Climate coverage JSON file, for example, the | ||
output of *cc-test-reporter format-coverage* or | ||
*cc-test-reporter sum-coverage* command. | ||
|
||
# INPUT VALIDATION | ||
|
||
Must be a valid Code Climate coverage JSON file, for example, the | ||
output of *cc-test-reporter format-coverage* or | ||
*cc-test-reporter sum-coverage* command. | ||
|
||
# ENVIRONMENT VARIABLES | ||
|
||
None | ||
|
||
# SEE ALSO | ||
|
||
**cc-test-reporter-format-coverage**(1). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done