Skip to content

testing: change -run regexp to make / have usual precedence #39904

@dnephin

Description

@dnephin

The go test -run flag can be used to select multiple root test cases. This example will run the 3 tests which match the regex exactly:

go test -run '^(TestOne|TestTwo|TestThree)$'

As far as I can tell, the logic for handling subtests makes it impossible to do the same with subtest cases. It seems to be possible to run multiple root test cases, with a single subtest case:

go test -run '^TestOne$|^TestTwo$|^TestThree$/^SubTestA$'

But adding anything after the / is assumed to be a sub-sub test, and does not match the same way.

Some other things that I tried, which do not work:

Matches any SubTestA, not just the one from TestThree

^(TestOne|TestTwo|TestThree)$/^SubTestA$

Does not match any subtests

Because of how parenthesis are handled in splitRegex

(^TestOne$|^TestTwo$|^TestThree$/^SubTestA$)

Would it be reasonable to support this with the -run flag? Looking over the matching logic in src/testing it seems like this may not be a small change.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions