Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: cmd/go: use anchored matching inside "go test -run" pattern #27382

Closed
rogpeppe opened this issue Aug 30, 2018 · 3 comments
Closed

proposal: cmd/go: use anchored matching inside "go test -run" pattern #27382

rogpeppe opened this issue Aug 30, 2018 · 3 comments

Comments

@rogpeppe
Copy link
Contributor

rogpeppe commented Aug 30, 2018

go version go1.11 linux/amd64

I just got bitten by this behaviour, which was unexpected to me.

 go test -run TestFoo/Bar

I expected it to run TestFoo/Bar, but not TestFooOther/Bar.
Instead it runs all tests any tests which start with TestFoo, regardless of subtest name.

In order to make it work as I expected, I need to do:

go test -run 'TestFoo$/Bar'

Given that this is a common thing to want to do, and the regexp $ looks very out of place in the middle of the string, I propose that all the parts of the pattern adjacent to / characters should be anchored, so to get the current behaviour, one would do:

go test -run 'TestFoo.*/Bar'

The sequence of regular expressions implied above would be:

(TestFoo.*)$
^(Bar)
@mvdan
Copy link
Member

mvdan commented Aug 30, 2018

I too get bitten by this a few times a week. Very rarely do I actually want to do -run 'TestFoo.*/Bar'.

@FiloSottile FiloSottile changed the title cmd/go: test: use anchored matching inside -run pattern proposal: cmd/go: use anchored matching inside "go test -run" pattern Aug 31, 2018
@gopherbot gopherbot added this to the Proposal milestone Aug 31, 2018
@rsc
Copy link
Contributor

rsc commented Sep 19, 2018

Sorry but I think it's too late to change this. This API is set. In general I treat cmd/go's command-line API the same way we treat package APIs - don't redefine existing behaviors (don't make breaking changes).

I use the substring all the time, as in -run=Foo/Bar.

@rsc rsc closed this as completed Sep 19, 2018
@mvdan
Copy link
Member

mvdan commented Sep 19, 2018

I'm not sure I understand your point about substrings. What Roger is proposing is that your -run=Foo/Bar would become the old -run=Foo$/^Bar, which would still match our example above.

It's still reasonable if this is rejected as a breaking change, though.

@golang golang locked and limited conversation to collaborators Sep 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants