go: cmd/go: go test cannot find module path in module root directory

What version of Go are you using (go version)?

go version devel +ecec63c8a1 Tue Jul 31 16:34:38 2018 +0000 darwin/amd64

Does this issue reproduce with the latest release?

testing with tip (issue does not reproduce in go1.11beta2)

What operating system and processor architecture are you using (go env)?

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/suzmue/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/suzmue/go"
GOPROXY=""
GORACE=""
GOROOT="/Users/suzmue/tipgo/go"
GOTMPDIR=""
GOTOOLDIR="/Users/suzmue/tipgo/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/suzmue/myproject/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/c4/982kvfgd4jz6_6sdlzzk2nj400fkl_/T/go-build226914824=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Files in directory a: a/a.go: package a a/a_test.go: package a; import "testing"; func Test(t *testing.T){} a/go.mod: module github.com/user/a

$ cd a/
$ go test

What did you expect to see?

PASS
ok  	github.com/user/a	0.017s

What did you see instead?

build github.com/user/a (test): cannot find module for path github.com/user/a (test)

Additional notes

go test works as expected in any subdirectories of a.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 20 (15 by maintainers)

Most upvoted comments

Any idea when this will be pushed to vgo? I just stumbled across using these tools for golang versioning and am playing with vgo. This issue is still present there. However, it goes away when I manually copy the changed files from https://github.com/golang/go/commit/79faf9246e978628373999801279038a2ebc21ad into my local vgo sources.

Think I’ve found the problem. The ImportStack is not “a stack of import paths”, it is “a stack of import paths, sometimes with the suffix " (test)"”. We can’t resolve an import for a module path with a " (test)" suffix, because that’s not a valid import path.

http://thecodelesscode.com/case/84

Should be fixed at head. Please let me know if you’re still seeing these symptoms.

Yes that’s fixed it.