Skip to content

Instantly share code, notes, and snippets.

@KEINOS
Last active August 12, 2021 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KEINOS/f15d018ceb6d2a2103c581b41530ad49 to your computer and use it in GitHub Desktop.
Save KEINOS/f15d018ceb6d2a2103c581b41530ad49 to your computer and use it in GitHub Desktop.
[Golang][go-carpet] Bash sample of how to display / print only uncovered (not 100% of coverage) source files in "go-carpet" of Golang.
#!/bin/bash
name_file_coverage='coverage.out'
# getNameFilesUncovered echoes file names in comma-separated list which didn't
# cover 100%. This will be used for “go-carpet` -file option.
function getNameFilesUncovered() {
list=$(go tool cover -func="$name_file_coverage" | grep -v '100.0%\|init\|total' | awk '{print $1}')
echo "$list" | while IFS= read -r line; do
basename "${line}" | sed -e 's/\.[^\.]*$/\.go/'
done | uniq | tr '\n' ','
}
# Run test and create cover profile
go test -timeout 30s -cover -v -coverprofile "$name_file_coverage" ./...
# Run go-carpet by specifing files into test
go-carpet -file "$(getNameFilesUncovered)"
@KEINOS
Copy link
Author

KEINOS commented Aug 12, 2021

To run all the tests and show the coverage pretty, simply run:

$ go-carpet -include-vendor
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment