Skip to content

Instantly share code, notes, and snippets.

@axw
Last active August 29, 2015 14:09
Show Gist options
  • Save axw/2fa39577d3f09358e55a to your computer and use it in GitHub Desktop.
Save axw/2fa39577d3f09358e55a to your computer and use it in GitHub Desktop.
Coverage testing of "main" program
package main
import "flag"
var b = flag.Bool("myflag", false, "description")
func main() {
flag.Parse()
if *b {
println("true")
} else {
println("false")
}
}
package main
import "testing"
func TestMain(t *testing.T) {
main()
}
$ go test -coverprofile=test.true.prof -myflag=true
$ gocov convert test.true.prof > test.true.gocov
$ gocov annotate test.true.gocov
7 func main() {
8 flag.Parse()
9 if *b {
10 println("true")
11 } else {
12 MISS println("false")
13 }
14 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment