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

Comments

Projects
None yet
4 participants
@rogpeppe
Copy link
Contributor

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)

@rogpeppe rogpeppe added the Proposal label Aug 30, 2018

@mvdan

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Contributor

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 Sep 19, 2018

@mvdan

This comment has been minimized.

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.