diff --git a/core-tests/jvm/src/test/scala/zio/SystemSpec.scala b/core-tests/jvm/src/test/scala/zio/SystemSpec.scala index 0743fb781408..c54162000f74 100644 --- a/core-tests/jvm/src/test/scala/zio/SystemSpec.scala +++ b/core-tests/jvm/src/test/scala/zio/SystemSpec.scala @@ -7,7 +7,7 @@ import java.io.File object SystemSpec extends ZIOBaseSpec { - def spec: Spec[Live with Annotations, Any] = suite("SystemSpec")( + def spec: Spec[Any, Any] = suite("SystemSpec")( suite("Fetch an environment variable and check that")( test("If it exists, return a reasonable value") { assertZIO(live(System.env("PATH")))(isSome(containsString(File.separator + "bin"))) diff --git a/core-tests/jvm/src/test/scala/zio/interop/JavaSpec.scala b/core-tests/jvm/src/test/scala/zio/interop/JavaSpec.scala index b7bc03ccb4ca..be28416dcc7a 100644 --- a/core-tests/jvm/src/test/scala/zio/interop/JavaSpec.scala +++ b/core-tests/jvm/src/test/scala/zio/interop/JavaSpec.scala @@ -14,7 +14,7 @@ object JavaSpec extends ZIOBaseSpec { import ZIOTag._ - def spec: Spec[Annotations, Any] = suite("JavaSpec")( + def spec: Spec[Any, Any] = suite("JavaSpec")( suite("`ZIO.fromFutureJava` must")( test("be lazy on the `Future` parameter") { var evaluated = false diff --git a/core-tests/shared/src/test/scala/zio/BitChunkByteSpec.scala b/core-tests/shared/src/test/scala/zio/BitChunkByteSpec.scala index 0c7a18f1a689..c90f77766465 100644 --- a/core-tests/shared/src/test/scala/zio/BitChunkByteSpec.scala +++ b/core-tests/shared/src/test/scala/zio/BitChunkByteSpec.scala @@ -5,22 +5,22 @@ import zio.test._ object BitChunkByteSpec extends ZIOBaseSpec { - val genByteChunk: Gen[Sized, Chunk[Byte]] = + val genByteChunk: Gen[Any, Chunk[Byte]] = for { bytes <- Gen.listOf(Gen.byte) } yield Chunk.fromIterable(bytes) - val genInt: Gen[Sized, Int] = + val genInt: Gen[Any, Int] = Gen.small(Gen.const(_)) - val genBitChunk: Gen[Sized, Chunk.BitChunkByte] = + val genBitChunk: Gen[Any, Chunk.BitChunkByte] = for { chunk <- genByteChunk i <- Gen.int(0, chunk.length * 8) j <- Gen.int(0, chunk.length * 8) } yield Chunk.BitChunkByte(chunk, i min j, i max j) - val genBoolChunk: Gen[Sized, Chunk[Boolean]] = + val genBoolChunk: Gen[Any, Chunk[Boolean]] = Gen.listOf(Gen.boolean).map(Chunk.fromIterable(_)) def toBinaryString(byte: Byte): String = diff --git a/core-tests/shared/src/test/scala/zio/BitChunkIntSpec.scala b/core-tests/shared/src/test/scala/zio/BitChunkIntSpec.scala index 1334596cdddc..7cc95efb1e02 100644 --- a/core-tests/shared/src/test/scala/zio/BitChunkIntSpec.scala +++ b/core-tests/shared/src/test/scala/zio/BitChunkIntSpec.scala @@ -5,15 +5,15 @@ import zio.test._ object BitChunkIntSpec extends ZIOBaseSpec { - val genIntChunk: Gen[Sized, Chunk[Int]] = + val genIntChunk: Gen[Any, Chunk[Int]] = for { ints <- Gen.listOf(Gen.int) } yield Chunk.fromIterable(ints) - val genInt: Gen[Sized, Int] = + val genInt: Gen[Any, Int] = Gen.small(Gen.const(_)) - val genEndianness: Gen[Sized, Chunk.BitChunk.Endianness] = + val genEndianness: Gen[Any, Chunk.BitChunk.Endianness] = Gen.elements(Chunk.BitChunk.Endianness.BigEndian, Chunk.BitChunk.Endianness.LittleEndian) def toBinaryString(endianness: Chunk.BitChunk.Endianness)(int: Int): String = { diff --git a/core-tests/shared/src/test/scala/zio/BitChunkLongSpec.scala b/core-tests/shared/src/test/scala/zio/BitChunkLongSpec.scala index 7a601a15ca29..7575d9373c92 100644 --- a/core-tests/shared/src/test/scala/zio/BitChunkLongSpec.scala +++ b/core-tests/shared/src/test/scala/zio/BitChunkLongSpec.scala @@ -5,15 +5,15 @@ import zio.test._ object BitChunkLongSpec extends ZIOBaseSpec { - val genLongChunk: Gen[Sized, Chunk[Long]] = + val genLongChunk: Gen[Any, Chunk[Long]] = for { longs <- Gen.listOf(Gen.long) } yield Chunk.fromIterable(longs) - val genInt: Gen[Sized, Int] = + val genInt: Gen[Any, Int] = Gen.small(Gen.const(_)) - val genEndianness: Gen[Sized, Chunk.BitChunk.Endianness] = + val genEndianness: Gen[Any, Chunk.BitChunk.Endianness] = Gen.elements(Chunk.BitChunk.Endianness.BigEndian, Chunk.BitChunk.Endianness.LittleEndian) def toBinaryString(endianness: Chunk.BitChunk.Endianness)(long: Long): String = { diff --git a/core-tests/shared/src/test/scala/zio/CauseSpec.scala b/core-tests/shared/src/test/scala/zio/CauseSpec.scala index 0d09acc5b045..2f8cd560ba5c 100644 --- a/core-tests/shared/src/test/scala/zio/CauseSpec.scala +++ b/core-tests/shared/src/test/scala/zio/CauseSpec.scala @@ -165,10 +165,10 @@ object CauseSpec extends ZIOBaseSpec { ) ) @@ samples(10) - val causes: Gen[Sized, Cause[String]] = + val causes: Gen[Any, Cause[String]] = Gen.causes(Gen.string, Gen.string.map(s => new RuntimeException(s))) - val equalCauses: Gen[Sized, (Cause[String], Cause[String])] = + val equalCauses: Gen[Any, (Cause[String], Cause[String])] = (causes <*> causes <*> causes).flatMap { case (a, b, c) => Gen.elements( (a, a), @@ -183,10 +183,10 @@ object CauseSpec extends ZIOBaseSpec { ) } - val errorCauseFunctions: Gen[Sized, String => Cause[String]] = + val errorCauseFunctions: Gen[Any, String => Cause[String]] = Gen.function(causes) - val errors: Gen[Sized, String] = + val errors: Gen[Any, String] = Gen.string val fiberIds: Gen[Any, FiberId] = diff --git a/core-tests/shared/src/test/scala/zio/ChunkPackedBooleanSpec.scala b/core-tests/shared/src/test/scala/zio/ChunkPackedBooleanSpec.scala index 65e8419fd523..2ab89198d999 100644 --- a/core-tests/shared/src/test/scala/zio/ChunkPackedBooleanSpec.scala +++ b/core-tests/shared/src/test/scala/zio/ChunkPackedBooleanSpec.scala @@ -5,10 +5,10 @@ import zio.test._ object ChunkPackedBooleanSpec extends ZIOBaseSpec { - val genEndianness: Gen[Sized, Chunk.BitChunk.Endianness] = + val genEndianness: Gen[Any, Chunk.BitChunk.Endianness] = Gen.elements(Chunk.BitChunk.Endianness.BigEndian, Chunk.BitChunk.Endianness.LittleEndian) - val genBoolChunk: Gen[Sized, Chunk[Boolean]] = + val genBoolChunk: Gen[Any, Chunk[Boolean]] = for { endianness <- genEndianness booleanChunk <- Gen.listOf(Gen.boolean).map(Chunk.fromIterable) @@ -18,7 +18,7 @@ object ChunkPackedBooleanSpec extends ZIOBaseSpec { oneOf <- Gen.elements(booleanChunk, byteChunk, intChunk, longChunk) } yield oneOf - val genInt: Gen[Sized, Int] = + val genInt: Gen[Any, Int] = Gen.small(Gen.const(_)) def toBinaryString(bool: Boolean): String = diff --git a/core-tests/shared/src/test/scala/zio/ChunkSpec.scala b/core-tests/shared/src/test/scala/zio/ChunkSpec.scala index d28ec4509b28..2beed66f6987 100644 --- a/core-tests/shared/src/test/scala/zio/ChunkSpec.scala +++ b/core-tests/shared/src/test/scala/zio/ChunkSpec.scala @@ -18,16 +18,16 @@ object ChunkSpec extends ZIOBaseSpec { def tinyChunks[R, A](a: Gen[R, A]): Gen[R, Chunk[A]] = Gen.chunkOfBounded(0, 3)(a) - def smallChunks[R, A](a: Gen[R, A]): Gen[R with Sized, Chunk[A]] = + def smallChunks[R, A](a: Gen[R, A]): Gen[R, Chunk[A]] = Gen.small(Gen.chunkOfN(_)(a)) - def mediumChunks[R, A](a: Gen[R, A]): Gen[R with Sized, Chunk[A]] = + def mediumChunks[R, A](a: Gen[R, A]): Gen[R, Chunk[A]] = Gen.medium(Gen.chunkOfN(_)(a)) - def largeChunks[R, A](a: Gen[R, A]): Gen[R with Sized, Chunk[A]] = + def largeChunks[R, A](a: Gen[R, A]): Gen[R, Chunk[A]] = Gen.large(Gen.chunkOfN(_)(a)) - def chunkWithIndex[R, A](a: Gen[R, A]): Gen[R with Sized, (Chunk[A], Int)] = + def chunkWithIndex[R, A](a: Gen[R, A]): Gen[R, (Chunk[A], Int)] = for { chunk <- Gen.chunkOfBounded(1, 100)(a) idx <- Gen.int(0, chunk.length - 1) @@ -58,7 +58,7 @@ object ChunkSpec extends ZIOBaseSpec { ), suite("append")( test("apply") { - val chunksWithIndex: Gen[Sized, (Chunk[Int], Chunk[Int], Int)] = + val chunksWithIndex: Gen[Any, (Chunk[Int], Chunk[Int], Int)] = for { p <- Gen.boolean as <- Gen.chunkOf(Gen.int) @@ -114,7 +114,7 @@ object ChunkSpec extends ZIOBaseSpec { ), suite("prepend")( test("apply") { - val chunksWithIndex: Gen[Sized, (Chunk[Int], Chunk[Int], Int)] = + val chunksWithIndex: Gen[Any, (Chunk[Int], Chunk[Int], Int)] = for { p <- Gen.boolean as <- Gen.chunkOf(Gen.int) @@ -218,7 +218,7 @@ object ChunkSpec extends ZIOBaseSpec { test("corresponds") { val genChunk = smallChunks(intGen) val genFunction = - Gen.function[Sized, (Int, Int), Boolean](Gen.boolean).map(Function.untupled(_)) + Gen.function[Any, (Int, Int), Boolean](Gen.boolean).map(Function.untupled(_)) check(genChunk, genChunk, genFunction) { (as, bs, f) => val actual = as.corresponds(bs)(f) val expected = as.toList.corresponds(bs.toList)(f) @@ -281,7 +281,7 @@ object ChunkSpec extends ZIOBaseSpec { } @@ zioTag(errors) ), test("map") { - val fn = Gen.function[Sized, Int, Int](intGen) + val fn = Gen.function[Any, Int, Int](intGen) check(smallChunks(intGen), fn)((c, f) => assert(c.map(f).toList)(equalTo(c.toList.map(f)))) }, suite("mapZIO")( @@ -293,7 +293,7 @@ object ChunkSpec extends ZIOBaseSpec { } @@ zioTag(errors) ), test("flatMap") { - val fn = Gen.function[Sized, Int, Chunk[Int]](smallChunks(intGen)) + val fn = Gen.function[Any, Int, Chunk[Int]](smallChunks(intGen)) check(smallChunks(intGen), fn) { (c, f) => assert(c.flatMap(f).toList)(equalTo(c.toList.flatMap(f.andThen(_.toList)))) } @@ -309,7 +309,7 @@ object ChunkSpec extends ZIOBaseSpec { check(mediumChunks(intGen))(c => assert(c.lastOption)(equalTo(c.toList.lastOption))) }, test("indexWhere") { - val fn = Gen.function[Sized, Int, Boolean](Gen.boolean) + val fn = Gen.function[Any, Int, Boolean](Gen.boolean) check(smallChunks(intGen), smallChunks(intGen), fn, intGen) { (left, right, p, from) => val actual = (left ++ right).indexWhere(p, from) val expected = (left.toVector ++ right.toVector).indexWhere(p, from) @@ -317,15 +317,15 @@ object ChunkSpec extends ZIOBaseSpec { } } @@ exceptScala211, test("exists") { - val fn = Gen.function[Sized, Int, Boolean](Gen.boolean) + val fn = Gen.function[Any, Int, Boolean](Gen.boolean) check(mediumChunks(intGen), fn)((chunk, p) => assert(chunk.exists(p))(equalTo(chunk.toList.exists(p)))) }, test("forall") { - val fn = Gen.function[Sized, Int, Boolean](Gen.boolean) + val fn = Gen.function[Any, Int, Boolean](Gen.boolean) check(mediumChunks(intGen), fn)((chunk, p) => assert(chunk.forall(p))(equalTo(chunk.toList.forall(p)))) }, test("find") { - val fn = Gen.function[Sized, Int, Boolean](Gen.boolean) + val fn = Gen.function[Any, Int, Boolean](Gen.boolean) check(mediumChunks(intGen), fn)((chunk, p) => assert(chunk.find(p))(equalTo(chunk.toList.find(p)))) }, suite("findZIO")( @@ -337,7 +337,7 @@ object ChunkSpec extends ZIOBaseSpec { } @@ zioTag(errors) ), test("filter") { - val fn = Gen.function[Sized, Int, Boolean](Gen.boolean) + val fn = Gen.function[Any, Int, Boolean](Gen.boolean) check(mediumChunks(intGen), fn)((chunk, p) => assert(chunk.filter(p).toList)(equalTo(chunk.toList.filter(p)))) }, suite("filterZIO")( @@ -424,7 +424,7 @@ object ChunkSpec extends ZIOBaseSpec { assert(Chunk.empty[Nothing].collect { case _ => 1 })(isEmpty) }, test("collect chunk") { - val pfGen = Gen.partialFunction[Sized, Int, Int](intGen) + val pfGen = Gen.partialFunction[Any, Int, Int](intGen) check(mediumChunks(intGen), pfGen)((c, pf) => assert(c.collect(pf).toList)(equalTo(c.toList.collect(pf)))) } ), @@ -433,7 +433,7 @@ object ChunkSpec extends ZIOBaseSpec { assertZIO(Chunk.empty[Nothing].collectZIO { case _ => ZIO.succeed(1) })(equalTo(Chunk.empty)) }, test("collectZIO chunk") { - val pfGen = Gen.partialFunction[Sized, Int, UIO[Int]](Gen.successes(intGen)) + val pfGen = Gen.partialFunction[Any, Int, UIO[Int]](Gen.successes(intGen)) check(mediumChunks(intGen), pfGen) { (c, pf) => for { result <- c.collectZIO(pf).map(_.toList) @@ -450,7 +450,7 @@ object ChunkSpec extends ZIOBaseSpec { assert(Chunk.empty[Nothing].collectWhile { case _ => 1 })(isEmpty) }, test("collectWhile chunk") { - val pfGen = Gen.partialFunction[Sized, Int, Int](intGen) + val pfGen = Gen.partialFunction[Any, Int, Int](intGen) check(mediumChunks(intGen), pfGen) { (c, pf) => assert(c.collectWhile(pf).toList)(equalTo(c.toList.takeWhile(pf.isDefinedAt).map(pf.apply))) } @@ -461,7 +461,7 @@ object ChunkSpec extends ZIOBaseSpec { assertZIO(Chunk.empty[Nothing].collectWhileZIO { case _ => ZIO.succeed(1) })(equalTo(Chunk.empty)) }, test("collectWhileZIO chunk") { - val pfGen = Gen.partialFunction[Sized, Int, UIO[Int]](Gen.successes(intGen)) + val pfGen = Gen.partialFunction[Any, Int, UIO[Int]](Gen.successes(intGen)) check(mediumChunks(intGen), pfGen) { (c, pf) => for { result <- c.collectWhileZIO(pf).map(_.toList) diff --git a/core-tests/shared/src/test/scala/zio/DifferSpec.scala b/core-tests/shared/src/test/scala/zio/DifferSpec.scala index e59a6d1f7a8e..05074d455b74 100644 --- a/core-tests/shared/src/test/scala/zio/DifferSpec.scala +++ b/core-tests/shared/src/test/scala/zio/DifferSpec.scala @@ -26,7 +26,7 @@ object DifferSpec extends ZIOSpecDefault { def diffLaws[Environment, Value, Patch](differ: Differ[Value, Patch])( gen: Gen[Environment, Value] - )(equal: (Value, Value) => Boolean): Spec[Environment with TestConfig, Nothing] = + )(equal: (Value, Value) => Boolean): Spec[Environment, Nothing] = suite("differ laws")( test("combining patches is associative") { check(gen, gen, gen, gen) { (value1, value2, value3, value4) => diff --git a/core-tests/shared/src/test/scala/zio/HubSpec.scala b/core-tests/shared/src/test/scala/zio/HubSpec.scala index 88eb608fbc42..ccf85adca7a8 100644 --- a/core-tests/shared/src/test/scala/zio/HubSpec.scala +++ b/core-tests/shared/src/test/scala/zio/HubSpec.scala @@ -4,7 +4,7 @@ import zio.test.Assertion._ import zio.test._ object HubSpec extends ZIOBaseSpec { - val smallInt: Gen[Sized, Int] = + val smallInt: Gen[Any, Int] = Gen.small(Gen.const(_), 1) def spec = suite("HubSpec")( diff --git a/core-tests/shared/src/test/scala/zio/NonEmptyChunkSpec.scala b/core-tests/shared/src/test/scala/zio/NonEmptyChunkSpec.scala index f554956df747..45c693c5a51f 100644 --- a/core-tests/shared/src/test/scala/zio/NonEmptyChunkSpec.scala +++ b/core-tests/shared/src/test/scala/zio/NonEmptyChunkSpec.scala @@ -5,7 +5,7 @@ import zio.test._ object NonEmptyChunkSpec extends ZIOBaseSpec { - lazy val genChunk: Gen[Sized, Chunk[Int]] = Gen.chunkOf(genInt) + lazy val genChunk: Gen[Any, Chunk[Int]] = Gen.chunkOf(genInt) lazy val genInt: Gen[Any, Int] = Gen.int(-10, 10) @@ -13,9 +13,9 @@ object NonEmptyChunkSpec extends ZIOBaseSpec { lazy val genIntFunction2: Gen[Any, (Any, Any) => Int] = Gen.function2(genInt) - lazy val genNonEmptyChunk: Gen[Sized, NonEmptyChunk[Int]] = Gen.chunkOf1(genInt) + lazy val genNonEmptyChunk: Gen[Any, NonEmptyChunk[Int]] = Gen.chunkOf1(genInt) - lazy val genNonEmptyChunkFunction: Gen[Sized, Any => NonEmptyChunk[Int]] = + lazy val genNonEmptyChunkFunction: Gen[Any, Any => NonEmptyChunk[Int]] = Gen.function(genNonEmptyChunk) def spec = suite("NonEmptyChunkSpec")( diff --git a/core-tests/shared/src/test/scala/zio/QueueSpec.scala b/core-tests/shared/src/test/scala/zio/QueueSpec.scala index 75bc47b81444..b0a5cce11a6d 100644 --- a/core-tests/shared/src/test/scala/zio/QueueSpec.scala +++ b/core-tests/shared/src/test/scala/zio/QueueSpec.scala @@ -772,12 +772,12 @@ object QueueSpec extends ZIOBaseSpec { } object QueueSpecUtil { - def waitForValue[T](ref: UIO[T], value: T): URIO[Live, T] = + def waitForValue[T](ref: UIO[T], value: T): UIO[T] = Live.live((ref <* Clock.sleep(10.millis)).repeatUntil(_ == value)) - def waitForSize[A](queue: Queue[A], size: Int): URIO[Live, Int] = + def waitForSize[A](queue: Queue[A], size: Int): UIO[Int] = waitForValue(queue.size, size) - val smallInt: Gen[Sized, Int] = + val smallInt: Gen[Any, Int] = Gen.small(Gen.const(_), 1) } diff --git a/core-tests/shared/src/test/scala/zio/TaggedSpec.scala b/core-tests/shared/src/test/scala/zio/TaggedSpec.scala index ea400633f510..b4521e27bcba 100644 --- a/core-tests/shared/src/test/scala/zio/TaggedSpec.scala +++ b/core-tests/shared/src/test/scala/zio/TaggedSpec.scala @@ -6,7 +6,7 @@ import zio.test._ object TaggedSpec extends ZIOBaseSpec { - def spec: Spec[Annotations, TestFailure[Any]] = suite("TaggedSpec")( + def spec: Spec[Any, TestFailure[Any]] = suite("TaggedSpec")( test("tags can be derived for polymorphic services") { val result = typeCheck { """ diff --git a/core-tests/shared/src/test/scala/zio/ZIOBaseSpec.scala b/core-tests/shared/src/test/scala/zio/ZIOBaseSpec.scala index a42b3b4fe52d..580913b4f3d7 100644 --- a/core-tests/shared/src/test/scala/zio/ZIOBaseSpec.scala +++ b/core-tests/shared/src/test/scala/zio/ZIOBaseSpec.scala @@ -5,7 +5,7 @@ import zio.test._ import scala.annotation.tailrec trait ZIOBaseSpec extends ZIOSpecDefault { - override def aspects: Chunk[TestAspectAtLeastR[Live]] = + override def aspects: Chunk[TestAspectPoly] = if (TestPlatform.isJVM) Chunk(TestAspect.timeout(120.seconds)) else Chunk(TestAspect.timeout(120.seconds), TestAspect.sequential) diff --git a/core-tests/shared/src/test/scala/zio/ZIOSpec.scala b/core-tests/shared/src/test/scala/zio/ZIOSpec.scala index 575ddc688c1d..6830f7d89507 100644 --- a/core-tests/shared/src/test/scala/zio/ZIOSpec.scala +++ b/core-tests/shared/src/test/scala/zio/ZIOSpec.scala @@ -4214,10 +4214,10 @@ object ZIOSpec extends ZIOBaseSpec { ) ) - def functionIOGen: Gen[Sized, String => ZIO[Any, Throwable, Int]] = - Gen.function[Sized, String, Task[Int]](Gen.successes(Gen.int)) + def functionIOGen: Gen[Any, String => ZIO[Any, Throwable, Int]] = + Gen.function[Any, String, Task[Int]](Gen.successes(Gen.int)) - def listGen: Gen[Sized, List[String]] = + def listGen: Gen[Any, List[String]] = Gen.listOfN(100)(Gen.alphaNumericString) val exampleError = new Error("something went wrong") diff --git a/core-tests/shared/src/test/scala/zio/internal/StackSpec.scala b/core-tests/shared/src/test/scala/zio/internal/StackSpec.scala index bf8782c1b375..eb81a3898ad7 100644 --- a/core-tests/shared/src/test/scala/zio/internal/StackSpec.scala +++ b/core-tests/shared/src/test/scala/zio/internal/StackSpec.scala @@ -87,6 +87,6 @@ object StackSpec extends ZIOBaseSpec { case object True extends Boolean case object False extends Boolean - val gen: Gen[Sized, List[Boolean]] = + val gen: Gen[Any, List[Boolean]] = Gen.large(n => Gen.listOfN(n)(Gen.elements(True, False))) } diff --git a/core-tests/shared/src/test/scala/zio/stm/THubSpec.scala b/core-tests/shared/src/test/scala/zio/stm/THubSpec.scala index 1854690bf8ae..67f24e711bcd 100644 --- a/core-tests/shared/src/test/scala/zio/stm/THubSpec.scala +++ b/core-tests/shared/src/test/scala/zio/stm/THubSpec.scala @@ -2,11 +2,11 @@ package zio.stm import zio._ import zio.test.Assertion._ -import zio.test.{assert, Gen, Sized, check} +import zio.test.{assert, Gen, check} object THubSpec extends ZIOBaseSpec { - val smallInt: Gen[Sized, Int] = + val smallInt: Gen[Any, Int] = Gen.small(Gen.const(_), 1) def spec = diff --git a/core-tests/shared/src/test/scala/zio/stm/TPriorityQueueSpec.scala b/core-tests/shared/src/test/scala/zio/stm/TPriorityQueueSpec.scala index d3f09b894d86..d93613201412 100644 --- a/core-tests/shared/src/test/scala/zio/stm/TPriorityQueueSpec.scala +++ b/core-tests/shared/src/test/scala/zio/stm/TPriorityQueueSpec.scala @@ -11,13 +11,13 @@ object TPriorityQueueSpec extends ZIOBaseSpec { implicit val eventOrdering: Ordering[Event] = Ordering.by(_.time) - val genEvent: Gen[Sized, Event] = + val genEvent: Gen[Any, Event] = for { time <- Gen.int(-10, 10) description <- Gen.alphaNumericString } yield Event(time, description) - val genEvents: Gen[Sized, Chunk[Event]] = + val genEvents: Gen[Any, Chunk[Event]] = Gen.chunkOf(genEvent) val genPredicate: Gen[Any, Event => Boolean] = diff --git a/core-tests/shared/src/test/scala/zio/stm/TRandomSpec.scala b/core-tests/shared/src/test/scala/zio/stm/TRandomSpec.scala index 7fb674ad9f55..496bd9aa6b77 100644 --- a/core-tests/shared/src/test/scala/zio/stm/TRandomSpec.scala +++ b/core-tests/shared/src/test/scala/zio/stm/TRandomSpec.scala @@ -46,7 +46,7 @@ object TRandomSpec extends ZIOBaseSpec { assert(n)(isLessThan(max)) } } - ).provideCustomLayer(TRandom.live) + ).provideLayer(TRandom.live) val genDoubles: Gen[Any, (Double, Double)] = for { diff --git a/core-tests/shared/src/test/scala/zio/stm/ZSTMSpec.scala b/core-tests/shared/src/test/scala/zio/stm/ZSTMSpec.scala index bb7f62df6126..6e1466dadcfa 100644 --- a/core-tests/shared/src/test/scala/zio/stm/ZSTMSpec.scala +++ b/core-tests/shared/src/test/scala/zio/stm/ZSTMSpec.scala @@ -1238,7 +1238,7 @@ object ZSTMSpec extends ZIOBaseSpec { .eventually } - def liveClockSleep(d: Duration): ZIO[Live, Nothing, Unit] = Live.live(ZIO.sleep(d)) + def liveClockSleep(d: Duration): ZIO[Any, Nothing, Unit] = Live.live(ZIO.sleep(d)) def incrementVarN(n: Int, tvar: TRef[Int]): ZIO[Any, Nothing, Int] = STM diff --git a/core/shared/src/main/scala/zio/package.scala b/core/shared/src/main/scala/zio/package.scala index fabeb9e62b21..96dcabd579a3 100644 --- a/core/shared/src/main/scala/zio/package.scala +++ b/core/shared/src/main/scala/zio/package.scala @@ -29,6 +29,7 @@ package object zio type RuntimeFlags = Int + type ZAny >: Any type ZNothing <: Nothing type IO[+E, +A] = ZIO[Any, E, A] // Succeed with an `A`, may fail with `E` , no requirements. diff --git a/docs/reference/test/aspects/sized.md b/docs/reference/test/aspects/sized.md index 10792b4641fa..f66a007d8b6d 100644 --- a/docs/reference/test/aspects/sized.md +++ b/docs/reference/test/aspects/sized.md @@ -3,7 +3,7 @@ id: sized title: "Changing the Size of Sized Generators" --- -To change the default _size_ used by [sized generators](../gen.md#sized-generators) we can use `sized` test aspect: +To change the default _size_ used by [sized generators](../gen.md#sized-generators) we can use `size` test aspect: ```scala mdoc:compile-only import zio._ @@ -13,7 +13,7 @@ test("generating small list of characters") { check(Gen.small(Gen.listOfN(_)(Gen.alphaNumericChar))) { n => ZIO.attempt(n).debug *> Sized.size.map(s => assertTrue(s == 50)) } -} @@ TestAspect.sized(50) @@ TestAspect.samples(5) +} @@ TestAspect.size(50) @@ TestAspect.samples(5) ``` Sample output: diff --git a/docs/reference/test/property-testing/generators.md b/docs/reference/test/property-testing/generators.md index b92da283e60e..b489aa8a596a 100644 --- a/docs/reference/test/property-testing/generators.md +++ b/docs/reference/test/property-testing/generators.md @@ -152,7 +152,7 @@ The `Gen.suspend` constructs a generator lazily. This is useful to avoid infinit The `unfoldGen` takes the initial state and depending on the previous state, it determines what will be the next generated value: ```scala -def unfoldGen[R <: Sized, S, A](s: S)(f: S => Gen[R, (S, A)]): Gen[R, List[A]] +def unfoldGen[R, S, A](s: S)(f: S => Gen[R, (S, A)]): Gen[R, List[A]] ``` Assume we want to test the built-in scala stack (`scala.collection.mutable.Stack`). One way to do that is to create an acceptable series of push and pop commands, and then check that the stack doesn't throw any exception by executing these commands: @@ -165,7 +165,7 @@ final case class Push(value: Char) extends Command val genPop: Gen[Any, Command] = Gen.const(Pop) def genPush: Gen[Any, Command] = Gen.alphaChar.map(Push) -val genCommands: Gen[Sized, List[Command]] = +val genCommands: Gen[Any, List[Command]] = Gen.unfoldGen(0) { n => if (n <= 0) genPush.map(command => (n + 1, command)) @@ -344,7 +344,7 @@ test("ZIO.foldLeft should have the same result with List.foldLeft") { 2. Failed effects (`Gen.failures`): ```scala mdoc:compile-only - val gen: Gen[Sized, IO[String, Nothing]] = Gen.failures(Gen.string) + val gen: Gen[Any, IO[String, Nothing]] = Gen.failures(Gen.string) ``` 3. Died effects (`Gen.died`): @@ -356,7 +356,7 @@ test("ZIO.foldLeft should have the same result with List.foldLeft") { 4. Cause values (`Gen.causes`): ```scala mdoc:compile-only - val causes: Gen[Sized, Cause[String]] = + val causes: Gen[Any, Cause[String]] = Gen.causes(Gen.string, Gen.throwable) ``` @@ -373,7 +373,7 @@ Let's see some example of chained ZIO effects: By using `Gen.chaned` or `Gen.chanedN` generator, we can create generators of chained effects: ```scala mdoc:compile-only - val chained : Gen[Sized, ZIO[Any, Nothing, Int]] = + val chained : Gen[Any, ZIO[Any, Nothing, Int]] = Gen.chained(Gen.successes(Gen.int)) val chainedN: Gen[Any, ZIO[Any, Nothing, Int]] = @@ -390,7 +390,7 @@ By using `Gen.chaned` or `Gen.chanedN` generator, we can create generators of ch 7. Parallel effects (`Gen.parallel`): A generator of effects that are the result of applying parallelism combinators to the specified effect that are guaranteed not to change its value. ```scala mdoc:compile-only - val random: Gen[Sized, UIO[String]] = + val random: Gen[Any, UIO[String]] = Gen.successes(Gen.string).flatMap(Gen.parallel) val constant: Gen[Any, UIO[String]] = diff --git a/docs/reference/test/services/sized.md b/docs/reference/test/services/sized.md index 5e44f157a8b6..9a9284f58a69 100644 --- a/docs/reference/test/services/sized.md +++ b/docs/reference/test/services/sized.md @@ -32,7 +32,7 @@ To access the default _size_ value from the environment, we can use the `Sized.s ```scala mdoc:compile-only object Sized { - def withSize[R <: Sized, E, A](size: Int)(zio: ZIO[R, E, A]): ZIO[R, E, A] = ??? + def withSize[R, E, A](size: Int)(zio: ZIO[R, E, A]): ZIO[R, E, A] = ??? } ``` @@ -40,7 +40,7 @@ For example, the `Gen.sized` generator has the following signature: ```scala mdoc:compile-only object Gen { - def sized[R <: Sized, A](f: Int => Gen[R, A]): Gen[R, A] = ??? + def sized[R, A](f: Int => Gen[R, A]): Gen[R, A] = ??? } ``` @@ -52,59 +52,24 @@ In the following example, we are creating a sized generator, which generates int import zio._ import zio.test._ -val sizedInts: Gen[Sized, Int] = +val sizedInts: Gen[Any, Int] = Gen.sized(Gen.int(0, _)) ``` To generate some sample values, we can use `Gen#runCollectN` operator on that: ```scala mdoc:silent:nest -val samples: URIO[Sized, List[Int]] = +val samples: UIO[List[Int]] = sizedInts.runCollectN(5).debug ``` -The return type require the _Sized_ service. Therefore, to run this effect, we need to provide this service: - -```scala mdoc:silent:nest -Unsafe.unsafe { implicit unsafe => - zio.Runtime.default.unsafe.run( - samples.provide(Sized.live(100)) - ).getOrThrowFiberFailure() -} -// Sample Output: List(34, 44, 89, 14, 15) -``` - -The previous example was for educational purposes. In the real world, when we are testing, we don't need to manually provide the `Sized.live` layer. The ZIO Test Runner has a built-in `TestEnvironment` which contains all required services for testing as well as `Sized` service: - -```scala mdoc:compile-only -type TestEnvironment = - Annotations - with Live - with Sized -``` - -So when we test a property with ZIO Test, all the required services will be provided to the ZIO Test Runner: - -```scala mdoc:compile-only -object SizedSpec extends ZIOSpecDefault { - def spec = - suite("sized") { - test("bounded int generator shouldn't cross its boundaries") { - check(Gen.sized(Gen.int(0, _))) { n => - assertTrue(n >= 0 && n <= 100) // The default size is 100 - } - } - } -} -``` - ### withSize To change the default _size_ temporarily, we can use the `Size.withSize`. It takes a `size` and a ZIO effect, and runs that effect bounded with the given `size`: ```scala mdoc:compile-only object Sized { - def withSize[R <: Sized, E, A](size: Int)(zio: ZIO[R, E, A]): ZIO[R, E, A] = ??? + def withSize[R, E, A](size: Int)(zio: ZIO[R, E, A]): ZIO[R, E, A] = ??? } ``` @@ -112,11 +77,11 @@ object Sized { import zio._ import zio.test._ -val effect : UIO[String] = ZIO.succeed("effect") -val sizedEffect: RIO[Sized, String] = Sized.withSize(10)(effect) +val effect : UIO[String] = ZIO.succeed("effect") +val sizedEffect: UIO[String] = Sized.withSize(10)(effect) ``` -ZIO Test has a test aspect called `TestAspect.sized` which is a helper method for this operation. This test aspect runs each test with the given _size_ value: +ZIO Test has a test aspect called `TestAspect.size` which is a helper method for this operation. This test aspect runs each test with the given _size_ value: ```scala mdoc:compile-only import zio._ @@ -129,7 +94,7 @@ object SizedSpec extends ZIOSpecDefault { check(Gen.sized(Gen.int(0, _))) { n => assertTrue(n >= 0 && n <= 200) } - } @@ TestAspect.sized(200) + } @@ TestAspect.size(200) } } ``` diff --git a/docs/reference/test/why-zio-test.md b/docs/reference/test/why-zio-test.md index 20dfc79b9eea..825433984b3d 100644 --- a/docs/reference/test/why-zio-test.md +++ b/docs/reference/test/why-zio-test.md @@ -29,7 +29,7 @@ The `TestRandom` service has some extra functionality that enables us to test th Each of these services, comes with a bunch of functionality that makes it very easy to test effects. -Whenever we need to access the _live_ environment, we can use the `live` method in the `test` package or specify the live environment in the type signature like `Live[Console]`. +Whenever we need to access the _live_ environment, we can use the `live` method in the `test` package or test annotations like `withLiveConsole`. ## Resource Management @@ -84,14 +84,14 @@ import zio.test.magnolia._ case class Point(x: Double, y: Double) -val genPoint: Gen[Sized, Point] = DeriveGen[Point] +val genPoint: Gen[Any, Point] = DeriveGen[Point] sealed trait Color case object Red extends Color case object Green extends Color case object Blue extends Color -val genColor: Gen[Sized, Color] = DeriveGen[Color] +val genColor: Gen[Any, Color] = DeriveGen[Color] ``` ## Test Reporting diff --git a/managed-tests/shared/src/test/scala/zio/managed/ZIOBaseSpec.scala b/managed-tests/shared/src/test/scala/zio/managed/ZIOBaseSpec.scala index 32be3b0ce1e2..b68d19e4aea7 100644 --- a/managed-tests/shared/src/test/scala/zio/managed/ZIOBaseSpec.scala +++ b/managed-tests/shared/src/test/scala/zio/managed/ZIOBaseSpec.scala @@ -6,7 +6,7 @@ import zio.test._ import scala.annotation.tailrec trait ZIOBaseSpec extends ZIOSpecDefault { - override def aspects: Chunk[TestAspectAtLeastR[Live]] = + override def aspects: Chunk[TestAspectPoly] = if (TestPlatform.isJVM) Chunk(TestAspect.timeout(120.seconds)) else Chunk(TestAspect.timeout(120.seconds)) diff --git a/managed-tests/shared/src/test/scala/zio/managed/ZManagedSpec.scala b/managed-tests/shared/src/test/scala/zio/managed/ZManagedSpec.scala index 92423e9acd2b..517eba6aeaf9 100644 --- a/managed-tests/shared/src/test/scala/zio/managed/ZManagedSpec.scala +++ b/managed-tests/shared/src/test/scala/zio/managed/ZManagedSpec.scala @@ -1859,10 +1859,10 @@ object ZManagedSpec extends ZIOBaseSpec { val ZManagedExampleDie: ZManaged[Any, Throwable, Int] = ZManaged.succeed(throw ExampleError) - def countDownLatch(n: Int): UIO[URIO[Live, Unit]] = + def countDownLatch(n: Int): UIO[UIO[Unit]] = Ref.make(n).map { counter => counter.update(_ - 1) *> { - def await: URIO[Live, Unit] = counter.get.flatMap { n => + def await: UIO[Unit] = counter.get.flatMap { n => if (n <= 0) ZIO.unit else Live.live(ZIO.sleep(10.milliseconds)) *> await } @@ -1873,7 +1873,7 @@ object ZManagedSpec extends ZIOBaseSpec { def doInterrupt( managed: IO[Nothing, Unit] => ZManaged[Any, Nothing, Unit], expected: FiberId => Option[Exit[Nothing, Unit]] - ): ZIO[Live, Nothing, TestResult] = + ): ZIO[Any, Nothing, TestResult] = for { fiberId <- ZIO.fiberId never <- Promise.make[Nothing, Unit] @@ -1905,8 +1905,8 @@ object ZManagedSpec extends ZIOBaseSpec { def testAcquirePar[R, E]( n: Int, - f: ZManaged[Live, Nothing, Unit] => ZManaged[R, E, Any] - ): ZIO[R with Live, Nothing, TestResult] = + f: ZManaged[Any, Nothing, Unit] => ZManaged[R, E, Any] + ): ZIO[R, Nothing, TestResult] = for { effects <- Ref.make(0) countDown <- countDownLatch(n + 1) @@ -1922,8 +1922,8 @@ object ZManagedSpec extends ZIOBaseSpec { def testReservePar[R, E, A]( n: Int, - f: ZManaged[Live, Nothing, Unit] => ZManaged[R, E, A] - ): ZIO[R with Live, Nothing, TestResult] = + f: ZManaged[Any, Nothing, Unit] => ZManaged[R, E, A] + ): ZIO[R, Nothing, TestResult] = for { effects <- Ref.make(0) countDown <- countDownLatch(n + 1) diff --git a/streams-tests/jvm/src/test/scala/zio/stream/ZPipelinePlatformSpecificSpec.scala b/streams-tests/jvm/src/test/scala/zio/stream/ZPipelinePlatformSpecificSpec.scala index 49af439ce689..e15c5e04e6ee 100644 --- a/streams-tests/jvm/src/test/scala/zio/stream/ZPipelinePlatformSpecificSpec.scala +++ b/streams-tests/jvm/src/test/scala/zio/stream/ZPipelinePlatformSpecificSpec.scala @@ -8,7 +8,7 @@ import zio.test.Assertion._ import java.util.zip.Deflater object ZPipelinePlatformSpecificSpec extends ZIOBaseSpec { - override def aspects: Chunk[TestAspectAtLeastR[Live]] = + override def aspects: Chunk[TestAspectPoly] = Chunk(TestAspect.timeout(300.seconds)) def spec = suite("ZPipeline JVM")( diff --git a/streams-tests/shared/src/test/scala/zio/stream/TextCodecPipelineSpec.scala b/streams-tests/shared/src/test/scala/zio/stream/TextCodecPipelineSpec.scala index 2851645dacc3..a0b57ae91927 100644 --- a/streams-tests/shared/src/test/scala/zio/stream/TextCodecPipelineSpec.scala +++ b/streams-tests/shared/src/test/scala/zio/stream/TextCodecPipelineSpec.scala @@ -19,7 +19,7 @@ object TextCodecPipelineSpec extends ZIOBaseSpec { private def testDecoderUsing( decodingPipeline: UtfDecodingPipeline, sourceCharset: Charset, - byteGenerator: Gen[Sized, Chunk[Byte]], + byteGenerator: Gen[Any, Chunk[Byte]], bom: Chunk[Byte] = Chunk.empty ) = { def fixIfGeneratedBytesBeginWithBom(generated: Chunk[Byte]) = @@ -63,7 +63,7 @@ object TextCodecPipelineSpec extends ZIOBaseSpec { decodingPipeline: UtfDecodingPipeline, sourceCharset: Charset, bom: Chunk[Byte] = Chunk.empty, - stringGenerator: Gen[Sized, String] = Gen.string + stringGenerator: Gen[Any, String] = Gen.string ) = testDecoderUsing( decodingPipeline, @@ -76,7 +76,7 @@ object TextCodecPipelineSpec extends ZIOBaseSpec { textDecodingPipeline: UtfDecodingPipeline, encoderUnderTest: UtfEncodingPipeline, sourceCharset: Charset, - byteGenerator: Gen[Sized, Chunk[Byte]], + byteGenerator: Gen[Any, Chunk[Byte]], bom: Chunk[Byte] ) = { def fixIfGeneratedBytesBeginWithBom(generated: Chunk[Byte]) = @@ -113,7 +113,7 @@ object TextCodecPipelineSpec extends ZIOBaseSpec { encoderUnderTest: UtfEncodingPipeline, sourceCharset: Charset, bom: Chunk[Byte] = Chunk.empty, - stringGenerator: Gen[Sized, String] = Gen.string + stringGenerator: Gen[Any, String] = Gen.string ) = testEncoderUsing( textDecodingPipeline, diff --git a/streams-tests/shared/src/test/scala/zio/stream/ZChannelSimulatedChecks.scala b/streams-tests/shared/src/test/scala/zio/stream/ZChannelSimulatedChecks.scala index 3c08c7632e00..562556d52f8a 100644 --- a/streams-tests/shared/src/test/scala/zio/stream/ZChannelSimulatedChecks.scala +++ b/streams-tests/shared/src/test/scala/zio/stream/ZChannelSimulatedChecks.scala @@ -29,9 +29,9 @@ object ZChannelSimulatedChecks extends ZIOBaseSpec { type Err = String type Res = Int - private val genErr: Gen[Sized, Err] = + private val genErr: Gen[Any, Err] = Gen.oneOf(Gen.const("err1"), Gen.const("err2"), Gen.const("err3")) - private val genRes: Gen[Sized, Res] = Gen.int(0, 100) + private val genRes: Gen[Any, Res] = Gen.int(0, 100) private def cutAtFailure(ops: List[Op]): List[Op] = ops.reverse.dropWhile { @@ -39,7 +39,7 @@ object ZChannelSimulatedChecks extends ZIOBaseSpec { case _ => true }.reverse - private def genOps(currentDepth: Int = 1): Gen[Sized, Op] = + private def genOps(currentDepth: Int = 1): Gen[Any, Op] = Gen.double(0.0, 1.0).flatMap { n => val r = (1.0 / currentDepth) @@ -62,7 +62,7 @@ object ZChannelSimulatedChecks extends ZIOBaseSpec { } } - val gen: Gen[Sized, Simulation] = + val gen: Gen[Any, Simulation] = for { first <- genRes rest <- Gen.listOf1(genOps()).map(cutAtFailure) diff --git a/streams-tests/shared/src/test/scala/zio/stream/ZPipelineSpec.scala b/streams-tests/shared/src/test/scala/zio/stream/ZPipelineSpec.scala index bac859cf8d21..6ac9de541676 100644 --- a/streams-tests/shared/src/test/scala/zio/stream/ZPipelineSpec.scala +++ b/streams-tests/shared/src/test/scala/zio/stream/ZPipelineSpec.scala @@ -155,7 +155,7 @@ object ZPipelineSpec extends ZIOBaseSpec { ) ) - val weirdStringGenForSplitLines: Gen[Sized, Chunk[String]] = Gen + val weirdStringGenForSplitLines: Gen[Any, Chunk[String]] = Gen .chunkOf(Gen.string(Gen.printableChar).map(_.filterNot(c => c == '\n' || c == '\r'))) .map(l => if (l.nonEmpty && l.last == "") l ++ List("a") else l) diff --git a/streams-tests/shared/src/test/scala/zio/stream/ZStreamGen.scala b/streams-tests/shared/src/test/scala/zio/stream/ZStreamGen.scala index 727df4df5db4..aab74b271785 100644 --- a/streams-tests/shared/src/test/scala/zio/stream/ZStreamGen.scala +++ b/streams-tests/shared/src/test/scala/zio/stream/ZStreamGen.scala @@ -1,7 +1,7 @@ package zio.stream import zio._ -import zio.test.{Gen, GenZIO, Sized} +import zio.test.{Gen, GenZIO} object ZStreamGen extends GenZIO { def tinyListOf[R, A](g: Gen[R, A]): Gen[R, List[A]] = @@ -10,10 +10,10 @@ object ZStreamGen extends GenZIO { def tinyChunkOf[R, A](g: Gen[R, A]): Gen[R, Chunk[A]] = Gen.chunkOfBounded(0, 5)(g) - def streamGen[R, A](a: Gen[R, A], max: Int): Gen[R with Sized, ZStream[Any, String, A]] = + def streamGen[R, A](a: Gen[R, A], max: Int): Gen[R, ZStream[Any, String, A]] = Gen.oneOf(failingStreamGen(a, max), pureStreamGen(a, max)) - def pureStreamGen[R, A](a: Gen[R, A], max: Int): Gen[R with Sized, ZStream[Any, Nothing, A]] = + def pureStreamGen[R, A](a: Gen[R, A], max: Int): Gen[R, ZStream[Any, Nothing, A]] = max match { case 0 => Gen.const(ZStream.empty) case n => @@ -26,7 +26,7 @@ object ZStreamGen extends GenZIO { ) } - def failingStreamGen[R, A](a: Gen[R, A], max: Int): Gen[R with Sized, ZStream[Any, String, A]] = + def failingStreamGen[R, A](a: Gen[R, A], max: Int): Gen[R, ZStream[Any, String, A]] = max match { case 0 => Gen.const(ZStream.fromZIO(ZIO.fail("fail-case"))) case _ => @@ -46,10 +46,10 @@ object ZStreamGen extends GenZIO { def nPulls[R, E, A](pull: ZIO[R, Option[E], A], n: Int): ZIO[R, Nothing, Iterable[Either[Option[E], A]]] = ZIO.foreach(1 to n)(_ => pull.either) - val streamOfInts: Gen[Sized, ZStream[Any, String, Int]] = + val streamOfInts: Gen[Any, ZStream[Any, String, Int]] = Gen.bounded(0, 5)(streamGen(Gen.int, _)).zipWith(Gen.function(Gen.boolean))(injectEmptyChunks) - val pureStreamOfInts: Gen[Sized, ZStream[Any, Nothing, Int]] = + val pureStreamOfInts: Gen[Any, ZStream[Any, Nothing, Int]] = Gen.bounded(0, 5)(pureStreamGen(Gen.int, _)).zipWith(Gen.function(Gen.boolean))(injectEmptyChunks) def injectEmptyChunks[R, E, A](stream: ZStream[R, E, A], predicate: Chunk[A] => Boolean): ZStream[R, E, A] = @@ -58,7 +58,7 @@ object ZStreamGen extends GenZIO { else Chunk.empty } - def splitChunks[A](chunks: Chunk[Chunk[A]]): Gen[Sized, Chunk[Chunk[A]]] = { + def splitChunks[A](chunks: Chunk[Chunk[A]]): Gen[Any, Chunk[Chunk[A]]] = { def split(chunks: Chunk[Chunk[A]]): Gen[Any, Chunk[Chunk[A]]] = for { diff --git a/test-magnolia-tests/shared/src/test/scala/zio/test/magnolia/DeriveGenSpec.scala b/test-magnolia-tests/shared/src/test/scala/zio/test/magnolia/DeriveGenSpec.scala index 5afc6d80e202..fac6e9d4f2f9 100644 --- a/test-magnolia-tests/shared/src/test/scala/zio/test/magnolia/DeriveGenSpec.scala +++ b/test-magnolia-tests/shared/src/test/scala/zio/test/magnolia/DeriveGenSpec.scala @@ -4,7 +4,7 @@ import zio._ import zio.test.Assertion._ import zio.test.GenUtils._ import zio.test.magnolia.DeriveGen._ -import zio.test.{Sized, _} +import zio.test._ import java.time.{Instant, LocalDate, LocalDateTime, LocalTime} import java.util.UUID @@ -13,7 +13,7 @@ object DeriveGenSpec extends ZIOSpecDefault { final case class Person(name: String, age: Int) - val genPerson: Gen[Sized, Person] = DeriveGen[Person] + val genPerson: Gen[Any, Person] = DeriveGen[Person] sealed trait Color @@ -23,7 +23,7 @@ object DeriveGenSpec extends ZIOSpecDefault { case object Blue extends Color } - val genColor: Gen[Sized, Color] = DeriveGen[Color] + val genColor: Gen[Any, Color] = DeriveGen[Color] sealed trait NonEmptyList[+A] { self => def foldLeft[S](s: S)(f: (S, A) => S): S = @@ -42,7 +42,7 @@ object DeriveGenSpec extends ZIOSpecDefault { implicit def deriveGen[A: DeriveGen]: DeriveGen[NonEmptyList[A]] = DeriveGen.gen } - def genNonEmptyList[A](implicit ev: DeriveGen[A]): Gen[Sized, NonEmptyList[A]] = + def genNonEmptyList[A](implicit ev: DeriveGen[A]): Gen[Any, NonEmptyList[A]] = DeriveGen[NonEmptyList[A]] def assertDeriveGen[A: DeriveGen]: TestResult = assertCompletes diff --git a/test-magnolia/shared/src/main/scala-2.12-2.13/zio/test/magnolia/DeriveGen.scala b/test-magnolia/shared/src/main/scala-2.12-2.13/zio/test/magnolia/DeriveGen.scala index ae43de6d9a39..ec42e6de8e45 100644 --- a/test-magnolia/shared/src/main/scala-2.12-2.13/zio/test/magnolia/DeriveGen.scala +++ b/test-magnolia/shared/src/main/scala-2.12-2.13/zio/test/magnolia/DeriveGen.scala @@ -18,7 +18,7 @@ package zio.test.magnolia import magnolia1._ import zio.Chunk -import zio.test.{Gen, Sized} +import zio.test.Gen import java.time.{Instant, LocalDate, LocalDateTime, LocalTime} import java.util.UUID @@ -32,14 +32,14 @@ import java.util.UUID * {{{ * final case class Point(x: Double, y: Double) * - * val genPoint: Gen[Sized, Point] = DeriveGen[Point] + * val genPoint: Gen[Any, Point] = DeriveGen[Point] * * sealed trait Color * case object Red extends Color * case object Green extends Color * case object Blue extends Color * - * val genColor: Gen[Sized, Color] = DeriveGen[Color] + * val genColor: Gen[Any, Color] = DeriveGen[Color] * }}} * * You can derive generators that include your own custom types by providing an @@ -47,7 +47,7 @@ import java.util.UUID * `instance` method. */ trait DeriveGen[A] { - def derive: Gen[Sized, A] + def derive: Gen[Any, A] } object DeriveGen { @@ -55,14 +55,14 @@ object DeriveGen { /** * Derives a generator of `A` values given an implicit `DeriveGen` instance. */ - def apply[A](implicit ev: DeriveGen[A]): Gen[Sized, A] = ev.derive + def apply[A](implicit ev: DeriveGen[A]): Gen[Any, A] = ev.derive /** * Constructs a `DeriveGen` instance given a generator of `A` values. */ - def instance[A](gen: Gen[Sized, A]): DeriveGen[A] = + def instance[A](gen: Gen[Any, A]): DeriveGen[A] = new DeriveGen[A] { - val derive: Gen[Sized, A] = gen + val derive: Gen[Any, A] = gen } implicit val genBoolean: DeriveGen[Boolean] = instance(Gen.boolean) diff --git a/test-magnolia/shared/src/main/scala-3/zio/test/magnolia/DeriveGen.scala b/test-magnolia/shared/src/main/scala-3/zio/test/magnolia/DeriveGen.scala index 2c6ad8e07b0c..9e209f7d3a13 100644 --- a/test-magnolia/shared/src/main/scala-3/zio/test/magnolia/DeriveGen.scala +++ b/test-magnolia/shared/src/main/scala-3/zio/test/magnolia/DeriveGen.scala @@ -23,19 +23,19 @@ import java.util.UUID import scala.compiletime.{erasedValue, summonInline} import scala.deriving._ import zio._ -import zio.test.{Gen, Sized} +import zio.test.Gen trait DeriveGen[A] { - def derive: Gen[Sized, A] + def derive: Gen[Any, A] } object DeriveGen { - def apply[A](using DeriveGen[A]): Gen[Sized, A] = + def apply[A](using DeriveGen[A]): Gen[Any, A] = summon[DeriveGen[A]].derive - inline def instance[A](gen: => Gen[Sized, A]): DeriveGen[A] = + inline def instance[A](gen: => Gen[Any, A]): DeriveGen[A] = new DeriveGen[A] { - val derive: Gen[Sized, A] = gen + val derive: Gen[Any, A] = gen } given DeriveGen[Boolean] = instance(Gen.boolean) @@ -87,7 +87,7 @@ object DeriveGen { inline def gen[T](using m: Mirror.Of[T]): DeriveGen[T] = new DeriveGen[T] { - def derive: Gen[Sized, T] = { + def derive: Gen[Any, T] = { val elemInstances = summonAll[m.MirroredElemTypes] inline m match { case s: Mirror.SumOf[T] => genSum(s, elemInstances) @@ -99,10 +99,10 @@ object DeriveGen { inline given derived[T](using m: Mirror.Of[T]): DeriveGen[T] = gen[T] - def genSum[T](s: Mirror.SumOf[T], instances: => List[DeriveGen[_]]): Gen[Sized, T] = + def genSum[T](s: Mirror.SumOf[T], instances: => List[DeriveGen[_]]): Gen[Any, T] = Gen.suspend(Gen.oneOf(instances.map(_.asInstanceOf[DeriveGen[T]].derive) : _*)) - def genProduct[T](p: Mirror.ProductOf[T], instances: => List[DeriveGen[_]]): Gen[Sized, T] = + def genProduct[T](p: Mirror.ProductOf[T], instances: => List[DeriveGen[_]]): Gen[Any, T] = Gen.suspend( Gen.collectAll(instances.map(_.derive)).map(lst => Tuple.fromArray(lst.toArray)).map(p.fromProduct)) diff --git a/test-refined/shared/src/main/scala/zio/test/refined/BooleanInstances.scala b/test-refined/shared/src/main/scala/zio/test/refined/BooleanInstances.scala index d1082b501889..12b137d44c73 100644 --- a/test-refined/shared/src/main/scala/zio/test/refined/BooleanInstances.scala +++ b/test-refined/shared/src/main/scala/zio/test/refined/BooleanInstances.scala @@ -19,7 +19,7 @@ package zio.test.refined import eu.timepit.refined.api.Refined import eu.timepit.refined.boolean.Or import zio.test.magnolia.DeriveGen -import zio.test.{Gen, Sized} +import zio.test.Gen import zio.Random object boolean extends BooleanInstances @@ -29,10 +29,10 @@ trait BooleanInstances { raGen: DeriveGen[Refined[T, A]], rbGen: DeriveGen[Refined[T, B]] ): DeriveGen[Refined[T, A Or B]] = { - val genA: Gen[Sized, T] = raGen.derive.map(_.value) - val genB: Gen[Sized, T] = rbGen.derive.map(_.value) + val genA: Gen[Any, T] = raGen.derive.map(_.value) + val genB: Gen[Any, T] = rbGen.derive.map(_.value) DeriveGen.instance( - Gen.oneOf[Sized, T](genA, genB).map(Refined.unsafeApply) + Gen.oneOf[Any, T](genA, genB).map(Refined.unsafeApply) ) } diff --git a/test-refined/shared/src/main/scala/zio/test/refined/CollectionInstances.scala b/test-refined/shared/src/main/scala/zio/test/refined/CollectionInstances.scala index 33397b3d93e3..e393076d23ae 100644 --- a/test-refined/shared/src/main/scala/zio/test/refined/CollectionInstances.scala +++ b/test-refined/shared/src/main/scala/zio/test/refined/CollectionInstances.scala @@ -20,27 +20,27 @@ import eu.timepit.refined.api.Refined import eu.timepit.refined.collection.{NonEmpty, Size} import zio.test.Gen.{listOfN, vectorOfN} import zio.test.magnolia.DeriveGen -import zio.test.{Gen, Sized} +import zio.test.Gen import zio.{Chunk, NonEmptyChunk} object collection extends CollectionInstances trait CollectionInstances { - def nonEmptyChunkRefinedGen[R <: Sized, T](implicit + def nonEmptyChunkRefinedGen[R, T](implicit genT: Gen[R, T] ): Gen[R, Refined[NonEmptyChunk[T], NonEmpty]] = Gen.chunkOf1(genT).map(Refined.unsafeApply) - def nonEmptyListRefinedGen[R <: Sized, T](implicit + def nonEmptyListRefinedGen[R, T](implicit genT: Gen[R, T] ): Gen[R, Refined[List[T], NonEmpty]] = Gen.listOf1(genT).map(Refined.unsafeApply) - def nonEmptyVectorRefinedGen[R <: Sized, T](implicit + def nonEmptyVectorRefinedGen[R, T](implicit genT: Gen[R, T] ): Gen[R, Refined[Vector[T], NonEmpty]] = Gen.vectorOf1(genT).map(Refined.unsafeApply) - def sizedChunkRefinedGen[R <: Sized, T, P](implicit + def sizedChunkRefinedGen[R, T, P](implicit genT: Gen[R, T], sizeGen: Gen[R, Int Refined P] ): Gen[R, Refined[Chunk[T], Size[P]]] = @@ -48,7 +48,7 @@ trait CollectionInstances { Gen.chunkOfN(n.value)(genT) }.map(r => Refined.unsafeApply(r)) - def listSizeRefinedGen[R <: Sized, T, P](implicit + def listSizeRefinedGen[R, T, P](implicit genT: Gen[R, T], sizeGen: Gen[R, Int Refined P] ): Gen[R, Refined[List[T], Size[P]]] = @@ -56,7 +56,7 @@ trait CollectionInstances { listOfN(n.value)(genT) }.map(Refined.unsafeApply) - def vectorSizeRefinedGen[R <: Sized, T, P](implicit + def vectorSizeRefinedGen[R, T, P](implicit genT: Gen[R, T], sizeGen: Gen[R, Int Refined P] ): Gen[R, Refined[Vector[T], Size[P]]] = sizeGen.flatMap { n => diff --git a/test-refined/shared/src/main/scala/zio/test/refined/GenericInstances.scala b/test-refined/shared/src/main/scala/zio/test/refined/GenericInstances.scala index 787cb6e1ddc8..f8065205256a 100644 --- a/test-refined/shared/src/main/scala/zio/test/refined/GenericInstances.scala +++ b/test-refined/shared/src/main/scala/zio/test/refined/GenericInstances.scala @@ -20,7 +20,7 @@ import eu.timepit.refined.api.Refined import eu.timepit.refined.generic.Equal import shapeless.Witness import zio.test.magnolia.DeriveGen -import zio.test.{Gen, Sized} +import zio.test.Gen object generic extends GenericInstances @@ -28,7 +28,7 @@ trait GenericInstances { def equalArbitraryGen[T, U <: T](implicit wu: Witness.Aux[U] - ): Gen[Sized, Refined[T, Equal[U]]] = + ): Gen[Any, Refined[T, Equal[U]]] = Gen.const(wu.value).map(Refined.unsafeApply) implicit def equalArbitrary[T, U <: T](implicit diff --git a/test-refined/shared/src/main/scala/zio/test/refined/StringInstances.scala b/test-refined/shared/src/main/scala/zio/test/refined/StringInstances.scala index f220fa23e1ec..9851a89fe284 100644 --- a/test-refined/shared/src/main/scala/zio/test/refined/StringInstances.scala +++ b/test-refined/shared/src/main/scala/zio/test/refined/StringInstances.scala @@ -20,41 +20,41 @@ import eu.timepit.refined.api.Refined import eu.timepit.refined.string.{EndsWith, StartsWith, Uuid} import shapeless.Witness import zio.test.magnolia.DeriveGen -import zio.test.{Gen, Sized} +import zio.test.Gen object string extends StringInstances trait StringInstances { - def endsWithStringGen[R <: Sized, S <: String](implicit + def endsWithStringGen[R, S <: String](implicit ws: Witness.Aux[S], charGen: Gen[R, Char] ): Gen[R, Refined[String, EndsWith[S]]] = Gen.string(charGen).map(v => Refined.unsafeApply(v + ws.value)) - def endsWithString1Gen[R <: Sized, S <: String](implicit + def endsWithString1Gen[R, S <: String](implicit ws: Witness.Aux[S], charGen: Gen[R, Char] ): Gen[R, Refined[String, EndsWith[S]]] = Gen.string1(charGen).map(v => Refined.unsafeApply(v + ws.value)) //Only String can call `+` since scala 2.13.0. - def endsWithStringNGen[R <: Sized, S <: String, P](implicit + def endsWithStringNGen[R, S <: String, P](implicit ws: Witness.Aux[S], charGen: Gen[R, Char], sizeGen: Gen[R, Int Refined P] ): Gen[R, Refined[String, EndsWith[S]]] = sizeGen.flatMap(s => Gen.stringN(s.value)(charGen).map(v => Refined.unsafeApply(v + ws.value))) - def startsWithStringGen[R <: Sized, S <: String](implicit + def startsWithStringGen[R, S <: String](implicit ws: Witness.Aux[S], charGen: Gen[R, Char] ): Gen[R, Refined[String, StartsWith[S]]] = Gen.string(charGen).map(v => Refined.unsafeApply(ws.value + v)) - def startsWithString1Gen[R <: Sized, S <: String](implicit + def startsWithString1Gen[R, S <: String](implicit ws: Witness.Aux[S], charGen: Gen[R, Char] ): Gen[R, Refined[String, StartsWith[S]]] = Gen.string1(charGen).map(v => Refined.unsafeApply(ws.value + v)) - def startsWithStringNGen[R <: Sized, S <: String, P](implicit + def startsWithStringNGen[R, S <: String, P](implicit ws: Witness.Aux[S], charGen: Gen[R, Char], sizeGen: Gen[R, Int Refined P] diff --git a/test-refined/shared/src/main/scala/zio/test/refined/types/StringInstance.scala b/test-refined/shared/src/main/scala/zio/test/refined/types/StringInstance.scala index d92cbde338aa..638a7eb75e81 100644 --- a/test-refined/shared/src/main/scala/zio/test/refined/types/StringInstance.scala +++ b/test-refined/shared/src/main/scala/zio/test/refined/types/StringInstance.scala @@ -7,7 +7,7 @@ import eu.timepit.refined.types.string.{FiniteString, HexString, NonEmptyFiniteS import shapeless.Nat._1 import shapeless.Witness import zio.test.magnolia.DeriveGen -import zio.test.{Gen, Sized} +import zio.test.Gen object string extends StringInstance @@ -22,13 +22,13 @@ trait StringInstance { def finiteStringGen[N <: Int]: FiniteStringPartiallyApplied[N, MaxSize[N]] = new FiniteStringPartiallyApplied[N, MaxSize[N]](0) - def nonEmptyStringGen[R](charGen: Gen[R, Char]): Gen[R with Sized, NonEmptyString] = + def nonEmptyStringGen[R](charGen: Gen[R, Char]): Gen[R, NonEmptyString] = Gen.string1(charGen).map(Refined.unsafeApply) def nonEmptyFiniteStringGen[N <: Int]: FiniteStringPartiallyApplied[N, Size[Interval.Closed[_1, N]]] = new FiniteStringPartiallyApplied[N, Size[Interval.Closed[_1, N]]](1) - def trimmedStringGen[R](charGen: Gen[R, Char]): Gen[R with Sized, TrimmedString] = + def trimmedStringGen[R](charGen: Gen[R, Char]): Gen[R, TrimmedString] = Gen.string(charGen).map(s => Refined.unsafeApply(s.trim)) - def hexStringGen: Gen[Sized, HexString] = + def hexStringGen: Gen[Any, HexString] = Gen.oneOf(Gen.string(Gen.hexCharLower), Gen.string(Gen.hexCharUpper)).map(Refined.unsafeApply) implicit def finiteStringDeriveGen[N <: Int](implicit diff --git a/test-sbt/jvm/src/test/scala/zio/test/sbt/FrameworkSpecInstances.scala b/test-sbt/jvm/src/test/scala/zio/test/sbt/FrameworkSpecInstances.scala index 4c0552520ddb..3fb7c27417ce 100644 --- a/test-sbt/jvm/src/test/scala/zio/test/sbt/FrameworkSpecInstances.scala +++ b/test-sbt/jvm/src/test/scala/zio/test/sbt/FrameworkSpecInstances.scala @@ -120,7 +120,7 @@ object FrameworkSpecInstances { lazy val failingSpecFQN = SimpleFailingSharedSpec.getClass.getName object SimpleFailingSharedSpec extends ZIOSpecDefault { - def spec: Spec[Annotations, TestFailure[Any]] = zio.test.suite("some suite")( + def spec: Spec[Any, TestFailure[Any]] = zio.test.suite("some suite")( test("failing test") { zio.test.assert(1)(Assertion.equalTo(2)) }, diff --git a/test-scalacheck/shared/src/main/scala/zio/test/scalacheck/package.scala b/test-scalacheck/shared/src/main/scala/zio/test/scalacheck/package.scala index 9e46348694d5..7776ca1b217d 100644 --- a/test-scalacheck/shared/src/main/scala/zio/test/scalacheck/package.scala +++ b/test-scalacheck/shared/src/main/scala/zio/test/scalacheck/package.scala @@ -17,7 +17,7 @@ import zio._ * import zio.test._ * import zio.test.scalacheck._ * - * val anyInt: Gen[Sized, Int] = + * val anyInt: Gen[Any, Int] = * Arbitrary.arbitrary[Int].toGenZIO * }}} */ @@ -28,7 +28,7 @@ package object scalacheck { /** * Converts a legacy ScalaCheck `Gen` to a ZIO Test `Gen`. */ - def toGenZIO: Gen[Sized, A] = + def toGenZIO: Gen[Any, A] = Gen.fromZIO { for { long <- Random.nextLong diff --git a/test-tests/shared/src/test/scala/zio/test/AssertionSpec.scala b/test-tests/shared/src/test/scala/zio/test/AssertionSpec.scala index e2cbc42d56aa..3feb69d29612 100644 --- a/test-tests/shared/src/test/scala/zio/test/AssertionSpec.scala +++ b/test-tests/shared/src/test/scala/zio/test/AssertionSpec.scala @@ -10,7 +10,7 @@ object AssertionSpec extends ZIOBaseSpec { val failing = TestAspect.failing - def spec: Spec[Annotations, TestFailure[Any]] = + def spec: Spec[Any, TestFailure[Any]] = suite("AssertionSpec")( test("and must succeed when both assertions are satisfied") { assert(sampleUser)(nameStartsWithU && ageGreaterThan20) diff --git a/test-tests/shared/src/test/scala/zio/test/GenSpec.scala b/test-tests/shared/src/test/scala/zio/test/GenSpec.scala index b73ce4c7ac92..17456e25a483 100644 --- a/test-tests/shared/src/test/scala/zio/test/GenSpec.scala +++ b/test-tests/shared/src/test/scala/zio/test/GenSpec.scala @@ -690,7 +690,7 @@ object GenSpec extends ZIOBaseSpec { val genPop: Gen[Any, Command] = Gen.const(Pop) def genPush: Gen[Any, Command] = Gen.int.map(value => Push(value)) - val genCommands: Gen[Sized, List[Command]] = + val genCommands: Gen[Any, List[Command]] = Gen.unfoldGen(0) { n => if (n <= 0) genPush.map(command => (n + 1, command)) diff --git a/test-tests/shared/src/test/scala/zio/test/GenUtils.scala b/test-tests/shared/src/test/scala/zio/test/GenUtils.scala index 961ea5bf1552..839e1abe379b 100644 --- a/test-tests/shared/src/test/scala/zio/test/GenUtils.scala +++ b/test-tests/shared/src/test/scala/zio/test/GenUtils.scala @@ -18,15 +18,15 @@ object GenUtils { assertZIO(gen.sample.collectSome.map(_.value).runCollect.map(xs => f(xs.toList)))(assertion) def checkSample[A, B]( - gen: Gen[Sized, A], + gen: Gen[Any, A], size: Int = 100 )(assertion: Assertion[B], f: List[A] => B = (a: List[A]) => a): UIO[TestResult] = assertZIO(provideSize(sample100(gen).map(f))(size))(assertion) - def checkShrink[A](gen: Gen[Sized, A])(a: A): UIO[TestResult] = + def checkShrink[A](gen: Gen[Any, A])(a: A): UIO[TestResult] = provideSize(alwaysShrinksTo(gen)(a: A))(100) - val deterministic: Gen[Sized, Gen[Any, Int]] = + val deterministic: Gen[Any, Gen[Any, Int]] = Gen.listOf1(Gen.int(-10, 10)).map(as => Gen.fromIterable(as)) def equal[A](left: Gen[Any, A], right: Gen[Any, A]): UIO[Boolean] = @@ -64,7 +64,7 @@ object GenUtils { case e @ Failure(_) => Left(e) } - def provideSize[R, A](zio: ZIO[Sized with R, Nothing, A])(n: Int): URIO[R, A] = + def provideSize[R, A](zio: ZIO[R, Nothing, A])(n: Int): URIO[R, A] = zio.provideSomeLayer[R](Sized.live(n)) val random: Gen[Any, Gen[Any, Int]] = @@ -85,7 +85,7 @@ object GenUtils { gen.sample.collectSome.map(_.value).forever.take(100).runCollect.map(_.toList) def sampleEffect[E, A]( - gen: Gen[Sized, ZIO[Sized, E, A]], + gen: Gen[Any, ZIO[Any, E, A]], size: Int = 100 ): ZIO[Any, Nothing, List[Exit[E, A]]] = provideSize(sample100(gen).flatMap(effects => ZIO.foreach(effects)(_.exit)))(size) diff --git a/test-tests/shared/src/test/scala/zio/test/RandomSpec.scala b/test-tests/shared/src/test/scala/zio/test/RandomSpec.scala index 68634f6b5173..f41692b9cc71 100644 --- a/test-tests/shared/src/test/scala/zio/test/RandomSpec.scala +++ b/test-tests/shared/src/test/scala/zio/test/RandomSpec.scala @@ -93,7 +93,7 @@ object RandomSpec extends ZIOBaseSpec { def checkClear[A, B <: Random](generate: SRandom => A)(feed: (ZRandom, List[A]) => UIO[Unit])( clear: ZRandom => UIO[Unit] - )(extract: ZRandom => UIO[A]): URIO[TestConfig, TestResult] = + )(extract: ZRandom => UIO[A]): UIO[TestResult] = check(Gen.long) { seed => for { sRandom <- ZIO.succeed(new SRandom(seed)) @@ -109,7 +109,7 @@ object RandomSpec extends ZIOBaseSpec { def checkFeed[A, B >: Random](generate: SRandom => A)( feed: (ZRandom, List[A]) => UIO[Unit] - )(extract: ZRandom => UIO[A]): URIO[TestConfig, TestResult] = + )(extract: ZRandom => UIO[A]): UIO[TestResult] = check(Gen.long) { seed => for { sRandom <- ZIO.succeed(new SRandom(seed)) @@ -143,7 +143,7 @@ object RandomSpec extends ZIOBaseSpec { def forAllEqual[A]( f: ZRandom => UIO[A] - )(g: SRandom => A): URIO[TestConfig, TestResult] = + )(g: SRandom => A): UIO[TestResult] = check(Gen.long) { seed => for { sRandom <- ZIO.succeed(new SRandom(seed)) @@ -154,7 +154,7 @@ object RandomSpec extends ZIOBaseSpec { } yield assert(actual)(equalTo(expected)) } - def forAllEqualBytes: URIO[TestConfig, TestResult] = + def forAllEqualBytes: UIO[TestResult] = check(Gen.long) { seed => for { sRandom <- ZIO.succeed(new SRandom(seed)) @@ -168,7 +168,7 @@ object RandomSpec extends ZIOBaseSpec { } yield assert(actual)(equalTo(expected)) } - def forAllEqualGaussian: URIO[TestConfig, TestResult] = + def forAllEqualGaussian: UIO[TestResult] = check(Gen.long) { seed => for { sRandom <- ZIO.succeed(new SRandom(seed)) @@ -181,7 +181,7 @@ object RandomSpec extends ZIOBaseSpec { def forAllEqualN[A]( f: (ZRandom, Int) => UIO[A] - )(g: (SRandom, Int) => A): URIO[TestConfig, TestResult] = + )(g: (SRandom, Int) => A): UIO[TestResult] = check(Gen.long, Gen.int(1, 100)) { (seed, size) => for { sRandom <- ZIO.succeed(new SRandom(seed)) @@ -194,7 +194,7 @@ object RandomSpec extends ZIOBaseSpec { def forAllEqualShuffle( f: (ZRandom, List[Int]) => UIO[List[Int]] - )(g: (SRandom, List[Int]) => List[Int]): ZIO[Sized with TestConfig, Nothing, TestResult] = + )(g: (SRandom, List[Int]) => List[Int]): ZIO[Any, Nothing, TestResult] = check(Gen.long, Gen.listOf(Gen.int)) { (seed, testList) => for { sRandom <- ZIO.succeed(new SRandom(seed)) @@ -207,7 +207,7 @@ object RandomSpec extends ZIOBaseSpec { def forAllBounded[A: Numeric](gen: Gen[Any, A])( next: (Random, A) => UIO[A] - ): URIO[TestConfig, TestResult] = { + ): UIO[TestResult] = { val num = implicitly[Numeric[A]] import num._ check(gen.map(num.abs(_))) { upper => @@ -220,7 +220,7 @@ object RandomSpec extends ZIOBaseSpec { def forAllBetween[A: Numeric](gen: Gen[Any, A])( between: (Random, A, A) => UIO[A] - ): URIO[TestConfig, TestResult] = { + ): UIO[TestResult] = { val num = implicitly[Numeric[A]] import num._ val genMinMax = for { diff --git a/test-tests/shared/src/test/scala/zio/test/ScopedSpec.scala b/test-tests/shared/src/test/scala/zio/test/ScopedSpec.scala index eae05356e375..ff7dfad2b4c2 100644 --- a/test-tests/shared/src/test/scala/zio/test/ScopedSpec.scala +++ b/test-tests/shared/src/test/scala/zio/test/ScopedSpec.scala @@ -25,7 +25,7 @@ object ScopedSpec extends ZIOBaseSpec { ZIO.serviceWithZIO(_.incrementAndGet) } - def spec: Spec[Annotations, TestFailure[Any]] = suite("ScopedSpec")( + def spec: Spec[Any, TestFailure[Any]] = suite("ScopedSpec")( suite("scoped shared")( suite("first suite")( test("first test") { diff --git a/test-tests/shared/src/test/scala/zio/test/ShowExpressionSpec.scala b/test-tests/shared/src/test/scala/zio/test/ShowExpressionSpec.scala index db88bb436856..01dd147d1f16 100644 --- a/test-tests/shared/src/test/scala/zio/test/ShowExpressionSpec.scala +++ b/test-tests/shared/src/test/scala/zio/test/ShowExpressionSpec.scala @@ -8,7 +8,7 @@ object ShowExpressionSpec extends ZIOBaseSpec { case class Nested(bar: Int) class SomeClass(val str: String = "") - override def spec: Spec[Annotations, Any] = suite("ShowExprSpec")( + override def spec: Spec[Any, Any] = suite("ShowExprSpec")( test("Some(1)", showExpression(Some(1)), "Some(1)"), test("Some(Right(1))", showExpression(Some(Right(1))), "Some(Right(1))"), test("class member val", showExpression(fooVal), "fooVal"), diff --git a/test-tests/shared/src/test/scala/zio/test/SpecSpec.scala b/test-tests/shared/src/test/scala/zio/test/SpecSpec.scala index 3125a96b61ee..704a365240d3 100644 --- a/test-tests/shared/src/test/scala/zio/test/SpecSpec.scala +++ b/test-tests/shared/src/test/scala/zio/test/SpecSpec.scala @@ -11,14 +11,6 @@ object SpecSpec extends ZIOBaseSpec { ZLayer.succeed(()) def spec: Spec[TestEnvironment, TestFailure[Nothing]] = suite("SpecSpec")( - suite("provideCustomLayer")( - test("provides the part of the environment that is not part of the `TestEnvironment`") { - for { - _ <- ZIO.environment[TestEnvironment] - _ <- ZIO.service[Unit] - } yield assertCompletes - }.provideCustomLayer(specLayer) - ), suite("provideLayer")( test("does not have early initialization issues") { for { @@ -49,7 +41,7 @@ object SpecSpec extends ZIOBaseSpec { for { ref <- Ref.make(true) specLayer = ZLayer.fromZIO(ref.set(false).as(ref)) - _ <- execute(spec.provideCustomLayerShared(specLayer) @@ ifEnvSet("foo")) + _ <- execute(spec.provideLayerShared(specLayer) @@ ifEnvSet("foo")) result <- ref.get } yield assert(result)(isTrue) }, @@ -130,7 +122,7 @@ object SpecSpec extends ZIOBaseSpec { test("test2") { assertZIO(update)(equalTo(2)) } - ).provideCustomLayerShared(specLayer), + ).provideLayerShared(specLayer), suite("suite2")( test("test1") { assertZIO(update)(equalTo(1)) @@ -138,7 +130,7 @@ object SpecSpec extends ZIOBaseSpec { test("test2") { assertZIO(update)(equalTo(2)) } - ).provideCustomLayerShared(specLayer) + ).provideLayerShared(specLayer) ) @@ sequential succeeded <- succeeded(spec) log <- ref.get.map(_.reverse) @@ -159,7 +151,7 @@ object SpecSpec extends ZIOBaseSpec { } ) ) - ).provideCustomLayerShared(ZLayer.scoped[Any](ZIO.acquireRelease(Ref.make(0))(_.set(-1)))) + ).provideLayerShared(ZLayer.scoped[Any](ZIO.acquireRelease(Ref.make(0))(_.set(-1)))) assertZIO(succeeded(spec))(isTrue) } ), diff --git a/test-tests/shared/src/test/scala/zio/test/StreamSpec.scala b/test-tests/shared/src/test/scala/zio/test/StreamSpec.scala index 4848c88037aa..5f8d51854d37 100644 --- a/test-tests/shared/src/test/scala/zio/test/StreamSpec.scala +++ b/test-tests/shared/src/test/scala/zio/test/StreamSpec.scala @@ -146,10 +146,10 @@ object StreamSpec extends ZIOBaseSpec { expected <- runCollectUnordered(100)(right) } yield assert(actual)(equalTo(expected)) - lazy val genIntStreamFunction: Gen[Sized, Int => ZStream[Any, Nothing, Option[Int]]] = + lazy val genIntStreamFunction: Gen[Any, Int => ZStream[Any, Nothing, Option[Int]]] = Gen.function(genStream) - lazy val genStream: Gen[Sized, ZStream[Any, Nothing, Option[Int]]] = + lazy val genStream: Gen[Any, ZStream[Any, Nothing, Option[Int]]] = for { as <- Gen.listOf(Gen.option(Gen.int)) n <- Gen.small(n => Gen.int(1, n), 1) diff --git a/test-tests/shared/src/test/scala/zio/test/TestAspectSpec.scala b/test-tests/shared/src/test/scala/zio/test/TestAspectSpec.scala index 3fbcf118d9a1..2a0543d085dd 100644 --- a/test-tests/shared/src/test/scala/zio/test/TestAspectSpec.scala +++ b/test-tests/shared/src/test/scala/zio/test/TestAspectSpec.scala @@ -249,7 +249,7 @@ object TestAspectSpec extends ZIOBaseSpec { value <- ref.get } yield assert(value)(equalTo(43)) }, - test("repeats sets the number of times to repeat a test to the specified value") { + test("retries sets the number of times to repeat a test to the specified value") { for { ref <- Ref.make(0) spec = test("test")(assertZIO(ref.update(_ + 1))(nothing)) @@ flaky @@ retries(42) @@ -305,9 +305,9 @@ object TestAspectSpec extends ZIOBaseSpec { assert(n)(equalTo(n + 1)) } } @@ shrinks(0) @@ failing, - test("sized sets the size to the specified value") { + test("size sets the size to the specified value") { assertZIO(Sized.size)(equalTo(42)) - } @@ sized(42), + } @@ size(42), test("timeout makes tests fail after given duration") { assertZIO(ZIO.never *> ZIO.unit)(equalTo(())) } @@ timeout(1.nanos) diff --git a/test-tests/shared/src/test/scala/zio/test/poly/PolySpec.scala b/test-tests/shared/src/test/scala/zio/test/poly/PolySpec.scala index 439550cd83ba..401f2fe656d2 100644 --- a/test-tests/shared/src/test/scala/zio/test/poly/PolySpec.scala +++ b/test-tests/shared/src/test/scala/zio/test/poly/PolySpec.scala @@ -23,21 +23,21 @@ object PolySpec extends ZIOSpecDefault { case x => x } - def genValue(t: GenPoly): Gen[Sized, Expr[t.T]] = + def genValue(t: GenPoly): Gen[Any, Expr[t.T]] = t.genT.map(Value(_)) - def genMapping(t: GenPoly): Gen[Sized, Expr[t.T]] = + def genMapping(t: GenPoly): Gen[Any, Expr[t.T]] = Gen.suspend { GenPoly.genPoly.flatMap { t0 => genExpr(t0).flatMap { expr => - val genFunction: Gen[Sized, t0.T => t.T] = Gen.function(t.genT) - val genExpr1: Gen[Sized, Expr[t.T]] = genFunction.map(f => Mapping(expr, f)) + val genFunction: Gen[Any, t0.T => t.T] = Gen.function(t.genT) + val genExpr1: Gen[Any, Expr[t.T]] = genFunction.map(f => Mapping(expr, f)) genExpr1 } } } - def genExpr(t: GenPoly): Gen[Sized, Expr[t.T]] = + def genExpr(t: GenPoly): Gen[Any, Expr[t.T]] = Gen.oneOf(genMapping(t), genValue(t)) def spec = suite("PolySpec")( diff --git a/test/shared/src/main/scala-2/zio/test/SpecVersionSpecific.scala b/test/shared/src/main/scala-2/zio/test/SpecVersionSpecific.scala index 2a30839c1803..f43d12130f7a 100644 --- a/test/shared/src/main/scala-2/zio/test/SpecVersionSpecific.scala +++ b/test/shared/src/main/scala-2/zio/test/SpecVersionSpecific.scala @@ -31,6 +31,7 @@ private[test] trait SpecVersionSpecific[-R, +E] { self: Spec[R, E] => * spec.provideCustom(userRepoLayer, databaseLayer) * }}} */ + @deprecated("use provide", "2.0.2") def provideCustom[E1 >: E](layer: ZLayer[_, E1, _]*): ZSpec[TestEnvironment, E1, TestSuccess] = macro LayerMacros.provideCustomImpl[ZSpec, TestEnvironment, R, E1, TestSuccess] @@ -74,6 +75,7 @@ private[test] trait SpecVersionSpecific[-R, +E] { self: Spec[R, E] => * spec.provideCustomShared(userRepoLayer, databaseLayer) * }}} */ + @deprecated("use provideShared", "2.0.2") def provideCustomShared[E1 >: E](layer: ZLayer[_, E1, _]*): Spec[TestEnvironment, E1] = macro SpecLayerMacros.provideCustomSharedImpl[R, E1] diff --git a/test/shared/src/main/scala-3/zio/test/SpecVersionSpecific.scala b/test/shared/src/main/scala-3/zio/test/SpecVersionSpecific.scala index 6770921e02a5..b712a4563738 100644 --- a/test/shared/src/main/scala-3/zio/test/SpecVersionSpecific.scala +++ b/test/shared/src/main/scala-3/zio/test/SpecVersionSpecific.scala @@ -34,6 +34,7 @@ trait SpecVersionSpecific[-R, +E] { self: Spec[R, E] => * zio.provideCustom(oldLadyLayer, flyLayer) * }}} */ + @deprecated("use provide", "2.0.2") inline def provideCustom[E1 >: E](inline layer: ZLayer[_, E1, _]*): Spec[TestEnvironment, E1] = ${SpecLayerMacros.provideImpl[TestEnvironment, R, E1]('self, 'layer)} @@ -63,6 +64,7 @@ trait SpecVersionSpecific[-R, +E] { self: Spec[R, E] => * zio.provideCustom(oldLadyLayer, flyLayer) * }}} */ + @deprecated("use provideShared", "2.0.2") inline def provideCustomShared[E1 >: E](inline layer: ZLayer[_, E1, _]*): Spec[TestEnvironment, E1] = ${SpecLayerMacros.provideSharedImpl[TestEnvironment, R, E1]('self, 'layer)} } diff --git a/test/shared/src/main/scala/zio/test/Annotations.scala b/test/shared/src/main/scala/zio/test/Annotations.scala index 68f8376a33f9..0b52201b69f1 100644 --- a/test/shared/src/main/scala/zio/test/Annotations.scala +++ b/test/shared/src/main/scala/zio/test/Annotations.scala @@ -25,58 +25,64 @@ trait Annotations extends Serializable { object Annotations { + val tag: Tag[Annotations] = Tag[Annotations] + + final case class Test(fiberRef: FiberRef[TestAnnotationMap]) extends Annotations { + def annotate[V](key: TestAnnotation[V], value: V)(implicit trace: Trace): UIO[Unit] = + fiberRef.update(_.annotate(key, value)) + def get[V](key: TestAnnotation[V])(implicit trace: Trace): UIO[V] = + fiberRef.get.map(_.get(key)) + def withAnnotation[R, E](zio: ZIO[R, TestFailure[E], TestSuccess])(implicit + trace: Trace + ): ZIO[R, TestFailure[E], TestSuccess] = + fiberRef.locally(TestAnnotationMap.empty) { + zio.foldZIO(e => fiberRef.get.map(e.annotated).flip, a => fiberRef.get.map(a.annotated)) + } + def supervisedFibers(implicit trace: Trace): UIO[SortedSet[Fiber.Runtime[Any, Any]]] = + ZIO.descriptorWith { descriptor => + get(TestAnnotation.fibers).flatMap { + case Left(_) => ZIO.succeedNow(SortedSet.empty[Fiber.Runtime[Any, Any]]) + case Right(refs) => + ZIO + .foreach(refs)(ref => ZIO.succeed(ref.get)) + .map(_.foldLeft(SortedSet.empty[Fiber.Runtime[Any, Any]])(_ ++ _)) + .map(_.filter(_.id != descriptor.id)) + } + } + } + /** * Accesses an `Annotations` instance in the environment and appends the * specified annotation to the annotation map. */ - def annotate[V](key: TestAnnotation[V], value: V)(implicit trace: Trace): URIO[Annotations, Unit] = - ZIO.serviceWithZIO(_.annotate(key, value)) + def annotate[V](key: TestAnnotation[V], value: V)(implicit trace: Trace): UIO[Unit] = + annotationsWith(_.annotate(key, value)) /** * Accesses an `Annotations` instance in the environment and retrieves the * annotation of the specified type, or its default value if there is none. */ - def get[V](key: TestAnnotation[V])(implicit trace: Trace): URIO[Annotations, V] = - ZIO.serviceWithZIO(_.get(key)) + def get[V](key: TestAnnotation[V])(implicit trace: Trace): UIO[V] = + annotationsWith(_.get(key)) /** * Returns a set of all fibers in this test. */ - def supervisedFibers(implicit - trace: Trace - ): ZIO[Annotations, Nothing, SortedSet[Fiber.Runtime[Any, Any]]] = - ZIO.serviceWithZIO(_.supervisedFibers) + def supervisedFibers(implicit trace: Trace): UIO[SortedSet[Fiber.Runtime[Any, Any]]] = + annotationsWith(_.supervisedFibers) /** * Constructs a new `Annotations` service. */ val live: ULayer[Annotations] = { implicit val trace = Tracer.newTrace - ZLayer.scoped(FiberRef.make(TestAnnotationMap.empty).map { fiberRef => - new Annotations { - def annotate[V](key: TestAnnotation[V], value: V)(implicit trace: Trace): UIO[Unit] = - fiberRef.update(_.annotate(key, value)) - def get[V](key: TestAnnotation[V])(implicit trace: Trace): UIO[V] = - fiberRef.get.map(_.get(key)) - def withAnnotation[R, E](zio: ZIO[R, TestFailure[E], TestSuccess])(implicit - trace: Trace - ): ZIO[R, TestFailure[E], TestSuccess] = - fiberRef.locally(TestAnnotationMap.empty) { - zio.foldZIO(e => fiberRef.get.map(e.annotated).flip, a => fiberRef.get.map(a.annotated)) - } - def supervisedFibers(implicit trace: Trace): UIO[SortedSet[Fiber.Runtime[Any, Any]]] = - ZIO.descriptorWith { descriptor => - get(TestAnnotation.fibers).flatMap { - case Left(_) => ZIO.succeedNow(SortedSet.empty[Fiber.Runtime[Any, Any]]) - case Right(refs) => - ZIO - .foreach(refs)(ref => ZIO.succeed(ref.get)) - .map(_.foldLeft(SortedSet.empty[Fiber.Runtime[Any, Any]])(_ ++ _)) - .map(_.filter(_.id != descriptor.id)) - } - } - } - }) + ZLayer.scoped { + for { + fiberRef <- FiberRef.make(TestAnnotationMap.empty) + annotations = Test(fiberRef) + _ <- withAnnotationsScoped(annotations) + } yield annotations + } } /** @@ -84,8 +90,8 @@ object Annotations { * specified effect with an empty annotation map, returning the annotation map * along with the result of execution. */ - def withAnnotation[R <: Annotations, E](zio: ZIO[R, TestFailure[E], TestSuccess])(implicit + def withAnnotation[R, E](zio: ZIO[R, TestFailure[E], TestSuccess])(implicit trace: Trace ): ZIO[R, TestFailure[E], TestSuccess] = - ZIO.serviceWithZIO[Annotations](_.withAnnotation(zio)) + annotationsWith(_.withAnnotation(zio)) } diff --git a/test/shared/src/main/scala/zio/test/Gen.scala b/test/shared/src/main/scala/zio/test/Gen.scala index cc5466293931..03f1f0ce3985 100644 --- a/test/shared/src/main/scala/zio/test/Gen.scala +++ b/test/shared/src/main/scala/zio/test/Gen.scala @@ -125,7 +125,7 @@ final case class Gen[-R, +A](sample: ZStream[R, Nothing, Option[Sample[R, A]]]) /** * Sets the size parameter for this generator to the specified value. */ - def resize(size: Int)(implicit trace: Trace): Gen[R with Sized, A] = + def resize(size: Int)(implicit trace: Trace): Gen[R, A] = Sized.withSizeGen(size)(self) /** @@ -181,7 +181,7 @@ object Gen extends GenZIO with FunctionVariants with TimeVariants { /** * A generator of alphanumeric strings. Shrinks towards the empty string. */ - def alphaNumericString(implicit trace: Trace): Gen[Sized, String] = + def alphaNumericString(implicit trace: Trace): Gen[Any, String] = Gen.string(alphaNumericChar) /** @@ -190,7 +190,7 @@ object Gen extends GenZIO with FunctionVariants with TimeVariants { */ def alphaNumericStringBounded(min: Int, max: Int)(implicit trace: Trace - ): Gen[Sized, String] = + ): Gen[Any, String] = Gen.stringBounded(min, max)(alphaNumericChar) /** @@ -202,7 +202,7 @@ object Gen extends GenZIO with FunctionVariants with TimeVariants { /** * A generator US-ASCII strings. Shrinks towards the empty string. */ - def asciiString(implicit trace: Trace): Gen[Sized, String] = + def asciiString(implicit trace: Trace): Gen[Any, String] = Gen.string(Gen.asciiChar) /** @@ -315,13 +315,13 @@ object Gen extends GenZIO with FunctionVariants with TimeVariants { /** * A sized generator of chunks. */ - def chunkOf[R <: Sized, A](g: Gen[R, A])(implicit trace: Trace): Gen[R, Chunk[A]] = + def chunkOf[R, A](g: Gen[R, A])(implicit trace: Trace): Gen[R, Chunk[A]] = listOf(g).map(Chunk.fromIterable) /** * A sized generator of non-empty chunks. */ - def chunkOf1[R <: Sized, A](g: Gen[R, A])(implicit + def chunkOf1[R, A](g: Gen[R, A])(implicit trace: Trace ): Gen[R, NonEmptyChunk[A]] = listOf1(g).map { case h :: t => NonEmptyChunk.fromIterable(h, t) } @@ -500,22 +500,22 @@ object Gen extends GenZIO with FunctionVariants with TimeVariants { /** * A generator of strings that can be encoded in the ISO-8859-1 character set. */ - def iso_8859_1(implicit trace: Trace): Gen[Sized, String] = + def iso_8859_1(implicit trace: Trace): Gen[Any, String] = chunkOf(byte).map(chunk => new String(chunk.toArray, StandardCharsets.ISO_8859_1)) /** * A sized generator that uses a uniform distribution of size values. A large * number of larger sizes will be generated. */ - def large[R <: Sized, A](f: Int => Gen[R, A], min: Int = 0)(implicit + def large[R, A](f: Int => Gen[R, A], min: Int = 0)(implicit trace: Trace ): Gen[R, A] = size.flatMap(max => int(min, max)).flatMap(f) - def listOf[R <: Sized, A](g: Gen[R, A])(implicit trace: Trace): Gen[R, List[A]] = + def listOf[R, A](g: Gen[R, A])(implicit trace: Trace): Gen[R, List[A]] = small(listOfN(_)(g)) - def listOf1[R <: Sized, A](g: Gen[R, A])(implicit trace: Trace): Gen[R, ::[A]] = + def listOf1[R, A](g: Gen[R, A])(implicit trace: Trace): Gen[R, ::[A]] = for { h <- g t <- small(n => listOfN(n - 1 max 0)(g)) @@ -557,7 +557,7 @@ object Gen extends GenZIO with FunctionVariants with TimeVariants { /** * A sized generator of maps. */ - def mapOf[R <: Sized, A, B](key: Gen[R, A], value: Gen[R, B])(implicit + def mapOf[R, A, B](key: Gen[R, A], value: Gen[R, B])(implicit trace: Trace ): Gen[R, Map[A, B]] = small(mapOfN(_)(key, value)) @@ -565,7 +565,7 @@ object Gen extends GenZIO with FunctionVariants with TimeVariants { /** * A sized generator of non-empty maps. */ - def mapOf1[R <: Sized, A, B](key: Gen[R, A], value: Gen[R, B])(implicit + def mapOf1[R, A, B](key: Gen[R, A], value: Gen[R, B])(implicit trace: Trace ): Gen[R, Map[A, B]] = small(mapOfN(_)(key, value), 1) @@ -591,7 +591,7 @@ object Gen extends GenZIO with FunctionVariants with TimeVariants { * majority of sizes will be towards the lower end of the range but some * larger sizes will be generated as well. */ - def medium[R <: Sized, A](f: Int => Gen[R, A], min: Int = 0)(implicit + def medium[R, A](f: Int => Gen[R, A], min: Int = 0)(implicit trace: Trace ): Gen[R, A] = { val gen = for { @@ -655,13 +655,13 @@ object Gen extends GenZIO with FunctionVariants with TimeVariants { /** * A sized generator of sets. */ - def setOf[R <: Sized, A](gen: Gen[R, A])(implicit trace: Trace): Gen[R, Set[A]] = + def setOf[R, A](gen: Gen[R, A])(implicit trace: Trace): Gen[R, Set[A]] = small(setOfN(_)(gen)) /** * A sized generator of non-empty sets. */ - def setOf1[R <: Sized, A](gen: Gen[R, A])(implicit trace: Trace): Gen[R, Set[A]] = + def setOf1[R, A](gen: Gen[R, A])(implicit trace: Trace): Gen[R, Set[A]] = small(setOfN(_)(gen), 1) /** @@ -700,13 +700,13 @@ object Gen extends GenZIO with FunctionVariants with TimeVariants { def short(min: Short, max: Short)(implicit trace: Trace): Gen[Any, Short] = int(min.toInt, max.toInt).map(_.toShort) - def size(implicit trace: Trace): Gen[Sized, Int] = + def size(implicit trace: Trace): Gen[Any, Int] = Gen.fromZIO(Sized.size) /** * A sized generator, whose size falls within the specified bounds. */ - def sized[R <: Sized, A](f: Int => Gen[R, A])(implicit trace: Trace): Gen[R, A] = + def sized[R, A](f: Int => Gen[R, A])(implicit trace: Trace): Gen[R, A] = size.flatMap(f) /** @@ -714,7 +714,7 @@ object Gen extends GenZIO with FunctionVariants with TimeVariants { * values generated will be strongly concentrated towards the lower end of the * range but a few larger values will still be generated. */ - def small[R <: Sized, A](f: Int => Gen[R, A], min: Int = 0)(implicit + def small[R, A](f: Int => Gen[R, A], min: Int = 0)(implicit trace: Trace ): Gen[R, A] = { val gen = for { @@ -730,13 +730,13 @@ object Gen extends GenZIO with FunctionVariants with TimeVariants { /** * A generator of strings. Shrinks towards the empty string. */ - def string(implicit trace: Trace): Gen[Sized, String] = + def string(implicit trace: Trace): Gen[Any, String] = Gen.string(Gen.unicodeChar) - def string[R <: Sized](char: Gen[R, Char])(implicit trace: Trace): Gen[R, String] = + def string[R](char: Gen[R, Char])(implicit trace: Trace): Gen[R, String] = listOf(char).map(_.mkString) - def string1[R <: Sized](char: Gen[R, Char])(implicit trace: Trace): Gen[R, String] = + def string1[R](char: Gen[R, Char])(implicit trace: Trace): Gen[R, String] = listOf1(char).map(_.mkString) /** @@ -767,7 +767,7 @@ object Gen extends GenZIO with FunctionVariants with TimeVariants { * A sized generator of collections, where each collection is generated by * repeatedly applying a function to an initial state. */ - def unfoldGen[R <: Sized, S, A](s: S)(f: S => Gen[R, (S, A)])(implicit + def unfoldGen[R, S, A](s: S)(f: S => Gen[R, (S, A)])(implicit trace: Trace ): Gen[R, List[A]] = small(unfoldGenN(_)(s)(f)) @@ -809,10 +809,10 @@ object Gen extends GenZIO with FunctionVariants with TimeVariants { def uuid(implicit trace: Trace): Gen[Any, UUID] = Gen.fromZIO(nextUUID) - def vectorOf[R <: Sized, A](g: Gen[R, A])(implicit trace: Trace): Gen[R, Vector[A]] = + def vectorOf[R, A](g: Gen[R, A])(implicit trace: Trace): Gen[R, Vector[A]] = listOf(g).map(_.toVector) - def vectorOf1[R <: Sized, A](g: Gen[R, A])(implicit trace: Trace): Gen[R, Vector[A]] = + def vectorOf1[R, A](g: Gen[R, A])(implicit trace: Trace): Gen[R, Vector[A]] = listOf1(g).map(_.toVector) /** diff --git a/test/shared/src/main/scala/zio/test/GenZIO.scala b/test/shared/src/main/scala/zio/test/GenZIO.scala index 90c17315e5dd..af051f1b91b7 100644 --- a/test/shared/src/main/scala/zio/test/GenZIO.scala +++ b/test/shared/src/main/scala/zio/test/GenZIO.scala @@ -24,7 +24,7 @@ trait GenZIO { /** * A generator of `Cause` values */ - final def causes[R <: Sized, E](e: Gen[R, E], t: Gen[R, Throwable])(implicit + final def causes[R, E](e: Gen[R, E], t: Gen[R, Throwable])(implicit trace: Trace ): Gen[R, Cause[E]] = { val fiberId = (Gen.int zip Gen.int zip Gen.const(Trace.empty)).map { case (a, b, c) => FiberId(a, b, c) } @@ -65,7 +65,7 @@ trait GenZIO { * A generator of effects that are the result of chaining the specified effect * with itself a random number of times. */ - final def chained[R <: Sized, Env, E, A](gen: Gen[R, ZIO[Env, E, A]])(implicit + final def chained[R, Env, E, A](gen: Gen[R, ZIO[Env, E, A]])(implicit trace: Trace ): Gen[R, ZIO[Env, E, A]] = Gen.small(chainedN(_)(gen)) diff --git a/test/shared/src/main/scala/zio/test/Live.scala b/test/shared/src/main/scala/zio/test/Live.scala index f3ddbbe8c66e..eb08293b6f27 100644 --- a/test/shared/src/main/scala/zio/test/Live.scala +++ b/test/shared/src/main/scala/zio/test/Live.scala @@ -32,6 +32,13 @@ trait Live { object Live { + val tag: Tag[Live] = Tag[Live] + + final case class Test(zenv: ZEnvironment[Clock with Console with System with Random]) extends Live { + def provide[R, E, A](zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = + DefaultServices.currentServices.locallyWith(_.unionAll(zenv))(zio) + } + /** * Constructs a new `Live` service that implements the `Live` interface. This * typically should not be necessary as the `TestEnvironment` already includes @@ -40,28 +47,26 @@ object Live { */ val default: ZLayer[Clock with Console with System with Random, Nothing, Live] = { implicit val trace = Tracer.newTrace - ZLayer { - ZIO - .environmentWith[Clock with Console with System with Random] { zenv => - new Live { - def provide[R, E, A](zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = - DefaultServices.currentServices.locallyWith(_.unionAll(zenv))(zio) - } - } + ZLayer.scoped { + for { + zenv <- ZIO.environment[Clock with Console with System with Random] + live = Test(zenv) + _ <- withLiveScoped(live) + } yield live } } /** * Provides a workflow with the "live" default ZIO services. */ - def live[R <: Live, E, A](zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R with Live, E, A] = - ZIO.serviceWithZIO[Live](_.provide(zio)) + def live[R, E, A](zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = + liveWith(_.provide(zio)) /** * Runs a transformation function with the live default ZIO services while * ensuring that the workflow itself is run with the test services. */ - def withLive[R <: Live, E, E1, A, B]( + def withLive[R, E, E1, A, B]( zio: ZIO[R, E, A] )(f: ZIO[R, E, A] => ZIO[R, E1, B])(implicit trace: Trace): ZIO[R, E1, B] = DefaultServices.currentServices.getWith(services => live(f(DefaultServices.currentServices.locally(services)(zio)))) diff --git a/test/shared/src/main/scala/zio/test/Sized.scala b/test/shared/src/main/scala/zio/test/Sized.scala index 5fac98e56706..dce25a24dee9 100644 --- a/test/shared/src/main/scala/zio/test/Sized.scala +++ b/test/shared/src/main/scala/zio/test/Sized.scala @@ -1,6 +1,6 @@ package zio.test -import zio.{Layer, FiberRef, UIO, URIO, ZIO, ZLayer, Trace} +import zio._ import zio.stream.ZStream import zio.stacktracer.TracingImplicits.disableAutoTrace @@ -12,33 +12,44 @@ trait Sized extends Serializable { object Sized { + val tag: Tag[Sized] = Tag[Sized] + + final case class Test(fiberRef: FiberRef[Int]) extends Sized { + def size(implicit trace: Trace): UIO[Int] = + fiberRef.get + def withSize[R, E, A](size: Int)(zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = + fiberRef.locally(size)(zio) + def withSizeGen[R, A](size: Int)(gen: Gen[R, A])(implicit trace: Trace): Gen[R, A] = + Gen { + ZStream + .fromZIO(fiberRef.get) + .flatMap { oldSize => + ZStream.scoped(fiberRef.locallyScoped(size)) *> gen.sample.mapZIO(a => fiberRef.set(oldSize).as(a)) + } + } + } + val default: ZLayer[Any, Nothing, Sized] = live(100)(Trace.empty) def live(size: Int)(implicit trace: Trace): Layer[Nothing, Sized] = - ZLayer.scoped(FiberRef.make(size).map { fiberRef => - new Sized { - def size(implicit trace: Trace): UIO[Int] = - fiberRef.get - def withSize[R, E, A](size: Int)(zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = - fiberRef.locally(size)(zio) - def withSizeGen[R, A](size: Int)(gen: Gen[R, A])(implicit trace: Trace): Gen[R, A] = - Gen { - ZStream - .fromZIO(fiberRef.get) - .flatMap { oldSize => - ZStream.scoped(fiberRef.locallyScoped(size)) *> gen.sample.mapZIO(a => fiberRef.set(oldSize).as(a)) - } - } - } - }) + ZLayer.scoped { + for { + fiberRef <- FiberRef.make(size) + sized = Test(fiberRef) + _ <- withSizedScoped(sized) + } yield sized + } + + private[test] val initial: Sized = + Test(FiberRef.unsafe.make(100)(Unsafe.unsafe)) - def size(implicit trace: Trace): URIO[Sized, Int] = - ZIO.serviceWithZIO(_.size) + def size(implicit trace: Trace): UIO[Int] = + sizedWith(_.size) - def withSize[R <: Sized, E, A](size: Int)(zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = - ZIO.serviceWithZIO[Sized](_.withSize(size)(zio)) + def withSize[R, E, A](size: Int)(zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = + sizedWith(_.withSize(size)(zio)) - def withSizeGen[R <: Sized, A](size: Int)(gen: Gen[R, A])(implicit trace: Trace): Gen[R, A] = - Gen.fromZIO(ZIO.service[Sized]).flatMap(_.withSizeGen(size)(gen)) + def withSizeGen[R, A](size: Int)(gen: Gen[R, A])(implicit trace: Trace): Gen[R, A] = + Gen.fromZIO(sized).flatMap(_.withSizeGen(size)(gen)) } diff --git a/test/shared/src/main/scala/zio/test/Spec.scala b/test/shared/src/main/scala/zio/test/Spec.scala index 4816ab7677cd..cc35ebe8bb2a 100644 --- a/test/shared/src/main/scala/zio/test/Spec.scala +++ b/test/shared/src/main/scala/zio/test/Spec.scala @@ -62,12 +62,12 @@ final case class Spec[-R, +E](caseValue: SpecCase[R, E, Spec[R, E]]) extends Spe /** * Returns a new spec with the annotation map at each node. */ - final def annotated(implicit trace: Trace): Spec[R with Annotations, E] = - transform[R with Annotations, E] { + final def annotated(implicit trace: Trace): Spec[R, E] = + transform[R, E] { case ExecCase(exec, spec) => ExecCase(exec, spec) case LabeledCase(label, spec) => LabeledCase(label, spec) case ScopedCase(scoped) => - ScopedCase[R with Annotations, E, Spec[R with Annotations, E]]( + ScopedCase[R, E, Spec[R, E]]( scoped ) case MultipleCase(specs) => MultipleCase(specs) @@ -263,6 +263,7 @@ final case class Spec[-R, +E](caseValue: SpecCase[R, E, Spec[R, E]]) extends Spe * val spec2 = spec.provideCustomLayer(loggingLayer) * }}} */ + @deprecated("use provideLayer", "2.0.2") def provideCustomLayer[E1 >: E, R1](layer: ZLayer[TestEnvironment, E1, R1])(implicit ev: TestEnvironment with R1 <:< R, tagged: EnvironmentTag[R1], @@ -283,6 +284,7 @@ final case class Spec[-R, +E](caseValue: SpecCase[R, E, Spec[R, E]]) extends Spe * val spec2 = spec.provideCustomLayerShared(loggingLayer) * }}} */ + @deprecated("use provideLayerShared", "2.0.2") def provideCustomLayerShared[E1 >: E, R1](layer: ZLayer[TestEnvironment, E1, R1])(implicit ev: TestEnvironment with R1 <:< R, tagged: EnvironmentTag[R1], @@ -416,7 +418,7 @@ final case class Spec[-R, +E](caseValue: SpecCase[R, E, Spec[R, E]]) extends Spe */ final def when( b: => Boolean - )(implicit trace: Trace): Spec[R with Annotations, E] = + )(implicit trace: Trace): Spec[R, E] = whenZIO(ZIO.succeedNow(b)) /** @@ -424,14 +426,14 @@ final case class Spec[-R, +E](caseValue: SpecCase[R, E, Spec[R, E]]) extends Spe */ final def whenZIO[R1 <: R, E1 >: E]( b: ZIO[R1, E1, Boolean] - )(implicit trace: Trace): Spec[R1 with Annotations, E1] = + )(implicit trace: Trace): Spec[R1, E1] = caseValue match { case ExecCase(exec, spec) => Spec.exec(exec, spec.whenZIO(b)) case LabeledCase(label, spec) => Spec.labeled(label, spec.whenZIO(b)) case ScopedCase(scoped) => - Spec.scoped[R1 with Annotations]( + Spec.scoped[R1]( b.mapError(TestFailure.fail).flatMap { b => if (b) scoped else ZIO.succeedNow(Spec.empty) diff --git a/test/shared/src/main/scala/zio/test/TestAspect.scala b/test/shared/src/main/scala/zio/test/TestAspect.scala index dde64b0b0b2b..66accd9b0906 100644 --- a/test/shared/src/main/scala/zio/test/TestAspect.scala +++ b/test/shared/src/main/scala/zio/test/TestAspect.scala @@ -93,9 +93,9 @@ object TestAspect extends TimeoutVariants { /** * An aspect that marks tests as ignored. */ - val ignore: TestAspectAtLeastR[Annotations] = - new TestAspectAtLeastR[Annotations] { - def some[R <: Annotations, E](spec: Spec[R, E])(implicit trace: Trace): Spec[R, E] = + val ignore: TestAspectPoly = + new TestAspectPoly { + def some[R, E](spec: Spec[R, E])(implicit trace: Trace): Spec[R, E] = spec.when(false) } @@ -219,12 +219,12 @@ object TestAspect extends TimeoutVariants { * An aspect that runs each test on a separate fiber and prints a fiber dump * if the test fails or has not terminated within the specified duration. */ - def diagnose(duration: Duration): TestAspectAtLeastR[Live with Annotations] = - new TestAspectAtLeastR[Live with Annotations] { - def some[R <: Live with Annotations, E]( + def diagnose(duration: Duration): TestAspectPoly = + new TestAspectPoly { + def some[R, E]( spec: Spec[R, E] )(implicit trace: Trace): Spec[R, E] = { - def diagnose[R <: Live with Annotations, E]( + def diagnose[R, E]( label: String, test: ZIO[R, TestFailure[E], TestSuccess] ): ZIO[R, TestFailure[E], TestSuccess] = @@ -235,7 +235,7 @@ object TestAspect extends TimeoutVariants { ) } - def dump[E, A](label: String): URIO[Live with Annotations, Unit] = + def dump[E, A](label: String): UIO[Unit] = Annotations.supervisedFibers.flatMap { fibers => Live.live(ZIO.foreachDiscard(fibers) { fiber => for { @@ -282,49 +282,49 @@ object TestAspect extends TimeoutVariants { /** * An aspect that runs tests on all platforms except ScalaJS. */ - val exceptJS: TestAspectAtLeastR[Annotations] = + val exceptJS: TestAspectPoly = if (TestPlatform.isJS) ignore else identity /** * An aspect that runs tests on all platforms except the JVM. */ - val exceptJVM: TestAspectAtLeastR[Annotations] = + val exceptJVM: TestAspectPoly = if (TestPlatform.isJVM) ignore else identity /** * An aspect that runs tests on all platforms except ScalaNative. */ - val exceptNative: TestAspectAtLeastR[Annotations] = + val exceptNative: TestAspectPoly = if (TestPlatform.isNative) ignore else identity /** * An aspect that runs tests on all versions except Scala 2. */ - val exceptScala2: TestAspectAtLeastR[Annotations] = + val exceptScala2: TestAspectPoly = if (TestVersion.isScala2) ignore else identity /** * An aspect that runs tests on all versions except Scala 2.11. */ - val exceptScala211: TestAspectAtLeastR[Annotations] = + val exceptScala211: TestAspectPoly = if (TestVersion.isScala211) ignore else identity /** * An aspect that runs tests on all versions except Scala 2.12. */ - val exceptScala212: TestAspectAtLeastR[Annotations] = + val exceptScala212: TestAspectPoly = if (TestVersion.isScala212) ignore else identity /** * An aspect that runs tests on all versions except Scala 2.13. */ - val exceptScala213: TestAspectAtLeastR[Annotations] = + val exceptScala213: TestAspectPoly = if (TestVersion.isScala213) ignore else identity /** * An aspect that runs tests on all versions except Scala 3. */ - val exceptScala3: TestAspectAtLeastR[Annotations] = + val exceptScala3: TestAspectPoly = if (TestVersion.isScala3) ignore else identity /** @@ -367,9 +367,9 @@ object TestAspect extends TimeoutVariants { * [[TestAnnotation.fibers]]. Applied by default in [[ZIOSpecAbstract]]. This * aspect is required for the proper functioning * of `TestClock.adjust`. */ - lazy val fibers: TestAspect[Nothing, Annotations, Nothing, Any] = - new TestAspect.PerTest[Nothing, Annotations, Nothing, Any] { - def perTest[R <: Annotations, E]( + lazy val fibers: TestAspectPoly = + new PerTest.Poly { + def perTest[R, E]( test: ZIO[R, TestFailure[E], TestSuccess] )(implicit trace: Trace): ZIO[R, TestFailure[E], TestSuccess] = { val acquire = ZIO.succeed(new AtomicReference(SortedSet.empty[Fiber.Runtime[Any, Any]])).tap { ref => @@ -395,9 +395,9 @@ object TestAspect extends TimeoutVariants { * An aspect that retries a test until success, with a default limit, for use * with flaky tests. */ - val flaky: TestAspectAtLeastR[Annotations with TestConfig] = { - val flaky = new PerTest.AtLeastR[Annotations with TestConfig] { - def perTest[R <: Annotations with TestConfig, E]( + val flaky: TestAspectPoly = { + val flaky = new PerTest.Poly { + def perTest[R, E]( test: ZIO[R, TestFailure[E], TestSuccess] )(implicit trace: Trace): ZIO[R, TestFailure[E], TestSuccess] = TestConfig.retries.flatMap { n => @@ -411,9 +411,9 @@ object TestAspect extends TimeoutVariants { * An aspect that retries a test until success, with the specified limit, for * use with flaky tests. */ - def flaky(n: Int): TestAspectAtLeastR[Annotations] = { - val flaky = new PerTest.AtLeastR[Annotations] { - def perTest[R <: Annotations, E]( + def flaky(n: Int): TestAspectPoly = { + val flaky = new PerTest.Poly { + def perTest[R, E]( test: ZIO[R, TestFailure[E], TestSuccess] )(implicit trace: Trace): ZIO[R, TestFailure[E], TestSuccess] = test.catchAll(_ => test.tapError(_ => Annotations.annotate(TestAnnotation.retried, 1)).retryN(n - 1)) @@ -463,23 +463,23 @@ object TestAspect extends TimeoutVariants { * An aspect that only runs a test if the specified environment variable * satisfies the specified assertion. */ - def ifEnv(env: String)(assertion: String => Boolean): TestAspectAtLeastR[Live with Annotations] = + def ifEnv(env: String)(assertion: String => Boolean): TestAspectPoly = ifEnvOption(env)(_.fold(false)(assertion)) /** * An aspect that only runs a test if the specified environment variable is * not set. */ - def ifEnvNotSet(env: String): TestAspectAtLeastR[Live with Annotations] = + def ifEnvNotSet(env: String): TestAspectPoly = ifEnvOption(env)(_.isEmpty) /** * An aspect that only runs a test if the specified optional environment * variable satisfies the specified assertion. */ - def ifEnvOption(env: String)(assertion: Option[String] => Boolean): TestAspectAtLeastR[Live with Annotations] = - new TestAspectAtLeastR[Live with Annotations] { - def some[R <: Live with Annotations, E](spec: Spec[R, E])(implicit trace: Trace): Spec[R, E] = + def ifEnvOption(env: String)(assertion: Option[String] => Boolean): TestAspectPoly = + new TestAspectPoly { + def some[R, E](spec: Spec[R, E])(implicit trace: Trace): Spec[R, E] = spec.whenZIO(Live.live(System.env(env)).orDie.map(assertion)) } @@ -487,36 +487,36 @@ object TestAspect extends TimeoutVariants { * An aspect that only runs a test if the specified environment variable is * set. */ - def ifEnvSet(env: String): TestAspectAtLeastR[Live with Annotations] = + def ifEnvSet(env: String): TestAspectPoly = ifEnvOption(env)(_.nonEmpty) /** * An aspect that only runs a test if the specified Java property satisfies * the specified assertion. */ - def ifProp(prop: String)(assertion: String => Boolean): TestAspectAtLeastR[Live with Annotations] = + def ifProp(prop: String)(assertion: String => Boolean): TestAspectPoly = ifPropOption(prop)(_.fold(false)(assertion)) /** * An aspect that only runs a test if the specified Java property is not set. */ - def ifPropNotSet(env: String): TestAspectAtLeastR[Live with Annotations] = + def ifPropNotSet(env: String): TestAspectPoly = ifPropOption(env)(_.isEmpty) /** * An aspect that only runs a test if the specified optional Java property * satisfies the specified assertion. */ - def ifPropOption(prop: String)(assertion: Option[String] => Boolean): TestAspectAtLeastR[Live with Annotations] = - new TestAspectAtLeastR[Live with Annotations] { - def some[R <: Live with Annotations, E](spec: Spec[R, E])(implicit trace: Trace): Spec[R, E] = + def ifPropOption(prop: String)(assertion: Option[String] => Boolean): TestAspectPoly = + new TestAspectPoly { + def some[R, E](spec: Spec[R, E])(implicit trace: Trace): Spec[R, E] = spec.whenZIO(Live.live(System.property(prop)).orDie.map(assertion)) } /** * An aspect that only runs a test if the specified Java property is set. */ - def ifPropSet(prop: String): TestAspectAtLeastR[Live with Annotations] = + def ifPropSet(prop: String): TestAspectPoly = ifPropOption(prop)(_.nonEmpty) /** @@ -530,7 +530,7 @@ object TestAspect extends TimeoutVariants { /** * An aspect that only runs tests on ScalaJS. */ - val jsOnly: TestAspectAtLeastR[Annotations] = + val jsOnly: TestAspectPoly = if (TestPlatform.isJS) identity else ignore /** @@ -544,20 +544,20 @@ object TestAspect extends TimeoutVariants { /** * An aspect that only runs tests on the JVM. */ - val jvmOnly: TestAspectAtLeastR[Annotations] = + val jvmOnly: TestAspectPoly = if (TestPlatform.isJVM) identity else ignore /** * An aspect that runs only on operating systems accepted by the specified * predicate. */ - def os(f: System.OS => Boolean): TestAspectAtLeastR[Annotations] = + def os(f: System.OS => Boolean): TestAspectPoly = if (f(System.os)) identity else ignore /** * Runs only on Mac operating systems. */ - val mac: TestAspectAtLeastR[Annotations] = os(_.isMac) + val mac: TestAspectPoly = os(_.isMac) /** * An aspect that applies the specified aspect on ScalaNative. @@ -570,16 +570,16 @@ object TestAspect extends TimeoutVariants { /** * An aspect that only runs tests on ScalaNative. */ - val nativeOnly: TestAspectAtLeastR[Annotations] = + val nativeOnly: TestAspectPoly = if (TestPlatform.isNative) identity else ignore /** * An aspect that repeats the test a default number of times, ensuring it is * stable ("non-flaky"). Stops at the first failure. */ - val nonFlaky: TestAspectAtLeastR[Annotations with TestConfig] = { - val nonFlaky = new PerTest.AtLeastR[Annotations with TestConfig] { - def perTest[R <: Annotations with TestConfig, E]( + val nonFlaky: TestAspectPoly = { + val nonFlaky = new PerTest.Poly { + def perTest[R, E]( test: ZIO[R, TestFailure[E], TestSuccess] )(implicit trace: Trace): ZIO[R, TestFailure[E], TestSuccess] = TestConfig.repeats.flatMap { n => @@ -593,9 +593,9 @@ object TestAspect extends TimeoutVariants { * An aspect that repeats the test a specified number of times, ensuring it is * stable ("non-flaky"). Stops at the first failure. */ - def nonFlaky(n: Int): TestAspectAtLeastR[Annotations] = { - val nonFlaky = new PerTest.AtLeastR[Annotations] { - def perTest[R <: Annotations, E]( + def nonFlaky(n: Int): TestAspectPoly = { + val nonFlaky = new PerTest.Poly { + def perTest[R, E]( test: ZIO[R, TestFailure[E], TestSuccess] )(implicit trace: Trace): ZIO[R, TestFailure[E], TestSuccess] = test *> test.tap(_ => Annotations.annotate(TestAnnotation.repeated, 1)).repeatN(n - 1) @@ -607,7 +607,7 @@ object TestAspect extends TimeoutVariants { * Constructs an aspect that requires a test to not terminate within the * specified time. */ - def nonTermination(duration: Duration): TestAspectAtLeastR[Live] = + def nonTermination(duration: Duration): TestAspectPoly = timeout(duration) >>> failing { case TestFailure.Assertion(_, _) => false @@ -622,7 +622,7 @@ object TestAspect extends TimeoutVariants { * Sets the seed of the `TestRandom` instance in the environment to a random * value before each test. */ - val nondeterministic: TestAspectAtLeastR[Live] = + val nondeterministic: TestAspectPoly = before( Live .live(Random.nextLong(Trace.empty))(Trace.empty) @@ -645,7 +645,7 @@ object TestAspect extends TimeoutVariants { /** * An aspect that repeats successful tests according to a schedule. */ - def repeat[R0 <: Annotations with Live]( + def repeat[R0]( schedule: Schedule[R0, TestSuccess, Any] ): TestAspectAtLeastR[R0] = { val repeat = new PerTest.AtLeastR[R0] { @@ -668,18 +668,19 @@ object TestAspect extends TimeoutVariants { * An aspect that runs each test with the number of times to repeat tests to * ensure they are stable set to the specified value. */ - def repeats(n: Int): TestAspectAtLeastR[TestConfig] = - new PerTest.AtLeastR[TestConfig] { - def perTest[R <: TestConfig, E]( + def repeats(n: Int): TestAspectPoly = + new PerTest.Poly { + def perTest[R, E]( test: ZIO[R, TestFailure[E], TestSuccess] )(implicit trace: Trace): ZIO[R, TestFailure[E], TestSuccess] = - test.updateService[TestConfig] { old => - new TestConfig { + testConfigWith { old => + val testConfig = new TestConfig { val repeats = n val retries = old.retries val samples = old.samples val shrinks = old.shrinks } + withTestConfig(testConfig)(test) } } @@ -737,25 +738,26 @@ object TestAspect extends TimeoutVariants { * An aspect that runs each test with the number of times to retry flaky tests * set to the specified value. */ - def retries(n: Int): TestAspectAtLeastR[TestConfig] = - new PerTest.AtLeastR[TestConfig] { - def perTest[R <: TestConfig, E]( + def retries(n: Int): TestAspectPoly = + new PerTest.Poly { + def perTest[R, E]( test: ZIO[R, TestFailure[E], TestSuccess] )(implicit trace: Trace): ZIO[R, TestFailure[E], TestSuccess] = - test.updateService[TestConfig] { old => - new TestConfig { + testConfigWith { old => + val testConfig = new TestConfig { val repeats = old.repeats val retries = n val samples = old.samples val shrinks = old.shrinks } + withTestConfig(testConfig)(test) } } /** * An aspect that retries failed tests according to a schedule. */ - def retry[R0 <: Annotations with Live, E0]( + def retry[R0, E0]( schedule: Schedule[R0, TestFailure[E0], Any] ): TestAspect[Nothing, R0, Nothing, E0] = { val retry = new TestAspect.PerTest[Nothing, R0, Nothing, E0] { @@ -777,18 +779,19 @@ object TestAspect extends TimeoutVariants { * An aspect that runs each test with the number of sufficient samples to * check for a random variable set to the specified value. */ - def samples(n: Int): TestAspectAtLeastR[TestConfig] = - new PerTest.AtLeastR[TestConfig] { - def perTest[R <: TestConfig, E]( + def samples(n: Int): TestAspectPoly = + new PerTest.Poly { + def perTest[R, E]( test: ZIO[R, TestFailure[E], TestSuccess] )(implicit trace: Trace): ZIO[R, TestFailure[E], TestSuccess] = - test.updateService[TestConfig] { old => - new TestConfig { + testConfigWith { old => + val testConfig = new TestConfig { val repeats = old.repeats val retries = old.retries val samples = n val shrinks = old.shrinks } + withTestConfig(testConfig)(test) } } @@ -841,31 +844,31 @@ object TestAspect extends TimeoutVariants { /** * An aspect that only runs tests on Scala 2. */ - val scala2Only: TestAspectAtLeastR[Annotations] = + val scala2Only: TestAspectPoly = if (TestVersion.isScala2) identity else ignore /** * An aspect that only runs tests on Scala 2.11. */ - val scala211Only: TestAspectAtLeastR[Annotations] = + val scala211Only: TestAspectPoly = if (TestVersion.isScala211) identity else ignore /** * An aspect that only runs tests on Scala 2.12. */ - val scala212Only: TestAspectAtLeastR[Annotations] = + val scala212Only: TestAspectPoly = if (TestVersion.isScala212) identity else ignore /** * An aspect that only runs tests on Scala 2.13. */ - val scala213Only: TestAspectAtLeastR[Annotations] = + val scala213Only: TestAspectPoly = if (TestVersion.isScala213) identity else ignore /** * An aspect that only runs tests on Scala 3. */ - val scala3Only: TestAspectAtLeastR[Annotations] = + val scala3Only: TestAspectPoly = if (TestVersion.isScala3) identity else ignore /** @@ -879,18 +882,19 @@ object TestAspect extends TimeoutVariants { * An aspect that runs each test with the maximum number of shrinkings to * minimize large failures set to the specified value. */ - def shrinks(n: Int): TestAspectAtLeastR[TestConfig] = - new PerTest.AtLeastR[TestConfig] { - def perTest[R <: TestConfig, E]( + def shrinks(n: Int): TestAspectPoly = + new PerTest.Poly { + def perTest[R, E]( test: ZIO[R, TestFailure[E], TestSuccess] )(implicit trace: Trace): ZIO[R, TestFailure[E], TestSuccess] = - test.updateService[TestConfig] { old => - new TestConfig { + testConfigWith { old => + val testConfig = new TestConfig { val repeats = old.repeats val retries = old.retries val samples = old.samples val shrinks = n } + withTestConfig(testConfig)(test) } } @@ -910,14 +914,21 @@ object TestAspect extends TimeoutVariants { /** * An aspect that runs each test with the size set to the specified value. */ - def sized(n: Int): TestAspectAtLeastR[Sized] = - new PerTest.AtLeastR[Sized] { - def perTest[R <: Sized, E](test: ZIO[R, TestFailure[E], TestSuccess])(implicit + def size(n: Int): TestAspectPoly = + new PerTest.Poly { + def perTest[R, E](test: ZIO[R, TestFailure[E], TestSuccess])(implicit trace: Trace ): ZIO[R, TestFailure[E], TestSuccess] = Sized.withSize(n)(test) } + /** + * An aspect that runs each test with the size set to the specified value. + */ + @deprecated("use size", "2.0.2") + def sized(n: Int): TestAspectPoly = + size(n) + /** * An aspect that converts ignored tests into test failures. */ @@ -942,9 +953,9 @@ object TestAspect extends TimeoutVariants { /** * Annotates tests with their execution times. */ - val timed: TestAspectAtLeastR[Live with Annotations] = - new TestAspect.PerTest.AtLeastR[Live with Annotations] { - def perTest[R <: Live with Annotations, E]( + val timed: TestAspectPoly = + new PerTest.Poly { + def perTest[R, E]( test: ZIO[R, TestFailure[E], TestSuccess] )(implicit trace: Trace): ZIO[R, TestFailure[E], TestSuccess] = Live.withLive(test)(_.either.summarized(Clock.instant)(TestDuration.fromInterval)).flatMap { @@ -960,9 +971,9 @@ object TestAspect extends TimeoutVariants { */ def timeout( duration: Duration - ): TestAspectAtLeastR[Live] = - new PerTest.AtLeastR[Live] { - def perTest[R <: Live, E]( + ): TestAspectPoly = + new PerTest.Poly { + def perTest[R, E]( test: ZIO[R, TestFailure[E], TestSuccess] )(implicit trace: Trace): ZIO[R, TestFailure[E], TestSuccess] = { def timeoutFailure = @@ -989,19 +1000,19 @@ object TestAspect extends TimeoutVariants { /** * Runs only on Unix / Linux operating systems. */ - val unix: TestAspectAtLeastR[Annotations] = os(_.isUnix) + val unix: TestAspectPoly = os(_.isUnix) /** * Runs only on Windows operating systems. */ - val windows: TestAspectAtLeastR[Annotations] = os(_.isWindows) + val windows: TestAspectPoly = os(_.isWindows) /** * An aspect that runs tests with the live clock service. */ - lazy val withLiveClock: TestAspectAtLeastR[Live] = - new TestAspectAtLeastR[Live] { - def some[R <: Live, E](spec: Spec[R, E])(implicit trace: Trace): Spec[R, E] = { + lazy val withLiveClock: TestAspectPoly = + new TestAspectPoly { + def some[R, E](spec: Spec[R, E])(implicit trace: Trace): Spec[R, E] = { val layer = ZLayer.scoped { for { clock <- live(ZIO.clock) @@ -1015,9 +1026,9 @@ object TestAspect extends TimeoutVariants { /** * An aspect that runs tests with the live console service. */ - lazy val withLiveConsole: TestAspectAtLeastR[Live] = - new TestAspectAtLeastR[Live] { - def some[R <: Live, E](spec: Spec[R, E])(implicit trace: Trace): Spec[R, E] = { + lazy val withLiveConsole: TestAspectPoly = + new TestAspectPoly { + def some[R, E](spec: Spec[R, E])(implicit trace: Trace): Spec[R, E] = { val layer = ZLayer.scoped { for { console <- live(ZIO.console) @@ -1031,7 +1042,7 @@ object TestAspect extends TimeoutVariants { /** * An aspect that runs tests with the live default ZIO services. */ - lazy val withLiveEnvironment: TestAspectAtLeastR[Live] = + lazy val withLiveEnvironment: TestAspectPoly = withLiveClock >>> withLiveConsole >>> withLiveRandom >>> @@ -1040,9 +1051,9 @@ object TestAspect extends TimeoutVariants { /** * An aspect that runs tests with the live random service. */ - lazy val withLiveRandom: TestAspectAtLeastR[Live] = - new TestAspectAtLeastR[Live] { - def some[R <: Live, E](spec: Spec[R, E])(implicit trace: Trace): Spec[R, E] = { + lazy val withLiveRandom: TestAspectPoly = + new TestAspectPoly { + def some[R, E](spec: Spec[R, E])(implicit trace: Trace): Spec[R, E] = { val layer = ZLayer.scoped { for { random <- live(ZIO.random) @@ -1056,9 +1067,9 @@ object TestAspect extends TimeoutVariants { /** * An aspect that runs tests with the live system service. */ - lazy val withLiveSystem: TestAspectAtLeastR[Live] = - new TestAspectAtLeastR[Live] { - def some[R <: Live, E](spec: Spec[R, E])(implicit trace: Trace): Spec[R, E] = { + lazy val withLiveSystem: TestAspectPoly = + new TestAspectPoly { + def some[R, E](spec: Spec[R, E])(implicit trace: Trace): Spec[R, E] = { val layer = ZLayer.scoped { for { system <- live(ZIO.system) diff --git a/test/shared/src/main/scala/zio/test/TestConfig.scala b/test/shared/src/main/scala/zio/test/TestConfig.scala index f8243a2800c1..6ee5564d38d2 100644 --- a/test/shared/src/main/scala/zio/test/TestConfig.scala +++ b/test/shared/src/main/scala/zio/test/TestConfig.scala @@ -16,7 +16,7 @@ package zio.test -import zio.{URIO, ZIO, ZLayer} +import zio.{Tag, URIO, ZIO, ZLayer} import zio.stacktracer.TracingImplicits.disableAutoTrace import zio.Trace @@ -52,6 +52,10 @@ trait TestConfig extends Serializable { object TestConfig { + val tag: Tag[TestConfig] = Tag[TestConfig] + + final case class Test(repeats: Int, retries: Int, samples: Int, shrinks: Int) extends TestConfig + /** * Constructs a new `TestConfig` with the default settings. */ @@ -61,39 +65,35 @@ object TestConfig { /** * Constructs a new `TestConfig` service with the specified settings. */ - def live(repeats0: Int, retries0: Int, samples0: Int, shrinks0: Int)(implicit + def live(repeats: Int, retries: Int, samples: Int, shrinks: Int)(implicit trace: Trace ): ZLayer[Any, Nothing, TestConfig] = - ZLayer.succeed { - new TestConfig { - val repeats = repeats0 - val retries = retries0 - val samples = samples0 - val shrinks = shrinks0 - } + ZLayer.scoped { + val testConfig = Test(repeats, retries, samples, shrinks) + withTestConfigScoped(testConfig).as(testConfig) } /** * The number of times to repeat tests to ensure they are stable. */ - def repeats(implicit trace: Trace): URIO[TestConfig, Int] = - ZIO.serviceWith(_.repeats) + def repeats(implicit trace: Trace): URIO[Any, Int] = + testConfigWith(testConfig => ZIO.succeedNow(testConfig.repeats)) /** * The number of times to retry flaky tests. */ - def retries(implicit trace: Trace): URIO[TestConfig, Int] = - ZIO.serviceWith(_.retries) + def retries(implicit trace: Trace): URIO[Any, Int] = + testConfigWith(testConfig => ZIO.succeedNow(testConfig.retries)) /** * The number of sufficient samples to check for a random variable. */ - def samples(implicit trace: Trace): URIO[TestConfig, Int] = - ZIO.serviceWith(_.samples) + def samples(implicit trace: Trace): URIO[Any, Int] = + testConfigWith(testConfig => ZIO.succeedNow(testConfig.samples)) /** * The maximum number of shrinkings to minimize large failures */ - def shrinks(implicit trace: Trace): URIO[TestConfig, Int] = - ZIO.serviceWith(_.shrinks) + def shrinks(implicit trace: Trace): URIO[Any, Int] = + testConfigWith(testConfig => ZIO.succeedNow(testConfig.shrinks)) } diff --git a/test/shared/src/main/scala/zio/test/TestServices.scala b/test/shared/src/main/scala/zio/test/TestServices.scala new file mode 100644 index 000000000000..1f7dabcc3d0f --- /dev/null +++ b/test/shared/src/main/scala/zio/test/TestServices.scala @@ -0,0 +1,43 @@ +/* + * Copyright 2017-2022 John A. De Goes and the ZIO Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package zio.test + +import zio._ +import zio.internal.stacktracer.Tracer +import zio.stacktracer.TracingImplicits.disableAutoTrace + +object TestServices { + + /** + * The default ZIO Test services. + */ + val test: ZEnvironment[Annotations with Live with Sized with TestConfig] = + ZEnvironment[Annotations, Live, Sized, TestConfig]( + Annotations.Test(FiberRef.unsafe.make(TestAnnotationMap.empty)(Unsafe.unsafe)), + Live.Test(DefaultServices.live), + Sized.Test(FiberRef.unsafe.make(100)(Unsafe.unsafe)), + TestConfig.Test(100, 100, 200, 1000) + )(Annotations.tag, Live.tag, Sized.tag, TestConfig.tag) + + private[zio] val currentServices: FiberRef.WithPatch[ZEnvironment[ + Annotations with Live with Sized with TestConfig + ], ZEnvironment.Patch[ + Annotations with Live with Sized with TestConfig, + Annotations with Live with Sized with TestConfig + ]] = + FiberRef.unsafe.makeEnvironment(test)(Unsafe.unsafe) +} diff --git a/test/shared/src/main/scala/zio/test/TimeoutVariants.scala b/test/shared/src/main/scala/zio/test/TimeoutVariants.scala index 91a26948e18e..67f45a1744b3 100644 --- a/test/shared/src/main/scala/zio/test/TimeoutVariants.scala +++ b/test/shared/src/main/scala/zio/test/TimeoutVariants.scala @@ -26,12 +26,12 @@ trait TimeoutVariants { */ def timeoutWarning( duration: Duration - ): TestAspectAtLeastR[Live] = - new TestAspect[Nothing, Live, Nothing, Any] { - def some[R <: Live, E]( + ): TestAspectPoly = + new TestAspectPoly { + def some[R, E]( spec: Spec[R, E] )(implicit trace: Trace): Spec[R, E] = { - def loop(labels: List[String], spec: Spec[R, E]): Spec[R with Live, E] = + def loop(labels: List[String], spec: Spec[R, E]): Spec[R, E] = spec.caseValue match { case Spec.ExecCase(exec, spec) => Spec.exec(exec, loop(labels, spec)) case Spec.LabeledCase(label, spec) => Spec.labeled(label, loop(label :: labels, spec)) @@ -50,7 +50,7 @@ trait TimeoutVariants { labels: List[String], test: ZTest[R, E], duration: Duration - ): ZTest[R with Live, E] = + ): ZTest[R, E] = test.raceWith(Live.withLive(showWarning(labels, duration))(_.delay(duration)))( (result, fiber) => fiber.interrupt *> ZIO.done(result), (_, fiber) => fiber.join @@ -59,7 +59,7 @@ trait TimeoutVariants { private def showWarning( labels: List[String], duration: Duration - ): URIO[Live, Unit] = + ): UIO[Unit] = Live.live(Console.printLine(renderWarning(labels, duration)).orDie) private def renderWarning(labels: List[String], duration: Duration): String = diff --git a/test/shared/src/main/scala/zio/test/laws/GenF.scala b/test/shared/src/main/scala/zio/test/laws/GenF.scala index 7b2a79d5fad7..e7651d989647 100644 --- a/test/shared/src/main/scala/zio/test/laws/GenF.scala +++ b/test/shared/src/main/scala/zio/test/laws/GenF.scala @@ -17,7 +17,7 @@ package zio.test.laws import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.test.{Gen, Sized} +import zio.test.Gen import zio.Chunk import zio.Trace @@ -41,9 +41,9 @@ object GenF { /** * A generator of `Chunk` values. */ - val chunk: GenF[Sized, Chunk] = - new GenF[Sized, Chunk] { - def apply[R1 <: Sized, A](gen: Gen[R1, A])(implicit + val chunk: GenF[Any, Chunk] = + new GenF[Any, Chunk] { + def apply[R1, A](gen: Gen[R1, A])(implicit trace: Trace ): Gen[R1, Chunk[A]] = Gen.chunkOf(gen) @@ -61,9 +61,9 @@ object GenF { /** * A generator of `List` values. */ - val list: GenF[Sized, List] = - new GenF[Sized, List] { - def apply[R1 <: Sized, A](gen: Gen[R1, A])(implicit + val list: GenF[Any, List] = + new GenF[Any, List] { + def apply[R1, A](gen: Gen[R1, A])(implicit trace: Trace ): Gen[R1, List[A]] = Gen.listOf(gen) @@ -72,7 +72,7 @@ object GenF { /** * A generator of `Map` values. */ - def map[R <: Sized, A](a: Gen[R, A]): GenF[R, ({ type lambda[+x] = Map[A, x] })#lambda] = + def map[R, A](a: Gen[R, A]): GenF[R, ({ type lambda[+x] = Map[A, x] })#lambda] = new GenF[R, ({ type lambda[+x] = Map[A, x] })#lambda] { def apply[R1 <: R, B](b: Gen[R1, B])(implicit trace: Trace): Gen[R1, Map[A, B]] = Gen.mapOf(a, b) @@ -90,18 +90,18 @@ object GenF { /** * A generator of `Set` values. */ - val set: GenF[Sized, Set] = - new GenF[Sized, Set] { - def apply[R1 <: Sized, A](gen: Gen[R1, A])(implicit trace: Trace): Gen[R1, Set[A]] = + val set: GenF[Any, Set] = + new GenF[Any, Set] { + def apply[R1, A](gen: Gen[R1, A])(implicit trace: Trace): Gen[R1, Set[A]] = Gen.setOf(gen) } /** * A generator of `Vector` values. */ - val vector: GenF[Sized, Vector] = - new GenF[Sized, Vector] { - def apply[R1 <: Sized, A](gen: Gen[R1, A])(implicit + val vector: GenF[Any, Vector] = + new GenF[Any, Vector] { + def apply[R1, A](gen: Gen[R1, A])(implicit trace: Trace ): Gen[R1, Vector[A]] = Gen.vectorOf(gen) diff --git a/test/shared/src/main/scala/zio/test/laws/ZLaws.scala b/test/shared/src/main/scala/zio/test/laws/ZLaws.scala index 7df9e466b15a..169ef5711bd4 100644 --- a/test/shared/src/main/scala/zio/test/laws/ZLaws.scala +++ b/test/shared/src/main/scala/zio/test/laws/ZLaws.scala @@ -17,7 +17,7 @@ package zio.test.laws import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.test.{Gen, TestConfig, TestResult, check} +import zio.test.{Gen, TestResult, check} import zio.{URIO, ZIO, Trace} /** @@ -33,7 +33,7 @@ abstract class ZLaws[-Caps[_], -R] { self => * Test that values of type `A` satisfy the laws using the specified * generator. */ - def run[R1 <: R with TestConfig, A: Caps](gen: Gen[R1, A])(implicit + def run[R1 <: R, A: Caps](gen: Gen[R1, A])(implicit trace: Trace ): ZIO[R1, Nothing, TestResult] @@ -48,7 +48,7 @@ abstract class ZLaws[-Caps[_], -R] { self => object ZLaws { private final case class Both[-Caps[_], -R](left: ZLaws[Caps, R], right: ZLaws[Caps, R]) extends ZLaws[Caps, R] { - final def run[R1 <: R with TestConfig, A: Caps](gen: Gen[R1, A])(implicit + final def run[R1 <: R, A: Caps](gen: Gen[R1, A])(implicit trace: Trace ): ZIO[R1, Nothing, TestResult] = left.run(gen).zipWith(right.run(gen))(_ && _) @@ -59,7 +59,7 @@ object ZLaws { */ abstract class Law1[-Caps[_]](label: String) extends ZLaws[Caps, Any] { self => def apply[A: Caps](a1: A): TestResult - final def run[R <: TestConfig, A: Caps](gen: Gen[R, A])(implicit trace: Trace): URIO[R, TestResult] = + final def run[R, A: Caps](gen: Gen[R, A])(implicit trace: Trace): URIO[R, TestResult] = check(gen)(apply(_).??(label)) } @@ -68,7 +68,7 @@ object ZLaws { */ abstract class Law1ZIO[-Caps[_], -R](label: String) extends ZLaws[Caps, R] { self => def apply[A: Caps](a1: A): URIO[R, TestResult] - final def run[R1 <: R with TestConfig, A: Caps](gen: Gen[R1, A])(implicit + final def run[R1 <: R, A: Caps](gen: Gen[R1, A])(implicit trace: Trace ): ZIO[R1, Nothing, TestResult] = check(gen)(apply(_).map(_.??(label))) @@ -79,7 +79,7 @@ object ZLaws { */ abstract class Law2[-Caps[_]](label: String) extends ZLaws[Caps, Any] { self => def apply[A: Caps](a1: A, a2: A): TestResult - final def run[R <: TestConfig, A: Caps](gen: Gen[R, A])(implicit trace: Trace): URIO[R, TestResult] = + final def run[R, A: Caps](gen: Gen[R, A])(implicit trace: Trace): URIO[R, TestResult] = check(gen, gen)(apply(_, _).label(label)) } @@ -88,7 +88,7 @@ object ZLaws { */ abstract class Law2ZIO[-Caps[_], -R](label: String) extends ZLaws[Caps, R] { self => def apply[A: Caps](a1: A, a2: A): URIO[R, TestResult] - final def run[R1 <: R with TestConfig, A: Caps](gen: Gen[R1, A])(implicit + final def run[R1 <: R, A: Caps](gen: Gen[R1, A])(implicit trace: Trace ): ZIO[R1, Nothing, TestResult] = check(gen, gen)(apply(_, _).map(_.label(label))) @@ -99,7 +99,7 @@ object ZLaws { */ abstract class Law3[-Caps[_]](label: String) extends ZLaws[Caps, Any] { self => def apply[A: Caps](a1: A, a2: A, a3: A): TestResult - final def run[R <: TestConfig, A: Caps](gen: Gen[R, A])(implicit trace: Trace): URIO[R, TestResult] = + final def run[R, A: Caps](gen: Gen[R, A])(implicit trace: Trace): URIO[R, TestResult] = check(gen, gen, gen)(apply(_, _, _).label(label)) } @@ -108,7 +108,7 @@ object ZLaws { */ abstract class Law3ZIO[-Caps[_], -R](label: String) extends ZLaws[Caps, R] { self => def apply[A: Caps](a1: A, a2: A, a3: A): URIO[R, TestResult] - final def run[R1 <: R with TestConfig, A: Caps](gen: Gen[R1, A])(implicit + final def run[R1 <: R, A: Caps](gen: Gen[R1, A])(implicit trace: Trace ): ZIO[R1, Nothing, TestResult] = check(gen, gen, gen)(apply(_, _, _).map(_.label(label))) diff --git a/test/shared/src/main/scala/zio/test/laws/ZLaws2.scala b/test/shared/src/main/scala/zio/test/laws/ZLaws2.scala index 488a1b4a8b79..99a39dfc6779 100644 --- a/test/shared/src/main/scala/zio/test/laws/ZLaws2.scala +++ b/test/shared/src/main/scala/zio/test/laws/ZLaws2.scala @@ -17,12 +17,12 @@ package zio.test.laws import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.test.{Gen, TestConfig, TestResult, check} +import zio.test.{Gen, TestResult, check} import zio.{URIO, ZIO, Trace} abstract class ZLaws2[-CapsBoth[_, _], -CapsLeft[_], -CapsRight[_], -R] { self => - def run[R1 <: R with TestConfig, A: CapsLeft, B: CapsRight](left: Gen[R1, A], right: Gen[R1, B])(implicit + def run[R1 <: R, A: CapsLeft, B: CapsRight](left: Gen[R1, A], right: Gen[R1, B])(implicit CapsBoth: CapsBoth[A, B], trace: Trace ): ZIO[R1, Nothing, TestResult] @@ -39,7 +39,7 @@ object ZLaws2 { left: ZLaws2[CapsBoth, CapsLeft, CapsRight, R], right: ZLaws2[CapsBoth, CapsLeft, CapsRight, R] ) extends ZLaws2[CapsBoth, CapsLeft, CapsRight, R] { - final def run[R1 <: R with TestConfig, A: CapsLeft, B: CapsRight](a: Gen[R1, A], b: Gen[R1, B])(implicit + final def run[R1 <: R, A: CapsLeft, B: CapsRight](a: Gen[R1, A], b: Gen[R1, B])(implicit CapsBoth: CapsBoth[A, B], trace: Trace ): ZIO[R1, Nothing, TestResult] = @@ -49,7 +49,7 @@ object ZLaws2 { abstract class Law1Left[-CapsBoth[_, _], -CapsLeft[_], -CapsRight[_]](label: String) extends ZLaws2[CapsBoth, CapsLeft, CapsRight, Any] { self => def apply[A: CapsLeft, B: CapsRight](a1: A)(implicit CapsBoth: CapsBoth[A, B]): TestResult - final def run[R <: TestConfig, A: CapsLeft, B: CapsRight](a: Gen[R, A], b: Gen[R, B])(implicit + final def run[R, A: CapsLeft, B: CapsRight](a: Gen[R, A], b: Gen[R, B])(implicit CapsBoth: CapsBoth[A, B], trace: Trace ): URIO[R, TestResult] = @@ -59,7 +59,7 @@ object ZLaws2 { abstract class Law1Right[-CapsBoth[_, _], -CapsLeft[_], -CapsRight[_]](label: String) extends ZLaws2[CapsBoth, CapsLeft, CapsRight, Any] { self => def apply[A: CapsLeft, B: CapsRight](b1: B)(implicit CapsBoth: CapsBoth[A, B]): TestResult - final def run[R <: TestConfig, A: CapsLeft, B: CapsRight](a: Gen[R, A], b: Gen[R, B])(implicit + final def run[R, A: CapsLeft, B: CapsRight](a: Gen[R, A], b: Gen[R, B])(implicit CapsBoth: CapsBoth[A, B], trace: Trace ): URIO[R, TestResult] = diff --git a/test/shared/src/main/scala/zio/test/laws/ZLawsF.scala b/test/shared/src/main/scala/zio/test/laws/ZLawsF.scala index 35979cc26878..46ef82690512 100644 --- a/test/shared/src/main/scala/zio/test/laws/ZLawsF.scala +++ b/test/shared/src/main/scala/zio/test/laws/ZLawsF.scala @@ -17,7 +17,7 @@ package zio.test.laws import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.test.{Gen, TestConfig, TestResult, check} +import zio.test.{Gen, TestResult, check} import zio.{URIO, ZIO, Trace} /** @@ -40,7 +40,7 @@ object ZLawsF { * function to construct a generator of `F[A]` values given a generator of * `A` values. */ - def run[R1 <: R with TestConfig, F[+_]: CapsF, A: Caps]( + def run[R1 <: R, F[+_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] @@ -61,7 +61,7 @@ object ZLawsF { left: Covariant[CapsF, Caps, R], right: Covariant[CapsF, Caps, R] ) extends Covariant[CapsF, Caps, R] { - final def run[R1 <: R with TestConfig, F[+_]: CapsF, A: Caps]( + final def run[R1 <: R, F[+_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = @@ -74,7 +74,7 @@ object ZLawsF { */ abstract class ComposeLaw[-CapsF[_[+_]], -Caps[_]](label: String) extends Covariant[CapsF, Caps, Any] { self => def apply[F[+_]: CapsF, A: Caps, B: Caps, C: Caps](fa: F[A], f: A => B, g: B => C): TestResult - final def run[R <: TestConfig, F[+_]: CapsF, A: Caps]( + final def run[R, F[+_]: CapsF, A: Caps]( genF: GenF[R, F], gen: Gen[R, A] )(implicit trace: Trace): URIO[R, TestResult] = @@ -87,7 +87,7 @@ object ZLawsF { */ abstract class FlattenLaw[-CapsF[_[+_]], -Caps[_]](label: String) extends Covariant[CapsF, Caps, Any] { self => def apply[F[+_]: CapsF, A: Caps](fffa: F[F[F[A]]]): TestResult - final def run[R <: TestConfig, F[+_]: CapsF, A: Caps]( + final def run[R, F[+_]: CapsF, A: Caps]( genF: GenF[R, F], gen: Gen[R, A] )(implicit trace: Trace): URIO[R, TestResult] = @@ -99,7 +99,7 @@ object ZLawsF { */ abstract class Law1[-CapsF[_[+_]], -Caps[_]](label: String) extends Covariant[CapsF, Caps, Any] { self => def apply[F[+_]: CapsF, A: Caps](fa: F[A]): TestResult - final def run[R <: TestConfig, F[+_]: CapsF, A: Caps]( + final def run[R, F[+_]: CapsF, A: Caps]( genF: GenF[R, F], gen: Gen[R, A] )(implicit trace: Trace): URIO[R, TestResult] = @@ -111,7 +111,7 @@ object ZLawsF { */ abstract class Law1ZIO[-CapsF[_[+_]], -Caps[_], -R](label: String) extends Covariant[CapsF, Caps, R] { self => def apply[F[+_]: CapsF, A: Caps](fa: F[A]): URIO[R, TestResult] - final def run[R1 <: R with TestConfig, F[+_]: CapsF, A: Caps]( + final def run[R1 <: R, F[+_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = @@ -123,7 +123,7 @@ object ZLawsF { */ abstract class Law2[-CapsF[_[+_]], -Caps[_]](label: String) extends Covariant[CapsF, Caps, Any] { self => def apply[F[+_]: CapsF, A: Caps, B: Caps](fa: F[A], fb: F[B]): TestResult - final def run[R <: TestConfig, F[+_]: CapsF, A: Caps]( + final def run[R, F[+_]: CapsF, A: Caps]( genF: GenF[R, F], gen: Gen[R, A] )(implicit trace: Trace): URIO[R, TestResult] = @@ -135,7 +135,7 @@ object ZLawsF { */ abstract class Law2ZIO[-CapsF[_[+_]], -Caps[_], -R](label: String) extends Covariant[CapsF, Caps, R] { self => def apply[F[+_]: CapsF, A: Caps, B: Caps](fa: F[A], fb: F[B]): URIO[R, TestResult] - final def run[R1 <: R with TestConfig, F[+_]: CapsF, A: Caps]( + final def run[R1 <: R, F[+_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = @@ -147,7 +147,7 @@ object ZLawsF { */ abstract class Law3[-CapsF[_[+_]], -Caps[_]](label: String) extends Covariant[CapsF, Caps, Any] { self => def apply[F[+_]: CapsF, A: Caps, B: Caps, C: Caps](fa: F[A], fb: F[B], fc: F[C]): TestResult - final def run[R <: TestConfig, F[+_]: CapsF, A: Caps]( + final def run[R, F[+_]: CapsF, A: Caps]( genF: GenF[R, F], gen: Gen[R, A] )(implicit trace: Trace): URIO[R, TestResult] = @@ -159,7 +159,7 @@ object ZLawsF { */ abstract class Law3ZIO[-CapsF[_[+_]], -Caps[_], -R](label: String) extends Covariant[CapsF, Caps, R] { self => def apply[F[+_]: CapsF, A: Caps, B: Caps, C: Caps](fa: F[A], fb: F[B], fc: F[C]): URIO[R, TestResult] - final def run[R1 <: R with TestConfig, F[+_]: CapsF, A: Caps]( + final def run[R1 <: R, F[+_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = @@ -177,7 +177,7 @@ object ZLawsF { * function to construct a generator of `F[A]` values given a generator of * `A` values. */ - def run[R1 <: R with TestConfig, F[-_]: CapsF, A: Caps]( + def run[R1 <: R, F[-_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] @@ -198,7 +198,7 @@ object ZLawsF { left: Contravariant[CapsF, Caps, R], right: Contravariant[CapsF, Caps, R] ) extends Contravariant[CapsF, Caps, R] { - final def run[R1 <: R with TestConfig, F[-_]: CapsF, A: Caps]( + final def run[R1 <: R, F[-_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = @@ -212,7 +212,7 @@ object ZLawsF { abstract class ComposeLaw[-CapsF[_[-_]], -Caps[_]](label: String) extends Contravariant[CapsF, Caps, Any] { self => def apply[F[-_]: CapsF, A: Caps, B: Caps, C: Caps](fa: F[A], f: B => A, g: C => B): TestResult - final def run[R <: TestConfig, F[-_]: CapsF, A: Caps]( + final def run[R, F[-_]: CapsF, A: Caps]( genF: GenF[R, F], gen: Gen[R, A] )(implicit trace: Trace): URIO[R, TestResult] = @@ -224,7 +224,7 @@ object ZLawsF { */ abstract class Law1[-CapsF[_[-_]], -Caps[_]](label: String) extends Contravariant[CapsF, Caps, Any] { self => def apply[F[-_]: CapsF, A: Caps](fa: F[A]): TestResult - final def run[R <: TestConfig, F[-_]: CapsF, A: Caps]( + final def run[R, F[-_]: CapsF, A: Caps]( genF: GenF[R, F], gen: Gen[R, A] )(implicit trace: Trace): URIO[R, TestResult] = @@ -236,7 +236,7 @@ object ZLawsF { */ abstract class Law1ZIO[-CapsF[_[-_]], -Caps[_], -R](label: String) extends Contravariant[CapsF, Caps, R] { self => def apply[F[-_]: CapsF, A: Caps](fa: F[A]): URIO[R, TestResult] - final def run[R1 <: R with TestConfig, F[-_]: CapsF, A: Caps]( + final def run[R1 <: R, F[-_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = @@ -248,7 +248,7 @@ object ZLawsF { */ abstract class Law2[-CapsF[_[-_]], -Caps[_]](label: String) extends Contravariant[CapsF, Caps, Any] { self => def apply[F[-_]: CapsF, A: Caps, B: Caps](fa: F[A], fb: F[B]): TestResult - final def run[R <: TestConfig, F[-_]: CapsF, A: Caps]( + final def run[R, F[-_]: CapsF, A: Caps]( genF: GenF[R, F], gen: Gen[R, A] )(implicit trace: Trace): URIO[R, TestResult] = @@ -260,7 +260,7 @@ object ZLawsF { */ abstract class Law2ZIO[-CapsF[_[-_]], -Caps[_], -R](label: String) extends Contravariant[CapsF, Caps, R] { self => def apply[F[-_]: CapsF, A: Caps, B: Caps](fa: F[A], fb: F[B]): URIO[R, TestResult] - final def run[R1 <: R with TestConfig, F[-_]: CapsF, A: Caps]( + final def run[R1 <: R, F[-_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = @@ -272,7 +272,7 @@ object ZLawsF { */ abstract class Law3[-CapsF[_[-_]], -Caps[_]](label: String) extends Contravariant[CapsF, Caps, Any] { self => def apply[F[-_]: CapsF, A: Caps, B: Caps, C: Caps](fa: F[A], fb: F[B], fc: F[C]): TestResult - final def run[R <: TestConfig, F[-_]: CapsF, A: Caps]( + final def run[R, F[-_]: CapsF, A: Caps]( genF: GenF[R, F], gen: Gen[R, A] )(implicit trace: Trace): URIO[R, TestResult] = @@ -284,7 +284,7 @@ object ZLawsF { */ abstract class Law3ZIO[-CapsF[_[-_]], -Caps[_], -R](label: String) extends Contravariant[CapsF, Caps, R] { self => def apply[F[-_]: CapsF, A: Caps, B: Caps, C: Caps](fa: F[A], fb: F[B], fc: F[C]): URIO[R, TestResult] - final def run[R1 <: R with TestConfig, F[-_]: CapsF, A: Caps]( + final def run[R1 <: R, F[-_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = @@ -302,7 +302,7 @@ object ZLawsF { * function to construct a generator of `F[A]` values given a generator of * `A` values. */ - def run[R1 <: R with TestConfig, F[_]: CapsF, A: Caps]( + def run[R1 <: R, F[_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] @@ -323,7 +323,7 @@ object ZLawsF { left: Invariant[CapsF, Caps, R], right: Invariant[CapsF, Caps, R] ) extends Invariant[CapsF, Caps, R] { - final def run[R1 <: R with TestConfig, F[_]: CapsF, A: Caps]( + final def run[R1 <: R, F[_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = @@ -335,7 +335,7 @@ object ZLawsF { */ abstract class Law1[-CapsF[_[_]], -Caps[_]](label: String) extends Invariant[CapsF, Caps, Any] { self => def apply[F[_]: CapsF, A: Caps](fa: F[A]): TestResult - final def run[R <: TestConfig, F[_]: CapsF, A: Caps](genF: GenF[R, F], gen: Gen[R, A])(implicit + final def run[R, F[_]: CapsF, A: Caps](genF: GenF[R, F], gen: Gen[R, A])(implicit trace: Trace ): URIO[R, TestResult] = check(genF(gen))(apply(_).label(label)) @@ -346,7 +346,7 @@ object ZLawsF { */ abstract class Law1ZIO[-CapsF[_[_]], -Caps[_], -R](label: String) extends Invariant[CapsF, Caps, R] { self => def apply[F[_]: CapsF, A: Caps](fa: F[A]): URIO[R, TestResult] - final def run[R1 <: R with TestConfig, F[_]: CapsF, A: Caps]( + final def run[R1 <: R, F[_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = @@ -358,7 +358,7 @@ object ZLawsF { */ abstract class Law2[-CapsF[_[_]], -Caps[_]](label: String) extends Invariant[CapsF, Caps, Any] { self => def apply[F[_]: CapsF, A: Caps, B: Caps](fa: F[A], fb: F[B]): TestResult - final def run[R <: TestConfig, F[_]: CapsF, A: Caps](genF: GenF[R, F], gen: Gen[R, A])(implicit + final def run[R, F[_]: CapsF, A: Caps](genF: GenF[R, F], gen: Gen[R, A])(implicit trace: Trace ): URIO[R, TestResult] = check(genF(gen), genF(gen))(apply(_, _).label(label)) @@ -369,7 +369,7 @@ object ZLawsF { */ abstract class Law2ZIO[-CapsF[_[_]], -Caps[_], -R](label: String) extends Invariant[CapsF, Caps, R] { self => def apply[F[_]: CapsF, A: Caps, B: Caps](fa: F[A], fb: F[B]): URIO[R, TestResult] - final def run[R1 <: R with TestConfig, F[_]: CapsF, A: Caps]( + final def run[R1 <: R, F[_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = @@ -381,7 +381,7 @@ object ZLawsF { */ abstract class Law3[-CapsF[_[_]], -Caps[_]](label: String) extends Invariant[CapsF, Caps, Any] { self => def apply[F[_]: CapsF, A: Caps, B: Caps, C: Caps](fa: F[A], fb: F[B], fc: F[C]): TestResult - final def run[R <: TestConfig, F[_]: CapsF, A: Caps](genF: GenF[R, F], gen: Gen[R, A])(implicit + final def run[R, F[_]: CapsF, A: Caps](genF: GenF[R, F], gen: Gen[R, A])(implicit trace: Trace ): URIO[R, TestResult] = check(genF(gen), genF(gen), genF(gen))(apply(_, _, _).label(label)) @@ -392,7 +392,7 @@ object ZLawsF { */ abstract class Law3ZIO[-CapsF[_[_]], -Caps[_], -R](label: String) extends Invariant[CapsF, Caps, R] { self => def apply[F[_]: CapsF, A: Caps, B: Caps, C: Caps](fa: F[A], fb: F[B], fc: F[C]): URIO[R, TestResult] - final def run[R1 <: R with TestConfig, F[_]: CapsF, A: Caps]( + final def run[R1 <: R, F[_]: CapsF, A: Caps]( genF: GenF[R1, F], gen: Gen[R1, A] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = diff --git a/test/shared/src/main/scala/zio/test/laws/ZLawsF2.scala b/test/shared/src/main/scala/zio/test/laws/ZLawsF2.scala index b225721a7f6f..7dd820c60922 100644 --- a/test/shared/src/main/scala/zio/test/laws/ZLawsF2.scala +++ b/test/shared/src/main/scala/zio/test/laws/ZLawsF2.scala @@ -17,7 +17,7 @@ package zio.test.laws import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.test.{Gen, TestConfig, TestResult, check} +import zio.test.{Gen, TestResult, check} import zio.{URIO, ZIO} import zio.Trace @@ -33,7 +33,7 @@ object ZLawsF2 { * function to construct a generator of `F[A,B]` values given a generator of * `B` values. */ - def run[R1 <: R with TestConfig, F[-_, +_]: CapsF, A: CapsLeft, B: CapsRight]( + def run[R1 <: R, F[-_, +_]: CapsF, A: CapsLeft, B: CapsRight]( genF: GenF2[R1, F], gen: Gen[R1, B] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] @@ -55,7 +55,7 @@ object ZLawsF2 { right: Divariant[CapsBothF, CapsLeft, CapsRight, R] ) extends Divariant[CapsBothF, CapsLeft, CapsRight, R] { - override final def run[R1 <: R with TestConfig, F[-_, +_]: CapsBothF, A: CapsLeft, B: CapsRight]( + override final def run[R1 <: R, F[-_, +_]: CapsBothF, A: CapsLeft, B: CapsRight]( genF: GenF2[R1, F], gen: Gen[R1, B] )(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = { @@ -78,7 +78,7 @@ object ZLawsF2 { g: A1 => A2 ): TestResult - final def run[R <: TestConfig, F[-_, +_]: CapsBothF, A: Caps, B: Caps, A1: Caps, A2: Caps]( + final def run[R, F[-_, +_]: CapsBothF, A: Caps, B: Caps, A1: Caps, A2: Caps]( genF: GenF2[R, F], genB: Gen[R, B], genA1: Gen[R, A1], @@ -98,7 +98,7 @@ object ZLawsF2 { extends Divariant[CapsBothF, CapsLeft, CapsRight, Any] { self => def apply[F[-_, +_]: CapsBothF, A: CapsLeft, B: CapsRight](fa: F[A, B]): TestResult - final def run[R <: TestConfig, F[-_, +_]: CapsBothF, A: CapsLeft, B: CapsRight]( + final def run[R, F[-_, +_]: CapsBothF, A: CapsLeft, B: CapsRight]( genF: GenF2[R, F], gen: Gen[R, B] )(implicit trace: Trace): URIO[R, TestResult] = diff --git a/test/shared/src/main/scala/zio/test/laws/package.scala b/test/shared/src/main/scala/zio/test/laws/package.scala index 28e7c562da2d..45d654cff9e2 100644 --- a/test/shared/src/main/scala/zio/test/laws/package.scala +++ b/test/shared/src/main/scala/zio/test/laws/package.scala @@ -166,7 +166,7 @@ package object laws { * Checks that all values generated by a the specified generator satisfy the * expected behavior of the lawful instance. */ - def checkAllLaws[Caps[_], R <: TestConfig, R1 <: R, A: Caps]( + def checkAllLaws[Caps[_], R, R1 <: R, A: Caps]( lawful: ZLawful[Caps, R] )(gen: Gen[R1, A])(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = lawful.laws.run(gen) @@ -175,7 +175,7 @@ package object laws { * Checks that all values generated by a the specified generator satisfy the * expected behavior of the lawful instance. */ - def checkAllLaws[CapsBoth[_, _], CapsLeft[_], CapsRight[_], R <: TestConfig, R1 <: R, A: CapsLeft, B: CapsRight]( + def checkAllLaws[CapsBoth[_, _], CapsLeft[_], CapsRight[_], R, R1 <: R, A: CapsLeft, B: CapsRight]( lawful: ZLawful2[CapsBoth, CapsLeft, CapsRight, R] )(a: Gen[R1, A], b: Gen[R1, B])(implicit CapsBoth: CapsBoth[A, B], @@ -183,7 +183,7 @@ package object laws { ): ZIO[R1, Nothing, TestResult] = lawful.laws.run(a, b) - def checkAllLaws[CapsF[_[+_]], Caps[_], R <: TestConfig, R1 <: R, F[+_]: CapsF, A: Caps]( + def checkAllLaws[CapsF[_[+_]], Caps[_], R, R1 <: R, F[+_]: CapsF, A: Caps]( lawful: ZLawfulF.Covariant[CapsF, Caps, R] )(genF: GenF[R1, F], gen: Gen[R1, A])(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = lawful.laws.run(genF, gen) @@ -192,7 +192,7 @@ package object laws { * Checks that all values generated by a the specified generator satisfy the * expected behavior of the lawful instance. */ - def checkAllLaws[CapsF[_[-_]], Caps[_], R <: TestConfig, R1 <: R, F[-_]: CapsF, A: Caps]( + def checkAllLaws[CapsF[_[-_]], Caps[_], R, R1 <: R, F[-_]: CapsF, A: Caps]( lawful: ZLawfulF.Contravariant[CapsF, Caps, R] )(genF: GenF[R1, F], gen: Gen[R1, A])(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = lawful.laws.run(genF, gen) @@ -201,7 +201,7 @@ package object laws { * Checks that all values generated by a the specified generator satisfy the * expected behavior of the lawful instance. */ - def checkAllLaws[CapsF[_[_]], Caps[_], R <: TestConfig, R1 <: R, F[_]: CapsF, A: Caps]( + def checkAllLaws[CapsF[_[_]], Caps[_], R, R1 <: R, F[_]: CapsF, A: Caps]( lawful: ZLawfulF.Invariant[CapsF, Caps, R] )(genF: GenF[R1, F], gen: Gen[R1, A])(implicit trace: Trace): ZIO[R1, Nothing, TestResult] = lawful.laws.run(genF, gen) diff --git a/test/shared/src/main/scala/zio/test/package.scala b/test/shared/src/main/scala/zio/test/package.scala index d5cb8d220fcc..f02fe74a2729 100644 --- a/test/shared/src/main/scala/zio/test/package.scala +++ b/test/shared/src/main/scala/zio/test/package.scala @@ -91,7 +91,7 @@ package object test extends CompileVariants { * environment. This is useful for performing effects such as timing out * tests, accessing the real time, or printing to the real console. */ - def live[R <: Live, E, A](zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = + def live[R, E, A](zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = Live.live(zio) /** @@ -146,6 +146,126 @@ package object test extends CompileVariants { def testSystemWith[R, E, A](f: TestSystem => ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = DefaultServices.currentServices.getWith(services => f(services.asInstanceOf[ZEnvironment[TestSystem]].get)) + /** + * Retrieves the `Annotations` service for this test. + */ + def annotations(implicit trace: Trace): UIO[Annotations] = + annotationsWith(ZIO.succeedNow) + + /** + * Retrieves the `Annotations` service for this test and uses it to run the + * specified workflow. + */ + def annotationsWith[R, E, A](f: Annotations => ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = + TestServices.currentServices.getWith(services => f(services.asInstanceOf[ZEnvironment[Annotations]].get)) + + /** + * Retrieves the `Live` service for this test. + */ + def live(implicit trace: Trace): UIO[Live] = + liveWith(ZIO.succeedNow) + + /** + * Retrieves the `Live` service for this test and uses it to run the specified + * workflow. + */ + def liveWith[R, E, A](f: Live => ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = + TestServices.currentServices.getWith(services => f(services.asInstanceOf[ZEnvironment[Live]].get)) + + /** + * Retrieves the `Sized` service for this test. + */ + def sized(implicit trace: Trace): UIO[Sized] = + sizedWith(ZIO.succeedNow) + + /** + * Retrieves the `Sized` service for this test and uses it to run the + * specified workflow. + */ + def sizedWith[R, E, A](f: Sized => ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = + TestServices.currentServices.getWith(services => f(services.asInstanceOf[ZEnvironment[Sized]].get)) + + /** + * Retrieves the `TestConfig` service for this test. + */ + def testConfig(implicit trace: Trace): UIO[TestConfig] = + testConfigWith(ZIO.succeedNow) + + /** + * Retrieves the `TestConfig` service for this test and uses it to run the + * specified workflow. + */ + def testConfigWith[R, E, A](f: TestConfig => ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = + TestServices.currentServices.getWith(services => f(services.asInstanceOf[ZEnvironment[TestConfig]].get)) + + /** + * Executes the specified workflow with the specified implementation of the + * annotations service. + */ + def withAnnotations[R, E, A <: Annotations, B](annotations: => A)( + zio: => ZIO[R, E, B] + )(implicit tag: Tag[A], trace: Trace): ZIO[R, E, B] = + TestServices.currentServices.locallyWith(_.add(annotations))(zio) + + /** + * Sets the implementation of the annotations service to the specified value + * and restores it to its original value when the scope is closed. + */ + def withAnnotationsScoped[A <: Annotations]( + annotations: => A + )(implicit tag: Tag[A], trace: Trace): ZIO[Scope, Nothing, Unit] = + TestServices.currentServices.locallyScopedWith(_.add(annotations)) + + /** + * Executes the specified workflow with the specified implementation of the + * config service. + */ + def withTestConfig[R, E, A <: TestConfig, B](testConfig: => A)( + zio: => ZIO[R, E, B] + )(implicit tag: Tag[A], trace: Trace): ZIO[R, E, B] = + TestServices.currentServices.locallyWith(_.add(testConfig))(zio) + + /** + * Sets the implementation of the config service to the specified value and + * restores it to its original value when the scope is closed. + */ + def withTestConfigScoped[A <: TestConfig]( + testConfig: => A + )(implicit tag: Tag[A], trace: Trace): ZIO[Scope, Nothing, Unit] = + TestServices.currentServices.locallyScopedWith(_.add(testConfig)) + + /** + * Executes the specified workflow with the specified implementation of the + * sized service. + */ + def withSized[R, E, A <: Sized, B](sized: => A)( + zio: => ZIO[R, E, B] + )(implicit tag: Tag[A], trace: Trace): ZIO[R, E, B] = + TestServices.currentServices.locallyWith(_.add(sized))(zio) + + /** + * Sets the implementation of the sized service to the specified value and + * restores it to its original value when the scope is closed. + */ + def withSizedScoped[A <: Sized](sized: => A)(implicit tag: Tag[A], trace: Trace): ZIO[Scope, Nothing, Unit] = + TestServices.currentServices.locallyScopedWith(_.add(sized)) + + /** + * Executes the specified workflow with the specified implementation of the + * live service. + */ + def withLive[R, E, A <: Live, B](live: => A)( + zio: => ZIO[R, E, B] + )(implicit tag: Tag[A], trace: Trace): ZIO[R, E, B] = + TestServices.currentServices.locallyWith(_.add(live))(zio) + + /** + * Sets the implementation of the live service to the specified value and + * restores it to its original value when the scope is closed. + */ + def withLiveScoped[A <: Live](live: => A)(implicit tag: Tag[A], trace: Trace): ZIO[Scope, Nothing, Unit] = + TestServices.currentServices.locallyScopedWith(_.add(live)) + /** * Transforms this effect with the specified function. The test environment * will be provided to this effect, but the live environment will be provided @@ -157,9 +277,9 @@ package object test extends CompileVariants { * withLive(test)(_.timeout(duration)) * }}} */ - def withLive[R <: Live, E, E1, A, B]( + def withLive[R, E, E1, A, B]( zio: ZIO[R, E, A] - )(f: ZIO[R, E, A] => ZIO[R, E1, B])(implicit trace: Trace): ZIO[R with Live, E1, B] = + )(f: ZIO[R, E, A] => ZIO[R, E1, B])(implicit trace: Trace): ZIO[R, E1, B] = Live.withLive(zio)(f) /** @@ -269,7 +389,7 @@ package object test extends CompileVariants { * Checks the test passes for "sufficient" numbers of samples from the given * random variable. */ - def check[R <: TestConfig, A, In](rv: Gen[R, A])(test: A => In)(implicit + def check[R <: ZAny, A, In](rv: Gen[R, A])(test: A => In)(implicit checkConstructor: CheckConstructor[R, In], sourceLocation: SourceLocation, trace: Trace @@ -281,7 +401,7 @@ package object test extends CompileVariants { /** * A version of `check` that accepts two random variables. */ - def check[R <: TestConfig, A, B, In](rv1: Gen[R, A], rv2: Gen[R, B])( + def check[R <: ZAny, A, B, In](rv1: Gen[R, A], rv2: Gen[R, B])( test: (A, B) => In )(implicit checkConstructor: CheckConstructor[R, In], @@ -293,7 +413,7 @@ package object test extends CompileVariants { /** * A version of `check` that accepts three random variables. */ - def check[R <: TestConfig, A, B, C, In](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C])( + def check[R <: ZAny, A, B, C, In](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C])( test: (A, B, C) => In )(implicit checkConstructor: CheckConstructor[R, In], @@ -305,7 +425,7 @@ package object test extends CompileVariants { /** * A version of `check` that accepts four random variables. */ - def check[R <: TestConfig, A, B, C, D, In](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D])( + def check[R <: ZAny, A, B, C, D, In](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D])( test: (A, B, C, D) => In )(implicit checkConstructor: CheckConstructor[R, In], @@ -317,7 +437,7 @@ package object test extends CompileVariants { /** * A version of `check` that accepts five random variables. */ - def check[R <: TestConfig, A, B, C, D, F, In]( + def check[R <: ZAny, A, B, C, D, F, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -335,7 +455,7 @@ package object test extends CompileVariants { /** * A version of `check` that accepts six random variables. */ - def check[R <: TestConfig, A, B, C, D, F, G, In]( + def check[R <: ZAny, A, B, C, D, F, G, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -354,7 +474,7 @@ package object test extends CompileVariants { /** * A version of `check` that accepts seven random variables. */ - def check[R <: TestConfig, A, B, C, D, F, G, H, In]( + def check[R <: ZAny, A, B, C, D, F, G, H, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -374,7 +494,7 @@ package object test extends CompileVariants { /** * A version of `check` that accepts eight random variables. */ - def check[R <: TestConfig, A, B, C, D, F, G, H, I, In]( + def check[R <: ZAny, A, B, C, D, F, G, H, I, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -397,7 +517,7 @@ package object test extends CompileVariants { * generator. For non-deterministic or infinite generators use `check` or * `checkN`. */ - def checkAll[R <: TestConfig, A, In](rv: Gen[R, A])(test: A => In)(implicit + def checkAll[R <: ZAny, A, In](rv: Gen[R, A])(test: A => In)(implicit checkConstructor: CheckConstructor[R, In], sourceLocation: SourceLocation, trace: Trace @@ -407,7 +527,7 @@ package object test extends CompileVariants { /** * A version of `checkAll` that accepts two random variables. */ - def checkAll[R <: TestConfig, A, B, In](rv1: Gen[R, A], rv2: Gen[R, B])( + def checkAll[R <: ZAny, A, B, In](rv1: Gen[R, A], rv2: Gen[R, B])( test: (A, B) => In )(implicit checkConstructor: CheckConstructor[R, In], @@ -419,7 +539,7 @@ package object test extends CompileVariants { /** * A version of `checkAll` that accepts three random variables. */ - def checkAll[R <: TestConfig, A, B, C, In](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C])( + def checkAll[R <: ZAny, A, B, C, In](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C])( test: (A, B, C) => In )(implicit checkConstructor: CheckConstructor[R, In], @@ -431,7 +551,7 @@ package object test extends CompileVariants { /** * A version of `checkAll` that accepts four random variables. */ - def checkAll[R <: TestConfig, A, B, C, D, In](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D])( + def checkAll[R <: ZAny, A, B, C, D, In](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D])( test: (A, B, C, D) => In )(implicit checkConstructor: CheckConstructor[R, In], @@ -443,7 +563,7 @@ package object test extends CompileVariants { /** * A version of `checkAll` that accepts five random variables. */ - def checkAll[R <: TestConfig, A, B, C, D, F, In]( + def checkAll[R <: ZAny, A, B, C, D, F, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -461,7 +581,7 @@ package object test extends CompileVariants { /** * A version of `checkAll` that accepts six random variables. */ - def checkAll[R <: TestConfig, A, B, C, D, F, G, In]( + def checkAll[R <: ZAny, A, B, C, D, F, G, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -480,7 +600,7 @@ package object test extends CompileVariants { /** * A version of `checkAll` that accepts seven random variables. */ - def checkAll[R <: TestConfig, A, B, C, D, F, G, H, In]( + def checkAll[R <: ZAny, A, B, C, D, F, G, H, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -500,7 +620,7 @@ package object test extends CompileVariants { /** * A version of `checkAll` that accepts eight random variables. */ - def checkAll[R <: TestConfig, E, A, B, C, D, F, G, H, I, In]( + def checkAll[R <: ZAny, E, A, B, C, D, F, G, H, I, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -523,7 +643,7 @@ package object test extends CompileVariants { * random variable. This is useful for deterministic `Gen` that * comprehensively explore all possibilities in a given domain. */ - def checkAllPar[R <: TestConfig, E, A, In](rv: Gen[R, A], parallelism: Int)( + def checkAllPar[R <: ZAny, E, A, In](rv: Gen[R, A], parallelism: Int)( test: A => In )(implicit checkConstructor: CheckConstructor[R, In], @@ -535,7 +655,7 @@ package object test extends CompileVariants { /** * A version of `checkAllPar` that accepts two random variables. */ - def checkAllPar[R <: TestConfig, E, A, B, In](rv1: Gen[R, A], rv2: Gen[R, B], parallelism: Int)( + def checkAllPar[R <: ZAny, E, A, B, In](rv1: Gen[R, A], rv2: Gen[R, B], parallelism: Int)( test: (A, B) => In )(implicit checkConstructor: CheckConstructor[R, In], @@ -547,7 +667,7 @@ package object test extends CompileVariants { /** * A version of `checkAllPar` that accepts three random variables. */ - def checkAllPar[R <: TestConfig, E, A, B, C, In]( + def checkAllPar[R <: ZAny, E, A, B, C, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -564,7 +684,7 @@ package object test extends CompileVariants { /** * A version of `checkAllPar` that accepts four random variables. */ - def checkAllPar[R <: TestConfig, E, A, B, C, D, In]( + def checkAllPar[R <: ZAny, E, A, B, C, D, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -582,7 +702,7 @@ package object test extends CompileVariants { /** * A version of `checkAllPar` that accepts five random variables. */ - def checkAllPar[R <: TestConfig, E, A, B, C, D, F, In]( + def checkAllPar[R <: ZAny, E, A, B, C, D, F, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -601,7 +721,7 @@ package object test extends CompileVariants { /** * A version of `checkAllPar` that accepts six random variables. */ - def checkAllPar[R <: TestConfig, E, A, B, C, D, F, G, In]( + def checkAllPar[R <: ZAny, E, A, B, C, D, F, G, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -621,7 +741,7 @@ package object test extends CompileVariants { /** * A version of `checkAllPar` that accepts six random variables. */ - def checkAllPar[R <: TestConfig, E, A, B, C, D, F, G, H, In]( + def checkAllPar[R <: ZAny, E, A, B, C, D, F, G, H, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -642,7 +762,7 @@ package object test extends CompileVariants { /** * A version of `checkAllPar` that accepts six random variables. */ - def checkAllPar[R <: TestConfig, E, A, B, C, D, F, G, H, I, In]( + def checkAllPar[R <: ZAny, E, A, B, C, D, F, G, H, I, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -760,33 +880,33 @@ package object test extends CompileVariants { object CheckVariants { final class CheckN(private val n: Int) extends AnyVal { - def apply[R <: TestConfig, A, In](rv: Gen[R, A])(test: A => In)(implicit + def apply[R <: ZAny, A, In](rv: Gen[R, A])(test: A => In)(implicit checkConstructor: CheckConstructor[R, In], trace: Trace ): ZIO[checkConstructor.OutEnvironment, checkConstructor.OutError, TestResult] = checkStream(rv.sample.forever.collectSome.take(n.toLong))(a => checkConstructor(test(a))) - def apply[R <: TestConfig, A, B, In](rv1: Gen[R, A], rv2: Gen[R, B])( + def apply[R <: ZAny, A, B, In](rv1: Gen[R, A], rv2: Gen[R, B])( test: (A, B) => In )(implicit checkConstructor: CheckConstructor[R, In], trace: Trace ): ZIO[checkConstructor.OutEnvironment, checkConstructor.OutError, TestResult] = checkN(n)(rv1 <*> rv2)(test.tupled) - def apply[R <: TestConfig, A, B, C, In](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C])( + def apply[R <: ZAny, A, B, C, In](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C])( test: (A, B, C) => In )(implicit checkConstructor: CheckConstructor[R, In], trace: Trace ): ZIO[checkConstructor.OutEnvironment, checkConstructor.OutError, TestResult] = checkN(n)(rv1 <*> rv2 <*> rv3)(test.tupled) - def apply[R <: TestConfig, A, B, C, D, In](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D])( + def apply[R <: ZAny, A, B, C, D, In](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D])( test: (A, B, C, D) => In )(implicit checkConstructor: CheckConstructor[R, In], trace: Trace ): ZIO[checkConstructor.OutEnvironment, checkConstructor.OutError, TestResult] = checkN(n)(rv1 <*> rv2 <*> rv3 <*> rv4)(test.tupled) - def apply[R <: TestConfig, A, B, C, D, F, In]( + def apply[R <: ZAny, A, B, C, D, F, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -799,7 +919,7 @@ package object test extends CompileVariants { trace: Trace ): ZIO[checkConstructor.OutEnvironment, checkConstructor.OutError, TestResult] = checkN(n)(rv1 <*> rv2 <*> rv3 <*> rv4 <*> rv5)(test.tupled) - def apply[R <: TestConfig, A, B, C, D, F, G, In]( + def apply[R <: ZAny, A, B, C, D, F, G, In]( rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], @@ -818,7 +938,7 @@ package object test extends CompileVariants { private def checkStream[R, R1 <: R, E, A](stream: ZStream[R, Nothing, Sample[R, A]])( test: A => ZIO[R1, E, TestResult] - )(implicit trace: Trace): ZIO[R1 with TestConfig, E, TestResult] = + )(implicit trace: Trace): ZIO[R1, E, TestResult] = TestConfig.shrinks.flatMap { shrinkStream { stream.zipWithIndex.mapZIO { case (initial, index) => @@ -833,7 +953,7 @@ package object test extends CompileVariants { private def shrinkStream[R, R1 <: R, E, A]( stream: ZStream[R1, Nothing, Sample[R1, Either[E, TestResult]]] - )(maxShrinks: Int)(implicit trace: Trace): ZIO[R1 with TestConfig, E, TestResult] = + )(maxShrinks: Int)(implicit trace: Trace): ZIO[R1, E, TestResult] = stream .dropWhile(!_.value.fold(_ => true, _.isFailure)) // Drop until we get to a failure .take(1) // Get the first failure @@ -851,7 +971,7 @@ package object test extends CompileVariants { private def checkStreamPar[R, R1 <: R, E, A](stream: ZStream[R, Nothing, Sample[R, A]], parallelism: Int)( test: A => ZIO[R1, E, TestResult] - )(implicit trace: Trace): ZIO[R1 with TestConfig, E, TestResult] = + )(implicit trace: Trace): ZIO[R1, E, TestResult] = TestConfig.shrinks.flatMap { shrinkStream { stream.zipWithIndex diff --git a/test/shared/src/main/scala/zio/test/poly/GenFractionalPoly.scala b/test/shared/src/main/scala/zio/test/poly/GenFractionalPoly.scala index f7520fa8ad19..faf0a1624701 100644 --- a/test/shared/src/main/scala/zio/test/poly/GenFractionalPoly.scala +++ b/test/shared/src/main/scala/zio/test/poly/GenFractionalPoly.scala @@ -17,7 +17,7 @@ package zio.test.poly import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.test.{Gen, Sized} +import zio.test.Gen import zio.Trace /** @@ -34,7 +34,7 @@ object GenFractionalPoly { * Constructs an instance of `GenFractionalPoly` using the specified `Gen` and * `Fractional` instances, existentially hiding the underlying type. */ - def apply[A](gen: Gen[Sized, A], num: Fractional[A]): GenFractionalPoly = + def apply[A](gen: Gen[Any, A], num: Fractional[A]): GenFractionalPoly = new GenFractionalPoly { type T = A val genT = gen diff --git a/test/shared/src/main/scala/zio/test/poly/GenIntegralPoly.scala b/test/shared/src/main/scala/zio/test/poly/GenIntegralPoly.scala index 3f54d78f8cb9..ea15f749b3a6 100644 --- a/test/shared/src/main/scala/zio/test/poly/GenIntegralPoly.scala +++ b/test/shared/src/main/scala/zio/test/poly/GenIntegralPoly.scala @@ -17,7 +17,7 @@ package zio.test.poly import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.test.{Gen, Sized} +import zio.test.Gen import zio.Trace /** @@ -34,7 +34,7 @@ object GenIntegralPoly { * Constructs an instance of `GenIntegralPoly` using the specified `Gen` and * `Integral` instances, existentially hiding the underlying type. */ - def apply[A](gen: Gen[Sized, A], num: Integral[A]): GenIntegralPoly = + def apply[A](gen: Gen[Any, A], num: Integral[A]): GenIntegralPoly = new GenIntegralPoly { type T = A val genT = gen diff --git a/test/shared/src/main/scala/zio/test/poly/GenNumericPoly.scala b/test/shared/src/main/scala/zio/test/poly/GenNumericPoly.scala index 9341f2ba3edf..18b592f6e305 100644 --- a/test/shared/src/main/scala/zio/test/poly/GenNumericPoly.scala +++ b/test/shared/src/main/scala/zio/test/poly/GenNumericPoly.scala @@ -17,7 +17,7 @@ package zio.test.poly import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.test.{Gen, Sized} +import zio.test.Gen import zio.Trace /** @@ -35,7 +35,7 @@ object GenNumericPoly { * Constructs an instance of `GenIntegralPoly` using the specified `Gen` and * `Numeric` instances, existentially hiding the underlying type. */ - def apply[A](gen: Gen[Sized, A], num: Numeric[A]): GenNumericPoly = + def apply[A](gen: Gen[Any, A], num: Numeric[A]): GenNumericPoly = new GenNumericPoly { type T = A val genT = gen diff --git a/test/shared/src/main/scala/zio/test/poly/GenOrderingPoly.scala b/test/shared/src/main/scala/zio/test/poly/GenOrderingPoly.scala index 3f9076441b5b..066e9804e24e 100644 --- a/test/shared/src/main/scala/zio/test/poly/GenOrderingPoly.scala +++ b/test/shared/src/main/scala/zio/test/poly/GenOrderingPoly.scala @@ -17,7 +17,7 @@ package zio.test.poly import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.test.{Gen, Sized} +import zio.test.Gen import zio.{Random, Trace} import scala.annotation.tailrec @@ -36,7 +36,7 @@ object GenOrderingPoly { * Constructs an instance of `GenOrderingPoly` using the specified `Gen` and * `Ordering` instances, existentially hiding the underlying type. */ - def apply[A](gen: Gen[Sized, A], ord: Ordering[A]): GenOrderingPoly = + def apply[A](gen: Gen[Any, A], ord: Ordering[A]): GenOrderingPoly = new GenOrderingPoly { type T = A val genT = gen diff --git a/test/shared/src/main/scala/zio/test/poly/GenPoly.scala b/test/shared/src/main/scala/zio/test/poly/GenPoly.scala index 9dabce3813bf..0eadc99b6d73 100644 --- a/test/shared/src/main/scala/zio/test/poly/GenPoly.scala +++ b/test/shared/src/main/scala/zio/test/poly/GenPoly.scala @@ -17,7 +17,7 @@ package zio.test.poly import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.test.{Gen, Sized} +import zio.test.Gen import zio.Trace /** @@ -52,21 +52,21 @@ import zio.Trace * Using it we can define polymorphic generators for expressions: * * {{{ - * def genValue(t: GenPoly): Gen[Sized, Expr[t.T]] = + * def genValue(t: GenPoly): Gen[Any, Expr[t.T]] = * t.genT.map(Value(_)) * - * def genMapping(t: GenPoly): Gen[Sized, Expr[t.T]] = + * def genMapping(t: GenPoly): Gen[Any, Expr[t.T]] = * Gen.suspend { * GenPoly.genPoly.flatMap { t0 => * genExpr(t0).flatMap { expr => - * val genFunction: Gen[Sized, t0.T => t.T] = Gen.function(t.genT) - * val genExpr1: Gen[Sized, Expr[t.T]] = genFunction.map(f => Mapping(expr, f)) + * val genFunction: Gen[Any, t0.T => t.T] = Gen.function(t.genT) + * val genExpr1: Gen[Any, Expr[t.T]] = genFunction.map(f => Mapping(expr, f)) * genExpr1 * } * } * } * - * def genExpr(t: GenPoly): Gen[Sized, Expr[t.T]] = + * def genExpr(t: GenPoly): Gen[Any, Expr[t.T]] = * Gen.oneOf(genMapping(t), genValue(t)) * }}} * @@ -91,7 +91,7 @@ import zio.Trace */ trait GenPoly { type T - val genT: Gen[Sized, T] + val genT: Gen[Any, T] } object GenPoly { @@ -100,7 +100,7 @@ object GenPoly { * Constructs an instance of `TypeWith` using the specified value, * existentially hiding the underlying type. */ - def apply[A](gen: Gen[Sized, A]): GenPoly = + def apply[A](gen: Gen[Any, A]): GenPoly = new GenPoly { type T = A val genT = gen