Skip to content

Editor support broken for gazelle generated go_test for packages containing both internal and external tests #3015

@rohitagarwal003

Description

@rohitagarwal003

What version of rules_go are you using?

v0.29.0

What version of gazelle are you using?

v0.24.0

What version of Bazel are you using?

4.2.1

Does this issue reproduce with the latest releases of all the above?

I am using the latest versions already.

What operating system and processor architecture are you using?

Intel Mac

Any other potentially useful information about your toolchain?

I have created the initial setup here: https://gist.github.com/rohitagarwal003/d9087ca9f87271b1b4f1d392a9dea593.

If you download all those files in a directory named mypkg and run bazel run //:gazelle from there, the updated BUILD.bazel will not work correctly with VSCode.

BUILD.bazel file generated by gazelle that doesn't work with VSCode

load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@bazel_gazelle//:def.bzl", "gazelle")

# gazelle:prefix example.com/mypkg
gazelle(name = "gazelle")

go_library(
    name = "mypkg",
    srcs = ["mypkg.go"],
    importpath = "example.com/mypkg",
    visibility = ["//visibility:public"],
)

go_test(
    name = "mypkg_test",
    srcs = [
        "mypkg_external_test.go",
        "mypkg_internal_test.go",
    ],
    embed = [":mypkg"],
)

error-with-gazelle-generated-rules

Error: package mypkg_test; expected mypkg compiler(MismatchedPkgName)

BUILD.bazel file that does work

load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
    name = "mypkg",
    srcs = ["mypkg.go"],
    importpath = "example.com/mypkg",
    visibility = ["//visibility:public"],
)

go_test(
    name = "mypkg_external_test",
    srcs = ["mypkg_external_test.go"],
    deps = [":mypkg"],
)

go_test(
    name = "mypkg_internal_test",
    srcs = ["mypkg_internal_test.go"],
    embed = [":mypkg"],
)

no-error-with-manual-rules


cc @steeve @linzhp

Metadata

Metadata

Assignees

No one assigned

    Labels

    IDEGo package driver and IDE support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions