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: testmain program doesn't use vendored stdlib packages #15219

Closed
cespare opened this issue Apr 10, 2016 · 1 comment
Closed

cmd/go: testmain program doesn't use vendored stdlib packages #15219

cespare opened this issue Apr 10, 2016 · 1 comment

Comments

@cespare
Copy link
Contributor

cespare commented Apr 10, 2016

go 1.6 linux/amd64

It is possible (and I believe intended as a valid practice) to vendor a stdlib package and have it "shadow" the package in $GOROOT.

However, the testmain program constructed by go test doesn't use such vendored stdlib packages. In particular, this prevents vendoring package "testing"; the testmain program refers to the GOROOT testing package, where as the package under test uses the vendored testing package. Thus the testmain program does not compile and so go test cannot work.

Demo:

$ export GOPATH=/tmp/gopath
$ mkdir -p $GOPATH/src/x
$ cd $GOPATH/src/x
$ cat > x_test.go
package x

import "testing"

func TestX(t *testing.T) {}
$ go test
PASS
ok      x       0.009s
$ mkdir -p $GOPATH/src/vendor
$ cp -r ~/apps/go/src/testing $GOPATH/src/vendor/ # vendor testing from your usual GOROOT
$ go test
# testmain
/var/folders/7r/pz2frytd23gb3pt4bwwshp1c0000gn/T/go-build151556267/x/_test/_testmain.go:22: cannot use x.TestX (type func(*"vendor/testing".T)) as type func(*"testing".T) in field value
FAIL    x [build failed]
@bradfitz bradfitz added this to the Unplanned milestone Apr 10, 2016
@cespare
Copy link
Contributor Author

cespare commented Aug 16, 2016

I no longer care about this since the sub-test changes I was trying to vendor are now released in Go 1.7.

I'm going to close this. If someone else cares, we can reopen.

@cespare cespare closed this as completed Aug 16, 2016
@golang golang locked and limited conversation to collaborators Aug 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants