英文:
List tests but don't run them
问题
你可以使用go list
命令来列出可用于go test
的测试,而不运行它们。以下是示例命令:
go list ./...
这将列出当前目录及其子目录中的所有测试。你可以根据需要调整路径参数来指定特定的包或目录。
希望这可以帮助到你!
英文:
How do I list the tests available to go test
without running them? I want to know what tests (including subtests) are present so I can manually pick a subset of them to run with a later command. I would expect something like go test -l
or go test -n
for something like this.
答案1
得分: 3
在go1.9中,go test
命令接受一个新的-list
标志,该标志以正则表达式作为参数,并将与之匹配的任何测试、基准测试或示例的名称打印到标准输出,而不运行它们。
test flags documentation 可以在 https://tip.golang.org 上找到,直到官方go1.9版本发布为止。
英文:
In go1.9 the go test
command accepts a new -list
flag, which takes a regular expression as an argument and prints to stdout the name of any tests, benchmarks, or examples that match it, without running them.
The test flags documentation can be found under https://tip.golang.org until the official go1.9 release.
答案2
得分: 1
没有go
子命令可以实现这个,但是你可以通过一点点的find
和grep
(GNU版本,用于-P
标志)魔法来实现:
find /path/to/your/project -not -path "./vendor" -type f -name "*_test.go" -exec cat {} \; | grep -oP '^func (\w+)\(\w \*testing\.T\) {$' | grep -oP ' \w+' | grep -oP '\w+';
英文:
There is no go
subcommand for that, but you can do it with a little bit of find
and grep
(GNU version, for the -P
flag) magic:
find /path/to/your/project -not -path "./vendor" -type f -name "*_test.go" -exec cat {} \; | grep -oP '^func (\w+)\(\w \*testing\.T\) {$' | grep -oP ' \w+' | grep -oP '\w+';
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论