rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

MismatchedPkgName with external test package and GOPACKAGESDRIVER

Open dt opened this issue 2 years ago • 1 comments

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 and foo_test_external.go, where the first two of those declare package foo while the last has package foo_test,
  • a gazelle-generated BUILD file for those files, which defines the expected go_library and a go_test targets, for foo.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

dt avatar Aug 18 '22 18:08 dt

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?

dt avatar Sep 07 '22 00:09 dt

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.

JamyDev avatar Dec 07 '23 21:12 JamyDev

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!

dt avatar Dec 08 '23 02:12 dt