golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.84k stars 17.65k forks source link

cmd/go: fails to find `*_test` package when testing #26807

Closed hajimehoshi closed 6 years ago

hajimehoshi commented 6 years ago

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11beta3 darwin/amd64

Does this issue reproduce with the latest release?

Yes (Go 1.11 Beta 3)

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hajimehoshi/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hajimehoshi/go"
GOPROXY=""
GORACE=""
GOROOT="/Users/hajimehoshi/sdk/go1.11beta3"
GOTMPDIR=""
GOTOOLDIR="/Users/hajimehoshi/sdk/go1.11beta3/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/hajimehoshi/mygo/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/b7/w11sqqrx7kx6fqfbn24wdsmh0000gn/T/go-build531286046=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

mkdir mygo
cd mygo
go1.11beta3 mod init example.com/m
GO111MODULE=on go1.11beta3 test github.com/hajimehoshi/ebiten

Note that Ebiten package has two package names: ebiten and ebiten_test.

What did you expect to see?

Test succeeds.

What did you see instead?

Test fails with an error message:

build github.com/hajimehoshi/ebiten_test: cannot find module for path github.com/hajimehoshi/ebiten_test
hajimehoshi commented 6 years ago

Note that this is a regression: Go 1.11 beta 2 worked well with this case.

thepudds commented 6 years ago

@gopherbot, please add label modules

mpx commented 6 years ago

Here is a trivial example to reproduce:

go mod init foo
cat > a_test.go <<EOT
package foo_test
import "testing"
func TestA(t *testing.T) {}
EOT
mkdir a
cp a_test.go a

go1.11beta2 tests fine in both directories, but go1.11beta3 now fails in the module root with an external test package:

$ ~/go1.11beta2/bin/go test foo foo/a
ok      foo     0.001s
ok      foo/a   0.001s
$ ~/go1.11beta3/bin/go test foo
build foo_test: cannot find module for path foo_test
$ ~/go1.11beta3/bin/go test foo/a
ok      foo/a   0.001s
mpx commented 6 years ago

Bisect shows it breaks at b294fe9b0a9a0b9032cb2ecf9924e4c90f8de0ac which was submitted to fix #23970

@bcmills

mpx commented 6 years ago

Looks like this is the same bug as #26722

bcmills commented 6 years ago

Closing as duplicate.