如何在测试标识符中指定包名?

huangapple go评论82阅读模式
英文:

go test -run: how to specify the package in the test identifier

问题

假设我有两个包foo/bar和foo/baz。foo/bar和foo/baz都有一个TestFoo,但我只想运行foo/bar的TestFoo。此外,foo/baz还有一个TestBaz,我想要运行。

有没有可能指定一个go test命令,只运行foo/bar的TestFoo和foo/baz的TestBaz?

我尝试使用go test -run来实现,但看起来运行的正则表达式只是按名称过滤,而不是按包标识符过滤:

go test -run "TestFoo|TestBaz" foo/bar foo/baz

理想情况下,我想要做的是:

go test -run "foo/bar/TestFoo|foo/baz/TestBaz" foo/bar foo/baz

英文:

Let's say I have two packages foo/bar and foo/baz. Both foo/bar and foo/baz have a TestFoo, but I only want to run foo/bar's TestFoo. Additionally, foo/baz has a TestBaz that I want to run.

Is it possible to specify a go test command that will run just foo/bar::TestFoo and foo/baz::TestBaz?

I've tried using go test -run for this, but it looks like the run regex just filters by name, not by the package identifier:

go test -run "TestFoo|TestBaz" foo/bar foo/baz

Ideally, I'd want to do something like:

go test -run "foo/bar/TestFoo|foo/baz/TestBaz" foo/bar foo/baz.

答案1

得分: 0

可以指定一个go test命令来只运行foo/bar::TestFoofoo/baz::TestBaz吗?

不,这是不可能的。

(通常情况下,包应该是自包含的,只测试其中一个选定的测试并不是常见的用例。通过go test ./...可以很好地测试多个或所有的包。)

英文:

> Is it possible to specify a go test command that will run just foo/bar::TestFoo and foo/baz::TestBaz?

No, this is not possible.

(Packages normally should be self contained and testing one selected test out of several simply isn't a common use case. Testing several or all packages works good enough via go test ./...)

huangapple
  • 本文由 发表于 2023年6月22日 18:23:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76530921.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定