Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go test builtin fails #26008

Closed
dvyukov opened this issue Jun 22, 2018 · 4 comments

Comments

Projects
None yet
6 participants
@dvyukov
Copy link
Member

commented Jun 22, 2018

on bedfa4e

$ go test ./...
# builtin.test
../../../tmp/go-build/go-build854466004/b073_testmain.go:12:2: can't find import: "builtin"

Does it have some special handling? Should we skip its testing?

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2018

There are no tests of that package. It's not a real package, just documentation. What's broken here is that go test builtin tries to build a test binary, although there are no tests. This was almost certainly broken by https://golang.org/cl/115095, for #24570.

CC @kyroy

@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Jun 22, 2018

@ianlancetaylor ianlancetaylor changed the title builtin: test broken cmd/go: go test builtin fails Jun 22, 2018

@wingyplus

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2018

I found that it back to normal when revert come changes from ebb8a1f.

diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go
index aff5ff2c9d..744a1fa983 100644
--- a/src/cmd/go/internal/test/test.go
+++ b/src/cmd/go/internal/test/test.go
@@ -781,6 +781,13 @@ var windowsBadWords = []string{
 }
 
 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:
 	//	pmain - pkg.test binary
 	//	ptest - package + test files
@@ -1592,3 +1599,15 @@ func builderPrintTest(b *work.Builder, a *work.Action) error {
 	}
 	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
+}
@ysmolsky

This comment has been minimized.

Copy link
Member

commented Jul 15, 2018

That revert has reached the tip. This cannot be reproduced on Darwin (el capitan).

@bcmills

This comment has been minimized.

Copy link
Member

commented Jul 16, 2018

Agreed; seems to be fixed.

~/go/src$ go version
go version devel +3fcfb1f573 Mon Jul 16 15:32:40 2018 +0000 linux/amd64

~/go/src$ go test builtin
?       builtin [no test files]

@bcmills bcmills closed this Jul 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.