Skip to content

Commit

Permalink
Merge pull request #10 from award28/issue_9
Browse files Browse the repository at this point in the history
Issue #9 Allow code coverage with build tags
  • Loading branch information
jpoles1 authored Feb 13, 2019
2 parents 3ab187c + 860d91e commit 1f4eedb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
27 changes: 24 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ Manually set the coverage value (note: do not include %):

<hr>

Test code coverage using build tags:

`gopherbadger -tags "unit"`

<hr>

## Confused?

Try running:
Expand Down
Binary file modified coverage_badge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 16 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ func main() {
badgeStyleFlag := flag.String("style", "flat", "Badge style from list: ["+strings.Join(badgeStyles, ",")+"]")
updateMdFilesFlag := flag.String("md", "", "A list of markdown filepaths for badge updates.")
coveragePrefixFlag := flag.String("prefix", "Go", "A prefix to specify the coverage in your badge.")
coverageCommandFlag := flag.String("covercmd", "go test ./... -coverprofile=coverage.out && go tool cover -func=coverage.out", "gocover command to run; must print coverage report to stdout")
coverageCommandFlag := flag.String("covercmd", "", "gocover command to run; must print coverage report to stdout")
manualCoverageFlag := flag.Float64("manualcov", -1.0, "A manually inputted coverage float.")
tagsFlag := flag.String("tags", "", "The build tests you'd like to include in your coverage")
flag.Parse()

if !containsString(badgeStyles, *badgeStyleFlag) {
Expand All @@ -83,8 +84,21 @@ func main() {
ImageExtension: ".png",
}
var coverageFloat float64

coverageCommand := ""
if *coverageCommandFlag != "" {
coverageCommand = *coverageCommandFlag
if *tagsFlag != "" {
log.Println("Warning: When the covercmd flag is used the tags flag will be ignored.")
}
} else if *tagsFlag != "" {
coverageCommand = "go test ./... -tags \"" + *tagsFlag + "\" -coverprofile=coverage.out && go tool cover -func=coverage.out"
} else {
coverageCommand = "go test ./... -coverprofile=coverage.out && go tool cover -func=coverage.out"
}

if *manualCoverageFlag == -1 {
coverageFloat = <-getCommandOutput(*coverageCommandFlag)
coverageFloat = <-getCommandOutput(coverageCommand)
} else {
coverageFloat = *manualCoverageFlag
}
Expand Down

0 comments on commit 1f4eedb

Please sign in to comment.