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: a module directly inside a testdata directory is broken #28481

Open
mvdan opened this Issue Oct 30, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@mvdan
Member

mvdan commented Oct 30, 2018

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

go version devel +2e9f0817f0 Tue Oct 30 04:39:53 2018 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mvdan/go/cache"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mvdan/go/land:/home/mvdan/go"
GOPROXY=""
GORACE=""
GOROOT="/home/mvdan/tip"
GOTMPDIR=""
GOTOOLDIR="/home/mvdan/tip/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build160474966=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Try to use a testdata Go module. This is useful so that one can have Go packages that can import each other, to be used as input for a tool's tests. Below is a simple reproduction script.

rm -rf testdata
mkdir testdata
cd testdata
go mod init testdata.tld/foo

cat >main.go <<EOF
package foo

import _ "golang.org/x/tools/go/packages"
EOF

echo ====
cat go.mod
echo ====

go build

echo ====
cat go.mod
echo ====

go mod tidy

echo ====
cat go.mod
echo ====

What did you expect to see?

The go mod tidy at the end being a no-op.

What did you see instead?

The go mod tidy removing the dependency that go build added.

$ bash repro.sh
go: creating new go.mod: module testdata.tld/foo
====
module testdata.tld/foo
====
go: finding golang.org/x/tools/go/packages latest
go: finding golang.org/x/tools/go latest
go: finding golang.org/x/tools latest
====
module testdata.tld/foo

require golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b
====
====
module testdata.tld/foo
====

Thanks to @myitcv for helping debug what was going on.

@bcmills bcmills added this to the Go1.12 milestone Nov 6, 2018

@bcmills

This comment has been minimized.

Member

bcmills commented Nov 6, 2018

Contrast #27852. (I don't think the two actually conflict, but the interaction between testdata and modules threads a fine line.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment