英文:
How to tell gazelle that a go file is meant for go_default_test and not go_default_library?
问题
我有一个名为embed_testdata.go
的文件,用于测试,但它本身没有测试(所以我不想在文件名后面加上_test.go
)。我该如何告诉gazelle
这是测试源码而不是生产源码呢?
顺便说一下,只是将它添加到go_default_test
并从go_default_library
中移除并不起作用,因为gazelle
会撤销手动编辑的更改。
英文:
I have a file, embed_testdata.go
, meant to be used in tests but does not itself have tests (so I don't want to suffix it with _test.go
). How do I tell gazelle
that it's really test source and not prod source?
FYI, simply adding it to go_default_test
and removing it from go_default_library
doesn't work since gazelle
undoes that manual edit.
答案1
得分: 0
https://github.com/bazelbuild/bazel-gazelle#directives 是所有有效的gazelle
指令。
没有特定的指令告诉它将非_test.go
文件视为测试文件,但有两个指令可以用于实现这个效果,即exclude
和keep
:
# gazelle:exclude embed_testdata.go
…
go_test(
name = "go_default_test",
srcs = [
"embed_testdata.go", # keep
…
在嵌入文件系统时,还需要类似以下的内容:
go_test(
name = "go_default_test",
…
embedsrcs = glob(["testdata/**"]), # keep
…
英文:
https://github.com/bazelbuild/bazel-gazelle#directives are all the valid gazelle
directives.
There's no specific directive that tells it to treat a non-_test.go
file as a test but there are two that can be used to that effect, exclude
and keep
:
# gazelle:exclude embed_testdata.go
…
go_test(
name = "go_default_test",
srcs = [
"embed_testdata.go", # keep
…
When embedding a file system, something like the following is also needed:
go_test(
name = "go_default_test",
…
embedsrcs = glob(["testdata/**"]), # keep
…
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论