Why does `go test -run NotExist` pass?

前端 未结 1 1478
礼貌的吻别
礼貌的吻别 2021-01-26 23:47

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

相关标签:
1条回答
  • 2021-01-26 23:56

    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):

    Command go, Test packages:

    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.

    Description of testing flags:

    -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.

    0 讨论(0)
提交回复
热议问题