Skip to content

Conversation

Duhemm
Copy link
Contributor

@Duhemm Duhemm commented Jan 17, 2024

Previously, ScalaCheck ignored the selectors that it receives as input in the "root task". This prevented users from running only a subset of properties in a specification by passing their TestSelector to ScalaCheck in a TaskDef.

This patch fixes this by having the root task program the execution of only the requested properties if the TaskDef contains only TestSelectors. ScalaCheck's behavior remains unchanged if the TaskDef contains any other kind of Selector.

@Duhemm Duhemm force-pushed the test-selector branch 2 times, most recently from 46dbc34 to 7d9e2a9 Compare January 17, 2024 14:40
Previously, ScalaCheck ignored the selectors that it receives as input
in the "root task". This prevented users from running only a subset of
properties in a specification by passing their `TestSelector` to
ScalaCheck in a `TaskDef`.

This patch fixes this by having the root task program the execution of
only the requested properties if the `TaskDef` contains only
`TestSelector`s. ScalaCheck's behavior remains unchanged if the
`TaskDef` contains any other kind of `Selector`.
@Duhemm
Copy link
Contributor Author

Duhemm commented Feb 26, 2024

Hi @satorg! Would you mind taking a look at this PR, please?

@Duhemm
Copy link
Contributor Author

Duhemm commented May 3, 2024

@satorg Hi! Any concerns with this PR?

@satorg
Copy link
Contributor

satorg commented May 3, 2024

Hi @Duhemm ! Thank you for the ping. I'm really sorry that it takes so much time to review your PR.

Honestly, I made a couple of attempts to look into it, but every time was realizing that I'm not really sure what the problem the PR is aimed to solve.

It does not mean that there's anything wrong with your PR, but rather it seems that I've never encountered that kind of issue in my personal experience.

So I would really appreciate if you could elaborate a bit more on the issue the PR is addressing, maybe with some really small examples. I believe it could help to move it forward.

Anyway, thank you for contributing to the project!

@Duhemm
Copy link
Contributor Author

Duhemm commented Jul 2, 2024

Hi @satorg, thanks for taking a look and sorry for taking so long to get back to you!

sbt's test-interface API has a concept of Selector which can be passed to a test framework, so that only the selected subset of the entire test suite is run. They make it possible to encode, in a programmatic and framework agnostic way, the command line filter that most test frameworks also support (eg. in ScalaCheck: -propFilter).

For instance, Bloop uses TestSelector to ask test frameworks to run only a selected subset of test cases within a test class: https://github.com/scalacenter/bloop/blob/c505385edf0bbd420e19401ae1beabae8895df8f/frontend/src/main/scala/bloop/engine/tasks/TestTask.scala#L343-L348

In my case, I am working on a plugin that adds test retry in sbt. When a test case ("property", in ScalaCheck) fails, it is automatically retried a few times until it passes so that the build is not blocked by flaky tests. The changes in this PR will make it possible for the plugin to retry only the failing test case instead of the entire test object.

Please let me know if you have other questions or if the benefits of this PR are still unclear.

@Duhemm
Copy link
Contributor Author

Duhemm commented Aug 23, 2024

Hi @satorg! Was my message above helpful or do you have other questions and concerns?

Previously, only the last property would be verified and the others
would be ignored. This patch fixes the tests so that all properties are
verified.
@satorg
Copy link
Contributor

satorg commented Sep 1, 2024

@Duhemm , thank you for the clarification and sorry again for the long review.

I'm really trying to wrap my head around the problem.

You mentioned the -propFilter option, and looks it is already working as expected:

sbt:scalacheck> coreJVM/testOnly org.scalacheck.ChooseSpecification -- -propFilter BigInt
[info] + Choose.choose[BigInt]: OK, passed 100 tests.
[info] + Choose.choose[BigInteger]: OK, passed 100 tests.
[info] + Choose.choose(BigInt( 2^(2^18 - 1)), BigInt(-2^(2^18 - 1))): OK, passed 100 tests.
[info] Passed: Total 3, Failed 0, Errors 0, Passed 3
[success] Total time: 1 s, completed Aug 31, 2024, 9:29:11 PM

I.e. only the properties with names containing "BigInt" get executed.

Is there any way to reproduce the issue you're targeting with any existing testing framework or is it specific to the plugin you're working on?

@satorg
Copy link
Contributor

satorg commented Aug 12, 2025

@Duhemm , thank you for your contribution. I found some time to wrap my head around the issue eventually. Could you let us know your thoughts on how we could proceed here please: #1107 (comment)

Copy link
Contributor

@satorg satorg left a comment

Choose a reason for hiding this comment

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

Thanks!

@satorg satorg requested a review from Copilot August 13, 2025 04:20
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds functionality to selectively execute only specific properties when TestSelectors are provided to the ScalaCheck framework. Previously, ScalaCheck ignored selectors in the root task and would always run all properties in a specification.

  • Modified the rootTask execution logic to filter properties based on TestSelectors when only TestSelectors are present
  • Added comprehensive test coverage to verify the selective execution behavior works correctly
  • Maintains backward compatibility by running all properties when non-TestSelector selectors are present

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
ScalaCheckFramework.scala Implements property filtering logic in rootTask to respect TestSelectors
ScalaCheckFrameworkSpecification.scala Adds test suite to verify selective property execution functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@satorg satorg merged commit 8744565 into typelevel:main Aug 13, 2025
18 checks passed
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