Skip to content

Instantly share code, notes, and snippets.

@rebornwwp
Last active January 10, 2021 19:01
Show Gist options
  • Save rebornwwp/d7e1ee15522353832d6a68a9dcfb7cb1 to your computer and use it in GitHub Desktop.
Save rebornwwp/d7e1ee15522353832d6a68a9dcfb7cb1 to your computer and use it in GitHub Desktop.
go_coverage_for_function
cover () {
local t=$(mktemp -t cover)
go test $COVERFLAGS -coverprofile=$t $@ \
&& go tool cover -func=$t \
&& unlink $t
}
cover-web() {
t=$(tempfile)
go test $COVERFLAGS -coverprofile=$t $@ && go tool cover -html=$t && unlink $t
}
# stress test in unit test
#!/usr/bin/env bash -e
go test -c
# comment above and uncomment below to enable the race builder
# go test -c -race
PKG=$(basename $(pwd))
while true ; do
export GOMAXPROCS=$[ 1 + $[ RANDOM % 128 ]]
./$PKG.test $@ 2>&1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment