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

Filter examples based on TestSelector #1216

Merged
merged 1 commit into from
Jan 22, 2024

Conversation

Duhemm
Copy link
Contributor

@Duhemm Duhemm commented Jan 19, 2024

Previously, the Specs2 runner would ignore the selectors that are passed via a TaskDef.

With this patch, when a TaskDef's selectors contains only TestSelectors, then only the examples whose name match the input selectors will be executed.

Previously, the Specs2 runner would ignore the selectors that are passed
via a `TaskDef`.

With this patch, when a `TaskDef`'s selectors contains only
`TestSelector`s, then only the examples whose name match the input
selectors will be executed.
@Duhemm
Copy link
Contributor Author

Duhemm commented Jan 19, 2024

In case this ends up being accepted, I've already backported this to 4.x: backport-test-selector

@etorreborre
Copy link
Owner

Hi Martin. First of all, thanks for this PR, it looks great with all the tests! However I don't get what is the use for a TestSelector with sbt on the command line. I have always selected classes with a wildcard like testOnly *MySpec* and then individual tests (or examples in BDD terms) with testOnly *MySpec* -- ex "first example". How can I create a TestSelector from sbt's command line?

@etorreborre
Copy link
Owner

Confession: I just discovered that sbt was proposing to complete the spec names for the testOnly command when pressing TAB. Better late than never :-).

@Duhemm
Copy link
Contributor Author

Duhemm commented Jan 21, 2024

Hi Eric, thanks for taking a look.

On the command line, I don't know of a way to use the selectors. The selectors are intended to be used programmatically, for instance by an IDE that would trigger the execution of a single test, or an sbt plugin that would retry failed tests.

In the examples that you showed, the syntax to execute only a single test case works only for Specs2, whereas the solution based on test selectors is framework-agnostic.

My understanding is that this is the reason why, in sbt's test API, TaskDef has a list of selectors: so that it can be used to specify which test cases to execute within a test suite. I've noticed that ScalaTest, JUnit and MUnit already support filtering test cases based on selectors (I have pull requests open for the other major test frameworks).

Please let me know if this makes the intent behind this pull request clearer.

@etorreborre
Copy link
Owner

Thanks for your explanation @Duhemm. I left another question about the code because I'm not sure about one condition.

@etorreborre etorreborre merged commit d0f255d into etorreborre:main Jan 22, 2024
3 checks passed
@Duhemm Duhemm deleted the test-selector branch January 22, 2024 10:44
@etorreborre
Copy link
Owner

Excellent, thanks @Duhemm. Can you please open a PR for the backport as well?
Also, how fast do you need a release for this?

@Duhemm
Copy link
Contributor Author

Duhemm commented Jan 22, 2024

Thanks, I just opened #1217.

There's no rush in releasing! Sometime before March would be great though 😄

@etorreborre
Copy link
Owner

Perfect, that will definitely be done by then :-)

@etorreborre
Copy link
Owner

This is published now as 4.20.5 for the maintenance branch and 5.5.1 for the main branch.

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.

2 participants