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

x/tools/gopls: Cannot refer to a file with a prefix from a file without a test prefix #57297

Closed
komem3 opened this issue Dec 14, 2022 · 3 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@komem3
Copy link

komem3 commented Dec 14, 2022

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

$ go version
go version go1.19.4 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mikuni-k/.cache/go-build"
GOENV="/home/mikuni-k/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/mikuni-k/go/pkg/mod"
GOOS="linux"
GOPATH="/home/mikuni-k/go"
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3315974857=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I created two files that a file with _test prefix in the package name without _test prefix in the extension and a file with _test prefix in the package name with _test prefix in the extension.

  • sample_test.go
// sample_test.go
package sample_test

import "testing"

const data = "hello world"

func TestSample(t *testing.T) {
	t.Log(helloWorld())
}
  • sample.go
// sample.go
package sample_test

const d = data // gopls reports error

func helloWorld() string {
	return d
}

What did you expect to see?

Build and test succeed, but gopls reports an error referencing a test file from a test package with no test prefix in the file extension.

What did you see instead?

The test file can be referenced from the test package even if it does not have the test prefix in the extension.

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Dec 14, 2022
@gopherbot gopherbot added this to the Unreleased milestone Dec 14, 2022
@findleyr
Copy link
Contributor

Hi, thank you for the issue. I'm not sure what you mean by "Build and test succeed", because they don't succeed for me. I may be missing something.

> go build .
# issue.mod
./sample.go:3:11: undefined: data
> ls
go.mod  sample.go  sample_test.go
> cat sample.go
package sample_test

const d = data // gopls reports error

func helloWorld() string {
        return d
}
> cat sample_test.go
package sample_test

import "testing"

const data = "hello world"

func TestSample(t *testing.T) {
        t.Log(helloWorld())
}

How exactly are you running build and test?

@findleyr findleyr added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 14, 2022
@komem3
Copy link
Author

komem3 commented Dec 14, 2022

@findleyr
Sorry. I didn't import this package in my environment, I was using it only for testing, so I didn't do any build.
When I tried, the build failed, but the test was successful.

should not I create test package without _test in the extension?

@findleyr
Copy link
Contributor

@komem3 yes, all test files should go a file ending in _test.go.

Closing as this is working as intended.

@findleyr findleyr closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2022
@golang golang locked and limited conversation to collaborators Dec 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants