mirror of
https://github.com/golang/go
synced 2024-11-23 18:20:04 -07:00
cmd/go: revert "output coverage report even if there are no test files"
Original CL description: When using test -cover or -coverprofile the output for "no test files" is the same format as for "no tests to run". Reverting because this CL changed cmd/go to build test binaries for packages that have no tests, leading to extra work and confusion. Updates #24570 Fixes #25789 Fixes #26157 Fixes #26242 Change-Id: Ibab1307d39dfaec0de9359d6d96706e3910c8efd Reviewed-on: https://go-review.googlesource.com/122518 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
b56e24782f
commit
7254cfc37b
@ -3262,43 +3262,6 @@ func TestGoTestBuildsAnXtestContainingOnlyNonRunnableExamples(t *testing.T) {
|
|||||||
tg.grepStdout("File with non-runnable example was built.", "file with non-runnable example was not built")
|
tg.grepStdout("File with non-runnable example was built.", "file with non-runnable example was not built")
|
||||||
}
|
}
|
||||||
|
|
||||||
// issue 24570
|
|
||||||
func TestGoTestCoverMultiPackage(t *testing.T) {
|
|
||||||
tg := testgo(t)
|
|
||||||
defer tg.cleanup()
|
|
||||||
tg.run("test", "-cover", "./testdata/testcover/...")
|
|
||||||
tg.grepStdout(`\?.*testdata/testcover/pkg1.*(\d\.\d\d\ds|cached).*coverage:.*0\.0% of statements \[no test files\]`, "expected [no test files] for pkg1")
|
|
||||||
tg.grepStdout(`ok.*testdata/testcover/pkg2.*(\d\.\d\d\ds|cached).*coverage:.*0\.0% of statements \[no tests to run\]`, "expected [no tests to run] for pkg2")
|
|
||||||
tg.grepStdout(`ok.*testdata/testcover/pkg3.*(\d\.\d\d\ds|cached).*coverage:.*100\.0% of statements`, "expected 100% coverage for pkg3")
|
|
||||||
}
|
|
||||||
|
|
||||||
// issue 24570
|
|
||||||
func TestGoTestCoverprofileMultiPackage(t *testing.T) {
|
|
||||||
tg := testgo(t)
|
|
||||||
defer tg.cleanup()
|
|
||||||
tg.creatingTemp("testdata/cover.out")
|
|
||||||
tg.run("test", "-coverprofile=testdata/cover.out", "./testdata/testcover/...")
|
|
||||||
tg.grepStdout(`\?.*testdata/testcover/pkg1.*(\d\.\d\d\ds|cached).*coverage:.*0\.0% of statements \[no test files\]`, "expected [no test files] for pkg1")
|
|
||||||
tg.grepStdout(`ok.*testdata/testcover/pkg2.*(\d\.\d\d\ds|cached).*coverage:.*0\.0% of statements \[no tests to run\]`, "expected [no tests to run] for pkg2")
|
|
||||||
tg.grepStdout(`ok.*testdata/testcover/pkg3.*(\d\.\d\d\ds|cached).*coverage:.*100\.0% of statements`, "expected 100% coverage for pkg3")
|
|
||||||
if out, err := ioutil.ReadFile("testdata/cover.out"); err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
} else {
|
|
||||||
if !bytes.Contains(out, []byte("mode: set")) {
|
|
||||||
t.Errorf(`missing "mode: set" in %s`, out)
|
|
||||||
}
|
|
||||||
if !bytes.Contains(out, []byte(`pkg1/a.go:5.10,7.2 1 0`)) && !bytes.Contains(out, []byte(`pkg1\a.go:5.10,7.2 1 0`)) {
|
|
||||||
t.Errorf(`missing "pkg1/a.go:5.10,7.2 1 0" in %s`, out)
|
|
||||||
}
|
|
||||||
if !bytes.Contains(out, []byte(`pkg2/a.go:5.10,7.2 1 0`)) && !bytes.Contains(out, []byte(`pkg2\a.go:5.10,7.2 1 0`)) {
|
|
||||||
t.Errorf(`missing "pkg2/a.go:5.10,7.2 1 0" in %s`, out)
|
|
||||||
}
|
|
||||||
if !bytes.Contains(out, []byte(`pkg3/a.go:5.10,7.2 1 1`)) && !bytes.Contains(out, []byte(`pkg3\a.go:5.10,7.2 1 1`)) {
|
|
||||||
t.Errorf(`missing "pkg3/a.go:5.10,7.2 1 1" in %s`, out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGoGenerateHandlesSimpleCommand(t *testing.T) {
|
func TestGoGenerateHandlesSimpleCommand(t *testing.T) {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
t.Skip("skipping because windows has no echo command")
|
t.Skip("skipping because windows has no echo command")
|
||||||
|
@ -49,6 +49,9 @@ type TestCover struct {
|
|||||||
// (for example, if there are no "package p" test files and
|
// (for example, if there are no "package p" test files and
|
||||||
// package p need not be instrumented for coverage or any other reason),
|
// package p need not be instrumented for coverage or any other reason),
|
||||||
// then the returned ptest == p.
|
// then the returned ptest == p.
|
||||||
|
//
|
||||||
|
// The caller is expected to have checked that len(p.TestGoFiles)+len(p.XTestGoFiles) > 0,
|
||||||
|
// or else there's no point in any of this.
|
||||||
func TestPackagesFor(p *Package, cover *TestCover) (pmain, ptest, pxtest *Package, err error) {
|
func TestPackagesFor(p *Package, cover *TestCover) (pmain, ptest, pxtest *Package, err error) {
|
||||||
var imports, ximports []*Package
|
var imports, ximports []*Package
|
||||||
var stk ImportStack
|
var stk ImportStack
|
||||||
|
@ -781,6 +781,14 @@ var windowsBadWords = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, printAction *work.Action, err error) {
|
func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, printAction *work.Action, err error) {
|
||||||
|
if len(p.TestGoFiles)+len(p.XTestGoFiles) == 0 {
|
||||||
|
build := b.CompileAction(work.ModeBuild, work.ModeBuild, p)
|
||||||
|
run := &work.Action{Mode: "test run", Package: p, Deps: []*work.Action{build}}
|
||||||
|
addTestVet(b, p, run, nil)
|
||||||
|
print := &work.Action{Mode: "test print", Func: builderNoTest, Package: p, Deps: []*work.Action{run}}
|
||||||
|
return build, run, print, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Build Package structs describing:
|
// Build Package structs describing:
|
||||||
// pmain - pkg.test binary
|
// pmain - pkg.test binary
|
||||||
// ptest - package + test files
|
// ptest - package + test files
|
||||||
@ -1168,17 +1176,13 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
|
|||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
norun := ""
|
norun := ""
|
||||||
res := "ok"
|
|
||||||
if !testShowPass && !testJSON {
|
if !testShowPass && !testJSON {
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
}
|
}
|
||||||
if len(a.Package.TestGoFiles)+len(a.Package.XTestGoFiles) == 0 {
|
if bytes.HasPrefix(out, noTestsToRun[1:]) || bytes.Contains(out, noTestsToRun) {
|
||||||
res = "? "
|
|
||||||
norun = " [no test files]"
|
|
||||||
} else if bytes.HasPrefix(out, noTestsToRun[1:]) || bytes.Contains(out, noTestsToRun) {
|
|
||||||
norun = " [no tests to run]"
|
norun = " [no tests to run]"
|
||||||
}
|
}
|
||||||
fmt.Fprintf(cmd.Stdout, "%s \t%s\t%s%s%s\n", res, a.Package.ImportPath, t, coveragePercentage(out), norun)
|
fmt.Fprintf(cmd.Stdout, "ok \t%s\t%s%s%s\n", a.Package.ImportPath, t, coveragePercentage(out), norun)
|
||||||
c.saveOutput(a)
|
c.saveOutput(a)
|
||||||
} else {
|
} else {
|
||||||
base.SetExitStatus(1)
|
base.SetExitStatus(1)
|
||||||
@ -1592,3 +1596,15 @@ func builderPrintTest(b *work.Builder, a *work.Action) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// builderNoTest is the action for testing a package with no test files.
|
||||||
|
func builderNoTest(b *work.Builder, a *work.Action) error {
|
||||||
|
var stdout io.Writer = os.Stdout
|
||||||
|
if testJSON {
|
||||||
|
json := test2json.NewConverter(lockedStdout{}, a.Package.ImportPath, test2json.Timestamp)
|
||||||
|
defer json.Close()
|
||||||
|
stdout = json
|
||||||
|
}
|
||||||
|
fmt.Fprintf(stdout, "? \t%s\t[no test files]\n", a.Package.ImportPath)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
7
src/cmd/go/testdata/testcover/pkg1/a.go
vendored
7
src/cmd/go/testdata/testcover/pkg1/a.go
vendored
@ -1,7 +0,0 @@
|
|||||||
package pkg1
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func F() {
|
|
||||||
fmt.Println("pkg1")
|
|
||||||
}
|
|
7
src/cmd/go/testdata/testcover/pkg2/a.go
vendored
7
src/cmd/go/testdata/testcover/pkg2/a.go
vendored
@ -1,7 +0,0 @@
|
|||||||
package pkg2
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func F() {
|
|
||||||
fmt.Println("pkg2")
|
|
||||||
}
|
|
1
src/cmd/go/testdata/testcover/pkg2/a_test.go
vendored
1
src/cmd/go/testdata/testcover/pkg2/a_test.go
vendored
@ -1 +0,0 @@
|
|||||||
package pkg2
|
|
7
src/cmd/go/testdata/testcover/pkg3/a.go
vendored
7
src/cmd/go/testdata/testcover/pkg3/a.go
vendored
@ -1,7 +0,0 @@
|
|||||||
package pkg3
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func F() {
|
|
||||||
fmt.Println("pkg3")
|
|
||||||
}
|
|
7
src/cmd/go/testdata/testcover/pkg3/a_test.go
vendored
7
src/cmd/go/testdata/testcover/pkg3/a_test.go
vendored
@ -1,7 +0,0 @@
|
|||||||
package pkg3
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func TestF(t *testing.T) {
|
|
||||||
F()
|
|
||||||
}
|
|
@ -147,7 +147,7 @@ var (
|
|||||||
fourSpace = []byte(" ")
|
fourSpace = []byte(" ")
|
||||||
|
|
||||||
skipLinePrefix = []byte("? \t")
|
skipLinePrefix = []byte("? \t")
|
||||||
skipLineSuffix = []byte(" [no test files]\n")
|
skipLineSuffix = []byte("\t[no test files]\n")
|
||||||
)
|
)
|
||||||
|
|
||||||
// handleInputLine handles a single whole test output line.
|
// handleInputLine handles a single whole test output line.
|
||||||
@ -166,7 +166,7 @@ func (c *converter) handleInputLine(line []byte) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case for entirely skipped test binary: "? \tpkgname\t0.001s [no test files]\n" is only line.
|
// Special case for entirely skipped test binary: "? \tpkgname\t[no test files]\n" is only line.
|
||||||
// Report it as plain output but remember to say skip in the final summary.
|
// Report it as plain output but remember to say skip in the final summary.
|
||||||
if bytes.HasPrefix(line, skipLinePrefix) && bytes.HasSuffix(line, skipLineSuffix) && len(c.report) == 0 {
|
if bytes.HasPrefix(line, skipLinePrefix) && bytes.HasSuffix(line, skipLineSuffix) && len(c.report) == 0 {
|
||||||
c.result = "skip"
|
c.result = "skip"
|
||||||
|
Loading…
Reference in New Issue
Block a user