英文:
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::TestFoo
和foo/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 ./...)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论