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
Closed

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

suzmue opened this issue Jul 31, 2018 · 20 comments
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@suzmue
Copy link
Contributor

suzmue 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
Copy link
Contributor

matloob commented Aug 1, 2018

I can reproduce this on tip.

@suzmue
Copy link
Contributor Author

suzmue commented Aug 1, 2018

cc @bcmills

@matloob matloob added this to the Go1.11 milestone Aug 1, 2018
@bcmills
Copy link
Contributor

bcmills commented Aug 1, 2018

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

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. modules labels Aug 1, 2018
@mfridman
Copy link

mfridman 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
Copy link
Contributor

rogpeppe commented Aug 3, 2018

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

@bcmills
Copy link
Contributor

bcmills 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
Copy link
Contributor

rogpeppe 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
Copy link
Contributor

bcmills commented Aug 3, 2018

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

@rogpeppe
Copy link
Contributor

rogpeppe 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 [email protected]: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
Copy link
Contributor

bcmills 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
Copy link
Contributor

bcmills 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
Copy link
Contributor

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

@bcmills
Copy link
Contributor

bcmills commented Aug 3, 2018

Hmm, macaroon still doesn't work.

$ git clone [email protected]: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
Copy link
Contributor

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

@bcmills
Copy link
Contributor

bcmills commented Aug 3, 2018

Ok, think I've got it this time.

$ cd $(mktemp -d)
$ git clone [email protected]:go-macaroon/macaroon
$ cd macaroon/
macaroon$ go test
PASS
ok      gopkg.in/macaroon.v2    0.046s

@Gurpartap
Copy link

Gurpartap 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
Copy link
Contributor

anacrolix 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
Copy link
Contributor

bcmills commented Aug 7, 2018

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

@anacrolix
Copy link
Contributor

Yes that's fixed it.

@sinyang
Copy link

sinyang 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.

@golang golang locked and limited conversation to collaborators Aug 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

9 participants