Last active
August 12, 2021 01:45
-
-
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.
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
#!/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)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run all the tests and show the coverage pretty, simply run: