Skip to content

Match anonymous tests when all of the match expressions are negative #1502

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

Merged
merged 1 commit into from
Sep 5, 2017

Conversation

rhendric
Copy link
Contributor

@rhendric rhendric commented Sep 1, 2017

(Matching on '*', for example, still excludes tests with no titles, as it did prior to this commit.)

The motivation here is if I have a test suite with some anonymous tests and some titled tests, and some of the titled tests are tagged with something like [long-running], and I want to run ava -m '!*[long-running]*', I don't want to exclude the anonymous tests. But with current Ava they are excluded.

For what it's worth, anyone who misses the old behavior could get it back with -m '*' -m <negative match expression(s)>.

Edit: Changed so that -m '*' matches all tests, including anonymous. For purposes of matching, anonymous tests have empty string titles.

Copy link
Member

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks for the PR! I don't think matchTitleless is necessary, see the inline comment.

lib/runner.js Outdated
@@ -112,7 +113,7 @@ class Runner extends EventEmitter {
}

if (metadata.type === 'test' && this.match.length > 0) {
metadata.exclusive = title !== null && matcher([title], this.match).length === 1;
metadata.exclusive = title === null ? this.matchTitleless : matcher([title], this.match).length === 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be sufficient to remove the title !== null check. matcher([null],["!*oo"]) gives [null] which passes the length === 1 check. Perhaps use matcher([title || ''], this.match), since the matcher expects strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with that simplification, but you should know that it does change behavior—that would essentially treat a titleless test the same as a test with an empty string title, so -m '*' would truly include all tests, even the titleless ones, and there would no longer be an escape hatch to go back to the old behavior. I was trying to lean towards making this PR as conservative as possible, but I can't think of a real reason to want to distinguish between anonymous tests and empty title tests, so if you're fine with that then I'll make the change.

@novemberborn
Copy link
Member

I can't think of a real reason to want to distinguish between anonymous tests and empty title tests, so if you're fine with that then I'll make the change.

Yea me neither. I've scanned the discussion in #476 and I don't think we ever considered this. Generally we'd recommend against using anonymous tests, so if you do use them and need to somehow exclude them I guess you might just have to name them 😉

@rhendric rhendric force-pushed the fix/neg-match-anonymous branch from 4a722e8 to feffe0d Compare September 2, 2017 17:03
@rhendric
Copy link
Contributor Author

rhendric commented Sep 2, 2017

So shall it be!

@ORESoftware
Copy link

why not default to the file path for the name of the test if no test title is given

@novemberborn
Copy link
Member

@ORESoftware we already display the title as "anonymous". This PR postulates that !*foo should match anonymous tests, since, by virtue of having no title, their title does not end in foo.

@rhendric
Copy link
Contributor Author

rhendric commented Sep 5, 2017

@novemberborn, ready to merge?

Copy link
Member

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @rhendric!

@novemberborn novemberborn merged commit 1df502d into avajs:master Sep 5, 2017
mliou8 pushed a commit to mliou8/ava that referenced this pull request Sep 11, 2017
@rhendric rhendric deleted the fix/neg-match-anonymous branch March 23, 2018 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants