Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

@@ samples(N) after injectSomeShared is ignored #144

Open
strokyl opened this issue Feb 9, 2022 · 0 comments
Open

@@ samples(N) after injectSomeShared is ignored #144

strokyl opened this issue Feb 9, 2022 · 0 comments

Comments

@strokyl
Copy link

strokyl commented Feb 9, 2022

package com.github.strokyl

import zio.magic.ZSpecProvideMagicOps
import zio.test.TestAspect.{samples, sequential}
import zio.test._
import zio.test.environment.TestEnvironment
import zio.{ZIO, ZLayer}

object SampleSpec extends DefaultRunnableSpec {
  val sampleSpec1: ZSpec[TestEnvironment, Any] = suite("suite 1")(
    testM("samples") {
      checkM(Gen.anyInt) { _ =>
        ZIO.serviceWith[Unit](_ =>
          ZIO.debug("sample after provideSomeLayerShared (should be seen 1)").as(assertCompletes)
        )
      }
    }
  ).provideSomeLayerShared[TestEnvironment](
    ZLayer.succeed[Unit](())
  ) @@ samples(1)

  val sampleSpec2: ZSpec[TestEnvironment, Any] = (
    suite("suite 2")(
      testM("samples") {
        checkM(Gen.anyInt) { _ =>
          ZIO.serviceWith[Unit](_ =>
            ZIO.debug("sample(1) before injectSomeShared").as(assertCompletes)
          )
        }
      }
    ) @@ samples(1)
    ).injectSomeShared[TestEnvironment](
    ZLayer.succeed[Unit](())
  )

  val sampleSpec3: ZSpec[TestEnvironment, Any] =
    suite("suite 3")(
      testM("samples") {
        checkM(Gen.anyInt) { _ =>
          ZIO.serviceWith[Unit](_ =>
            ZIO.debug("final sample(2) after provideSomeLayerShared").as(assertCompletes)
          )
        }
      }
    ).provideSomeLayerShared[TestEnvironment](
      ZLayer.succeed[Unit](())
    )

  val sampleSpec4: ZSpec[TestEnvironment, Any] =
    suite("suite 4")(
      testM("samples") {
        checkM(Gen.anyInt) { _ =>
          ZIO.serviceWith[Unit](_ =>
            ZIO.debug("sample(1) after injectSomeShared").as(assertCompletes)
          )
        }
      }
    ).injectSomeShared[TestEnvironment](
      ZLayer.succeed[Unit](())
    ) @@ samples(1)

  val sampleSpec5: ZSpec[TestEnvironment, Any] = (
    suite("suite 5")(
      testM("samples") {
        checkM(Gen.anyInt) { _ =>
          ZIO.serviceWith[Unit](_ =>
            ZIO.debug("final sample(2) after injectSomeShared").as(assertCompletes)
          )
        }
      }
    )
    ).injectSomeShared[TestEnvironment](
    ZLayer.succeed[Unit](())
  )


  override def spec: ZSpec[TestEnvironment, Any] = suite("elements vs fromIterable")(
    sampleSpec1,
    sampleSpec2,
    sampleSpec3,
    sampleSpec4,
    sampleSpec5,
  ) @@ samples(2) @@ sequential
}

When running this test, I got way too much printing for:

  • sample(1) after injectSomeShared
  • final sample(2) after injectSomeShared
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant