diff --git a/instrumenter.go b/instrumenter.go index fff6a27..3a9e610 100644 --- a/instrumenter.go +++ b/instrumenter.go @@ -649,6 +649,10 @@ func (i *instrumenter) writeGobcoBlackBox(pkgs []*ast.Package, dstDir string) { "\n" + "func GobcoCover(idx int, cond bool) bool {\n" + "\t" + "return " + pkgName + ".GobcoCover(idx, cond)\n" + + "}\n" + + "\n" + + "func GobcoFinish(code int) int {\n" + + "\t" + "return " + pkgName + ".GobcoFinish(code)\n" + "}\n" writeFile(filepath.Join(dstDir, "gobco_bridge_test.go"), text) @@ -700,10 +704,7 @@ func (gen codeGenerator) typeAssertExpr(x string, typ ast.Expr) ast.Expr { func (gen codeGenerator) callFinish(arg ast.Expr) ast.Expr { return &ast.CallExpr{ - Fun: &ast.SelectorExpr{ - X: gen.ident("gobcoCounts"), - Sel: gen.ident("finish"), - }, + Fun: gen.ident("GobcoFinish"), Lparen: gen.pos, Args: []ast.Expr{arg}, Ellipsis: token.NoPos, diff --git a/main_test.go b/main_test.go index 092ccc5..2ff67ad 100644 --- a/main_test.go +++ b/main_test.go @@ -470,10 +470,10 @@ func Test_gobcoMain__TestMainTest(t *testing.T) { s := NewSuite(t) defer s.TearDownTest() - stdout, stderr := s.RunMain(1, "gobco", "-verbose", "testdata/testmaintest") + stdout, stderr := s.RunMain(0, "gobco", "-verbose", "testdata/testmaintest") - s.CheckContains(stdout, "[build failed]") - s.CheckContains(stderr, ": undefined: gobcoCounts") + s.CheckContains(stdout, "Condition coverage: 1/2") + _ = stderr } func Test_gobcoMain__oddeven(t *testing.T) { diff --git a/templates/gobco_fixed.go b/templates/gobco_fixed.go index 7247a70..aa77056 100644 --- a/templates/gobco_fixed.go +++ b/templates/gobco_fixed.go @@ -125,3 +125,8 @@ func (st *gobcoStats) finish(exitCode int) int { func GobcoCover(idx int, cond bool) bool { return gobcoCounts.cover(idx, cond) } + +// GobcoFinish needs to be exported to black-box test packages. +func GobcoFinish(code int) int { + return gobcoCounts.finish(code) +} diff --git a/testdata/testmaintest/add.go b/testdata/testmaintest/add.go index 9b7abbf..5d76ebe 100644 --- a/testdata/testmaintest/add.go +++ b/testdata/testmaintest/add.go @@ -1,5 +1,9 @@ package add func Add(x, y int) int { - return x + y + if x > y { + return x + y + } else { + return y + x + } }