Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
Go 1.7.3 and tip
What operating system and processor architecture are you using (go env
)?
linux/amd64
What did you do?
A package inside a directory named testdata
cannot use vendored packages from above the testdata directory. Here's a demo:
$ export GOPATH=/tmp/gopath
$ mkdir -p $GOPATH/src/vendor/v
$ mkdir -p $GOPATH/src/a
$ cat > $GOPATH/src/vendor/v/v.go
package v
const V = "vendored"
$ cat > $GOPATH/src/a/a.go
package main
import "fmt"
import "v"
func main() { fmt.Println(v.V) }
$ cd $GOPATH/src/a
$ go build && ./a
vendored
$ mkdir -p $GOPATH/src/testdata
$ cp -r $GOPATH/src/a $GOPATH/src/testdata/
$ cd $GOPATH/src/testdata/a
$ go build
a.go:4:8: cannot find package "v" in any of:
/Users/caleb/apps/go/src/v (from $GOROOT)
/tmp/gopath/src/v (from $GOPATH)
This came up while writing tests for a program that itself invokes go build
to build and run a temp binary.
I'm aware that testdata is special. It's documented in go help test
:
The go tool will ignore a directory named "testdata", making it available to hold ancillary data needed by the tests.
and go help packages
:
Directory and file names that begin with "." or "_" are ignored by the go tool, as are directories named "testdata".
but it wasn't obvious to me that not being able to use vendored packages is a consequence of this. Should it have been? Is this intended?