Skip to content

cmd/go: document that vendor directories are ignored for packages without import paths #18007

Closed as not planned
@cespare

Description

@cespare

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsFixThe path to resolution is known, but the work has not been done.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions