Testing os.Exit scenarios in Go with coverage information (coveralls.io/Goveralls)

With a slight refactoring, you may easily achieve 100% coverage. foo/bar.go: package foo import ( “fmt” “os” ) var osExit = os.Exit func Crasher() { fmt.Println(“Going down in flames!”) osExit(1) } And the testing code: foo/bar_test.go: package foo import “testing” func TestCrasher(t *testing.T) { // Save current function and restore at the end: oldOsExit := … Read more