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

x/tools/cmd/godoc: TestCLI test failing #20122

Closed
bradfitz opened this issue Apr 25, 2017 · 9 comments

Comments

Projects
None yet
3 participants
@bradfitz
Copy link
Member

commented Apr 25, 2017

https://build.golang.org/log/3975858bb0ebc4ded5cb6a1ca614b361c8e97803

Broken by https://go-review.googlesource.com/37768

Broken for Go 1.7 and Go 1.6 (but not tip) with.

--- FAIL: TestCLI (14.77s)
	godoc_test.go:113: godoc nonexistingpkg =
		2017/04/25 10:32:28 open /var/folders/dx/k53rs1s93538b4x20g46cj_w0000gn/T/workdir/go/src/nonexistingpkg: no such file or directory
		
		wanted /cannot find package/
2017/04/25 10:32:48 updateMetadata: open /var/folders/dx/k53rs1s93538b4x20g46cj_w0000gn/T/godoc-analysis093454778/goroot/doc: no such file or directory
2017/04/25 10:32:48 updateMetadata: open /var/folders/dx/k53rs1s93538b4x20g46cj_w0000gn/T/godoc-analysis093454778/goroot/doc: no such file or directory
2017/04/25 10:32:48 GOROOT=/var/folders/dx/k53rs1s93538b4x20g46cj_w0000gn/T/godoc-analysis093454778/goroot/src/: [lib]
2017/04/25 10:32:48 GOPATH[0]=/var/folders/dx/k53rs1s93538b4x20g46cj_w0000gn/T/godoc-analysis093454778/gopath/src/: [app]
2017/04/25 10:32:48 Loading and type-checking packages...
2017/04/25 10:32:48 Loaded 2 packages.
2017/04/25 10:32:48 Constructing SSA form...
2017/04/25 10:32:48 SSA construction complete
2017/04/25 10:32:48 Computing implements relation...
2017/04/25 10:32:48 Extracting type info...
2017/04/25 10:32:48 Visit instructions...
2017/04/25 10:32:48 Visit instructions complete
2017/04/25 10:32:48 Type analysis complete.
FAIL

@bradfitz bradfitz added the NeedsFix label Apr 25, 2017

@bradfitz bradfitz added this to the Go1.9 milestone Apr 25, 2017

@dmitshur

This comment has been minimized.

Copy link
Member

commented Apr 25, 2017

Thanks for reporting, I'll work on fixing this.

I only tested using latest Go version when I sent that CL. It looks like (still need to confirm confirmed, see below for details) the test failure is simply because I was fairly aggressive about removing unneeded accepted error message strings.

I can bring back the accepted error strings that were there before, but while doing that, I'll think if there's a better way to fix this.

@dmitshur

This comment has been minimized.

Copy link
Member

commented Apr 25, 2017

Broken for Go 1.7 and Go 1.6 (but not tip)

@bradfitz, did you mean it's broken for Go 1.8 and Go 1.7 (but not tip)? That would make more sense, given what I'm seeing (I expect it to fail for Go 1.8 too).

I see only Go 1.8 and 1.7 mentioned at https://build.golang.org/.

@dmitshur

This comment has been minimized.

Copy link
Member

commented Apr 25, 2017

I have a better understanding (it's more subtle than what I wrote above).

CL 33158 changed behavior of go/build (fixing a bug, making the behavior more consistent). This fix only went into Go 1.9 and newer, so Go 1.6, 1.7, 1.8 still have old go/build behavior.

The go/build change allowed for a better expected error message, which CL 37768 updated for. However, that better error message doesn't apply for Go 1.6, 1.7, 1.8 because they don't have the original go/build fix.

Fix

I see two possible fixes. Either make the test more lax and accept both new and old error messages:

args: []string{"nonexistingpkg"},
matches: []string{
	// For Go 1.9 and newer.
	"cannot find package" +

		// For Go 1.8 and older, because it doesn't have CL 33158 change to go/build.
		// The last pattern (does not e) is for plan9:
		// http://build.golang.org/log/2d8e5e14ed365bfa434b37ec0338cd9e6f8dd9bf
		`|no such file or directory|does not exist|cannot find the file|(?:' does not e)`,
},

Or if we want to be really precise about expected error messages, we'd need to use _test.go files build tags for this:

args:    []string{"nonexistingpkg"},
matches: nonexistingpkgMatches,
// +build go1.9

package main_test

var nonexistingpkgMatches = []string{"cannot find package"}
// +build !go1.9

package main_test

// For Go 1.8 and older, because it doesn't have CL 33158 change to go/build.
var nonexistingpkgMatches = []string{
	// The last pattern (does not e) is for plan9:
	// http://build.golang.org/log/2d8e5e14ed365bfa434b37ec0338cd9e6f8dd9bf
	`no such file or directory|does not exist|cannot find the file|(?:' does not e)`,
}

Are there preferences as to which solution to use for this?

Second one is more precise, but also more verbose (and less readable, probably).

@bradfitz

This comment has been minimized.

Copy link
Member Author

commented Apr 25, 2017

Let's do something in-between those two extremes.

I'd make a new file with just:

// +build go1.9
package main_test
func init() { isGo19 = true }

And then in the main test, have:

var isGo19 bool
....
args: []string{"nonexistingpkg"},
matches: []string{
		"cannot find package" +
                  condStr(!isGo19, 
    		         // For Go 1.8 and older, because it doesn't have CL 33158 change to go/build.
		         // The last pattern (does not e) is for plan9:
		         // http://build.golang.org/log/2d8e5e14ed365bfa434b37ec0338cd9e6f8dd9bf
		        `|no such file or directory|does not exist|cannot find the file|(?:' does not e)`)
},

func condStr(bool, string) string { .... }
@dmitshur

This comment has been minimized.

Copy link
Member

commented Apr 26, 2017

What you suggested exactly doesn't work, because package-level variables are initialized before init gets a chance to run (https://golang.org/ref/spec#Package_initialization). So when condStr(!isGo19, ...) gets executed, isGo19 will always be false.

I can fix that by creating two files instead of one:

// +build go1.9
package main_test
const isGo19 = true
// +build !go1.9
package main_test
const isGo19 = false
@bradfitz

This comment has been minimized.

Copy link
Member Author

commented Apr 26, 2017

I assumed the condStr() expression was inside of a test. I didn't go read the code.

I'd prefer the list of test cases to be a func variable instead of a package global anyway.

@bradfitz

This comment has been minimized.

Copy link
Member Author

commented Apr 26, 2017

Looked at the code now. Yes, just move that var godocTests into the test. It's only used those two places:

godoc_test.go:25:var godocTests = []struct {
godoc_test.go:102:      for _, test := range godocTests {
@dmitshur

This comment has been minimized.

Copy link
Member

commented Apr 26, 2017

Ok, that'll work.

Will send a CL soon, right after dinner.

@gopherbot

This comment has been minimized.

Copy link

commented Apr 26, 2017

CL https://golang.org/cl/41810 mentions this issue.

@golang golang locked and limited conversation to collaborators Apr 26, 2018

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