rules_go
rules_go copied to clipboard
MismatchedPkgName with external test package and GOPACKAGESDRIVER
What version of rules_go are you using?
v0.34.0
What version of gazelle are you using?
v0.26.0
What version of Bazel are you using?
5.2.0
Does this issue reproduce with the latest releases of all the above?
These are the latest.
What operating system and processor architecture are you using?
macOS 12.5 Arm M1 Pro
Any other potentially useful information about your toolchain?
n/a
What did you do?
I have a ready-to-run minimal reproduction at https://github.com/dt/externdemo, but essentially it is:
- a directory containing
foo.go
,foo_test.go
andfoo_test_external.go
, where the first two of those declarepackage foo
while the last haspackage foo_test
, - a gazelle-generated BUILD file for those files, which defines the expected
go_library
and ago_test
targets, forfoo.go
and the two_test.go
files, respectively, - a
bin/gopackagesdriver.sh
, script which is a thin launcher for@io_bazel_rules_go//go/tools/gopackagesdriver
, - a VSCode settings file pointing
GOPACKAGESDRIVER
at said launcher, - ... and of course a basic WORKSPACE file to set up latest rules_go and gazelle.
I then launched VSCode in this repo.
What did you expect to see?
bazel-powered gopls providing highlighting and analysis, including in foo_external_test.go.
What did you see instead?
package foo_test; expected foo (MismatchedPkgName)
on line 1 of foo_external_test.go
This looks very similar to the closed issue https://github.com/bazelbuild/rules_go/issues/3015, but that was marked as fixed by @illicitonion and @linzhp in https://github.com/bazelbuild/rules_go/pull/3116, which is in v0.34.0, which is what I am using in my reproduction repo above, so maybe this one is distinct?
This should be resolved in https://github.com/bazelbuild/rules_go/pull/3750 and https://github.com/bazelbuild/rules_go/pull/3777, however I would recommend even your external tests to still end in _test.go for this to work properly.
Yep, I can confirm that in the minimal reproduction repro I linked in the issue, if I bump rules_go to use git_repository and commit 37ba8d5b, the error no longer reproduces. Thanks so much for fixing this!