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: go test cannot find module path in module root directory #26722

Closed
suzmue opened this issue Jul 31, 2018 · 20 comments

Comments

Projects
None yet
9 participants
@suzmue
Copy link
Contributor

commented Jul 31, 2018

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.

@matloob

This comment has been minimized.

Copy link
Contributor

commented Aug 1, 2018

I can reproduce this on tip.

@suzmue

This comment has been minimized.

Copy link
Contributor Author

commented Aug 1, 2018

@matloob matloob added this to the Go1.11 milestone Aug 1, 2018

@bcmills

This comment has been minimized.

Copy link
Member

commented Aug 1, 2018

I suspect that this is the same underlying problem as #26602.

@mfridman

This comment has been minimized.

Copy link

commented Aug 1, 2018

@suzmue I can repro as well. I did notice ./... works, e.g.,

# go version devel +6b9c782f9f Wed Aug 1 00:57:00 2018 +0000 darwin/amd64

GO111MODULE=on go run main.go
build main: cannot find module for path main

GO111MODULE=on go run ./...
2018/08/01 11:14:49 failed decodeResp: Failed: Invalid Access Code / Password
exit status 1

Maybe the same is true for go test.

@rogpeppe

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2018

I bisected - it seems that https://go-review.googlesource.com/125836 (commit b294fe9) introduced this problem.

@bcmills

This comment has been minimized.

Copy link
Member

commented Aug 3, 2018

@rogpeppe, thanks for bisecting. In my experience debugging similar issues this week, these kinds of problems are very sensitive to the state of the module cache: did you clear the module and build caches at each commit?

(Just wondering how confident I should be in the bisection result.)

@rogpeppe

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2018

@bcmills I just tried again with clean module and build caches and I got the same results. I might be missing something though.

@bcmills

This comment has been minimized.

Copy link
Member

commented Aug 3, 2018

Nope, you've probably got it right. I suspect an off-by-one error (a trailing slash).

@rogpeppe

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2018

That is: 68170aa succeeds consistently;
b294fe9 fails.

FWIW I've been using gopkg.in/macaroon.v2 for testing.
Reproduce by:

 cd /tmp
 git clone git@github.com:go-macaroon/macaroon
 cd macaroon
 go test

After downloading the deps, I get:

build gopkg.in/macaroon.v2 (test): cannot find module for path gopkg.in/macaroon.v2 (test)
@bcmills

This comment has been minimized.

Copy link
Member

commented Aug 3, 2018

I added @suzmue's repro steps as a script test and it fails. (Thanks for the great minimal test case!)

I'll try macaroon too once it's fixed, just to be sure.

@bcmills

This comment has been minimized.

Copy link
Member

commented Aug 3, 2018

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

@gopherbot

This comment has been minimized.

Copy link

commented Aug 3, 2018

Change https://golang.org/cl/127795 mentions this issue: cmd/go/interna/load: trim the " (test)" suffix from ImportStack paths

@gopherbot gopherbot closed this in ac6d156 Aug 3, 2018

@bcmills

This comment has been minimized.

Copy link
Member

commented Aug 3, 2018

Hmm, macaroon still doesn't work.

$ git clone git@github.com:go-macaroon/macaroon
[…]
$ cd macaroon

macaroon$ go test
go: finding github.com/frankban/quicktest v1.0.0
go: finding github.com/google/go-cmp v0.2.0
go: finding golang.org/x/crypto v0.0.0-20180723164146-c126467f60eb
go: finding github.com/kr/pretty v0.1.0
go: finding github.com/kr/text v0.1.0
go: finding github.com/kr/pty v1.1.1
go: downloading golang.org/x/crypto v0.0.0-20180723164146-c126467f60eb
go: downloading github.com/frankban/quicktest v1.0.0
go: downloading github.com/google/go-cmp v0.2.0
go: downloading github.com/kr/pretty v0.1.0
go: downloading github.com/kr/text v0.1.0
build gopkg.in/macaroon.v2_test: cannot find module for path gopkg.in/macaroon.v2_test
@gopherbot

This comment has been minimized.

Copy link

commented Aug 3, 2018

Change https://golang.org/cl/127796 mentions this issue: cmd/go/internal/load: pass the importer's package path when checking visibility

@bcmills

This comment has been minimized.

Copy link
Member

commented Aug 3, 2018

Ok, think I've got it this time.

$ cd $(mktemp -d)
$ git clone git@github.com:go-macaroon/macaroon
$ cd macaroon/
macaroon$ go test
PASS
ok      gopkg.in/macaroon.v2    0.046s
@Gurpartap

This comment has been minimized.

Copy link

commented Aug 5, 2018

Adding my findings to this issue... here's an example project that uses replace to reproduce the build main: cannot find module for path main error upon running build or run on go1.11beta3. Not an issue with 1.11beta2.

example.zip

$ unzip example.zip
$ cd ~/example
$ tree .
.
├── cmd
│   └── example
│       ├── go.mod
│       └── main.go
├── go.mod
└── message.go

$ go1.11beta3 build cmd/example/main.go 
build main: cannot find module for path main
$ go1.11beta2 build cmd/example/main.go 
$ ./main
Hello
@anacrolix

This comment has been minimized.

Copy link
Contributor

commented Aug 6, 2018

I'm seeing this too, github.com/anacrolix/dht.

$ GO111MODULE=on go test .
build github.com/anacrolix/dht (test): cannot find module for path github.com/anacrolix/dht (test)

@bcmills

This comment has been minimized.

Copy link
Member

commented Aug 7, 2018

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

@anacrolix

This comment has been minimized.

Copy link
Contributor

commented Aug 8, 2018

Yes that's fixed it.

@sinyang

This comment has been minimized.

Copy link

commented Aug 19, 2018

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 79faf92 into my local vgo sources.

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