diff --git a/instrumenter.go b/instrumenter.go index 999ebce..d635713 100644 --- a/instrumenter.go +++ b/instrumenter.go @@ -467,9 +467,7 @@ func (i *instrumenter) replace(n ast.Node) bool { // related to the instrumented condition. Especially for switch statements, the // position may differ from the expression that is wrapped. func (i *instrumenter) callCover(expr ast.Expr, pos token.Pos, code string) ast.Expr { - if !pos.IsValid() { - panic("pos must refer to the code from before instrumentation") - } + assert(pos.IsValid(), "pos must refer to the code from before instrumentation") start := i.fset.Position(pos) if !strings.HasSuffix(start.Filename, ".go") { @@ -551,9 +549,7 @@ func (i *instrumenter) instrumentTestMain(astFile *ast.File) { i.hasTestMain = true ast.Inspect(decl.Body, wrapOsExit) - if !seenOsExit { - panic("gobco: can only handle TestMain with explicit call to os.Exit") - } + assert(seenOsExit, "can only handle TestMain with explicit call to os.Exit") } } } @@ -886,9 +882,3 @@ func shouldBuild(filename string) bool { ok(err) return m } - -func ok(err error) { - if err != nil { - panic(err) - } -} diff --git a/main.go b/main.go index c7bc4cf..85eb89d 100644 --- a/main.go +++ b/main.go @@ -117,9 +117,7 @@ func (g *gobco) parseArgs(args []string) { args = []string{"."} } - if len(args) > 1 { - panic("gobco: checking multiple packages doesn't work yet") - } + assert(len(args) <= 1, "checking multiple packages doesn't work yet") for _, arg := range args { arg = filepath.FromSlash(arg) diff --git a/util.go b/util.go index f6386e8..b5daddf 100644 --- a/util.go +++ b/util.go @@ -94,3 +94,15 @@ func (s *sliceFlag) Set(str string) error { *s.values = append(*s.values, str) return nil } + +func ok(err error) { + if err != nil { + panic(err) + } +} + +func assert(cond bool, msg string) { + if !cond { + panic(msg) + } +}