英文:
Why does `go test -run NotExist` pass?
问题
如果我运行以下命令:
go test -run NotExist
响应是 PASS。鉴于我的测试文件中没有包含名为 TestNotExist
的测试,我期望上述命令返回 FAIL。
英文:
If I run the following
go test -run NotExist
The response is PASS. Seeing as my test file does not contain a test called TestNotExist
I would expect the command above to return FAIL
答案1
得分: 1
没有-run
选项时,go test
会运行所有的测试。你可以使用-run
选项来不运行所有的测试,来过滤掉、排除测试(你可以通过要求非可排除测试的名称与正则表达式模式匹配来实现这一点,但这与讨论的重点无关):
默认情况下,go test不需要参数。它会编译和测试当前目录中包含测试的源代码,并运行这些测试。
-run regexp
只运行与正则表达式匹配的测试和示例。
过滤掉所有测试,使得剩下的测试集合中没有测试需要执行,这是完全“正常”的结果。
当没有测试失败时,被认为测试运行通过。如果没有测试匹配,将不会运行任何测试,也不会有测试失败,因此测试运行将通过。
英文:
Without the -run
option go test
runs all tests. You use the -run
option to not run all tests; to filter out, to exclude tests (and you do this in the form of requiring names of non-excludable tests to match a regexp pattern - but this is irrelevant form the point of discussion):
> By default, go test needs no arguments. It compiles and tests the package with source in the current directory, including tests, and runs the tests.
> -run regexp
> Run only those tests and examples matching the regular expression.
It is a perfectly "normal" outcome that a filtering filters out all tests, that no tests remains in the set of tests that still need to be executed.
When no tests FAIL, it is considered as the test run PASSes. If no tests match, no tests will run and no tests will FAIL, and thus the test run will PASS.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论