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

Add TestAspect.checks to allow running aspects within property-based specs #9076

Merged
merged 6 commits into from
Aug 13, 2024

Conversation

mschuwalow
Copy link
Member

@mschuwalow mschuwalow commented Aug 5, 2024

resolves #9046
/claim #9046

Copy link

algora-pbc bot commented Aug 5, 2024

💵 To receive payouts, sign up on Algora, link your Github account and connect with Stripe.

* NOTE: default implementation for backward compatibility. Remove in next
* major version.
*/
def checkSampleAspect: TestAspect.CheckSampleAspect = ZIOAspect.identity
Copy link
Member Author

Choose a reason for hiding this comment

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

This guy is a bit unfortunate as it's possible to forget to forward the aspect when creating proxies like in TestAspect.scala, but it's the most backward-compatible approach I could come up with.
Suggestions welcome.

Copy link
Contributor

Choose a reason for hiding this comment

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

Had this issue myself a few times.

Scala needs an annotation on methods that should always be overwritten by concrete implementations 🥲

@mschuwalow mschuwalow force-pushed the check-aspect branch 2 times, most recently from 9233ad1 to ad1b1fd Compare August 5, 2024 21:45
@mschuwalow mschuwalow changed the title Add TestAspect.checks to allow running aspects withing property-based specs Add TestAspect.checks to allow running aspects within property-based specs Aug 6, 2024
Copy link
Contributor

@kyri-petrou kyri-petrou left a comment

Choose a reason for hiding this comment

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

Thanks, looks great! Just some minor comments below

@@ -56,23 +65,57 @@ object TestConfig {

final case class Test(repeats: Int, retries: Int, samples: Int, shrinks: Int) extends TestConfig

// NOTE: Additonal class for backward compatibility. Rename to `Test` and remove the old one in next major version.
final case class Test1(
Copy link
Contributor

Choose a reason for hiding this comment

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

Next major version won't likely be for some time. Perhaps rename this to TestV2 add a @deprecated("use TestV2", "2.1.8") annotation to Test?

case Spec.TestCase(oldTest, annotations) =>
val newTest = makeAspect.mapError(TestFailure.fail).flatMap { aspect =>
testConfigWith { oldConfig =>
val newConfig = new TestConfig {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can use the TestV2 case class here instead. I don't really know why the Test case class wasn't used here but I can't think of a good reason

val retries = old.retries
val samples = old.samples
val shrinks = old.shrinks
val repeats = n
Copy link
Contributor

Choose a reason for hiding this comment

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

As above

val retries = n
val samples = old.samples
val shrinks = old.shrinks
val repeats = old.repeats
Copy link
Contributor

Choose a reason for hiding this comment

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

As above

val retries = old.retries
val samples = n
val shrinks = old.shrinks
val repeats = old.repeats
Copy link
Contributor

Choose a reason for hiding this comment

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

As above

val retries = old.retries
val samples = old.samples
val shrinks = n
val repeats = old.repeats
Copy link
Contributor

Choose a reason for hiding this comment

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

As above

@mschuwalow mschuwalow force-pushed the check-aspect branch 2 times, most recently from 81f0816 to 6c8879a Compare August 7, 2024 16:25
Copy link
Contributor

@kyri-petrou kyri-petrou left a comment

Choose a reason for hiding this comment

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

Sorry for the nitpick 😅
It's good to go after this

Comment on lines 25 to 27
import zio.System.env
import zio.test.TestAspectAtLeastR
import zio.test.TestAspectAtLeastR
Copy link
Contributor

Choose a reason for hiding this comment

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

Leftover imports

@mschuwalow mschuwalow requested a review from kyri-petrou August 7, 2024 21:33
Copy link
Contributor

@kyri-petrou kyri-petrou left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@kyri-petrou kyri-petrou merged commit d46a7d6 into zio:series/2.x Aug 13, 2024
21 checks passed
@mschuwalow mschuwalow deleted the check-aspect branch August 13, 2024 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow running some effect before / after a single sample of check
2 participants