Skip to content

Commit

Permalink
added support testing short coverage (#13)
Browse files Browse the repository at this point in the history
* added support testing short coverage

* append short and tags flags in coverage command

* deleted unnecesary initialization

* Small change to wording for clarity.

Co-authored-by: Jordan Poles <jpoles1@users.noreply.github.com>
  • Loading branch information
daltemen and jpoles1 authored Mar 10, 2020
1 parent 052f42b commit 8ea8613
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ Test code coverage using build tags:

<hr>

<hr>

Test code coverage, skipping short tests:

`gopherbadger -short`

<hr>

## Confused?

Try running:
Expand Down
22 changes: 16 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import (
"github.com/fatih/color"
)

const (
testCommand = "go test ./... -coverprofile=coverage.out"
toolCoverCommand = "go tool cover -func=coverage.out"
)

func getCommandOutput(commandString string) chan float64 {
cmd := exec.Command("bash", "-c", commandString)
cmd.Stderr = os.Stderr
Expand Down Expand Up @@ -73,6 +78,7 @@ func main() {
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")
shortFlag := flag.Bool("short", false, "It will skip tests marked as testing.Short()")
flag.Parse()

if !containsString(badgeStyles, *badgeStyleFlag) {
Expand All @@ -84,17 +90,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.")
if *tagsFlag != "" || *shortFlag {
log.Println("Warning: When the covercmd flag is used the -tags and -short flags 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"
flagsCommands := ""
if *tagsFlag != "" {
flagsCommands = flagsCommands + " -tags \"" + *tagsFlag + "\""
}
if *shortFlag {
flagsCommands = flagsCommands + " -short"
}
coverageCommand = fmt.Sprintf("%s %s && %s", testCommand, flagsCommands, toolCoverCommand)
}

if *manualCoverageFlag == -1 {
Expand Down

0 comments on commit 8ea8613

Please sign in to comment.