Skip to content

Commit

Permalink
Merge pull request #383 from vigoo/zio2-rc6
Browse files Browse the repository at this point in the history
ZIO 2.0.0 RC6
  • Loading branch information
vigoo authored May 5, 2022
2 parents 3d1ef51 + da44c3d commit 04c0411
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 68 deletions.
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ val scala213 = "2.13.8"
val scala3 = "3.1.2"

val zioVersion = "1.0.14"
val zio2Version = "2.0.0-RC5"
val zio2Version = "2.0.0-RC6"

val scalacOptions212 = Seq("-Ypartial-unification", "-deprecation", "-target:jvm-1.8")
val scalacOptions213 = Seq("-deprecation", "-target:jvm-1.8")
Expand Down Expand Up @@ -96,8 +96,8 @@ lazy val proxFS2 = Project("prox-fs2", file("prox-fs2")).settings(commonSettings

lazy val proxFS23 = Project("prox-fs2-3", file("prox-fs2-3")).settings(commonSettings(8)).settings(
libraryDependencies ++= Seq(
"co.fs2" %% "fs2-core" % "3.2.5",
"co.fs2" %% "fs2-io" % "3.2.5",
"co.fs2" %% "fs2-core" % "3.2.7",
"co.fs2" %% "fs2-io" % "3.2.7",

"dev.zio" %% "zio" % zioVersion % "test",
"dev.zio" %% "zio-test" % zioVersion % "test",
Expand Down Expand Up @@ -125,7 +125,7 @@ lazy val proxZStream2 = Project("prox-zstream-2", file("prox-zstream-2")).settin
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zio2Version,
"dev.zio" %% "zio-streams" % zio2Version,
"dev.zio" %% "zio-prelude" % "1.0.0-RC13",
"dev.zio" %% "zio-prelude" % "1.0.0-RC14",

"dev.zio" %% "zio-test" % zio2Version % "test",
"dev.zio" %% "zio-test-sbt" % zio2Version % "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ trait ProxZStream extends Prox {
implicit def transducerAsPipe[A, B](transducer: ZPipeline[Any, ProxError, A, B]): ProxPipe[A, B] =
(s: ProxStream[A]) => s.via(transducer)

implicit def transducerAsPipeThrowable[A, B](transducer: ZPipeline[Any, Throwable, A, B]): ProxPipe[A, B] =
(s: ProxStream[A]) => s.via(ZPipeline.fromChannel(transducer.channel.mapError(UnknownProxError.apply)))

implicit def sinkAsTransformAndSink[A](sink: ZSink[Any, ProxError, A, Any, Unit]): TransformAndSink[A, A] =
TransformAndSink(identity[ZStream[Any, ProxError, A]] _, sink)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object ProcessGroupSpecs extends ZIOSpecDefault with ProxSpecHelpers {
val processGroup = (Process("echo", List("This is a test string")) | Process("wc", List("-w"))) ># ZPipeline.utf8Decode
val program = processGroup.run().map(_.output.trim)

assertM(program)(equalTo("5"))
assertZIO(program)(equalTo("5"))
},

test("is possible with multiple") {
Expand All @@ -38,20 +38,24 @@ object ProcessGroupSpecs extends ZIOSpecDefault with ProxSpecHelpers {
r => r.output.map(_.stripLineEnd.trim).filter(_.nonEmpty)
)

assertM(program)(hasSameElements(List("1 apple")))
assertZIO(program)(hasSameElements(List("1 apple")))
},

test("is customizable with pipes") {
val customPipe = (s: zstream.ProxStream[Byte]) => s
.via(ZPipeline.utf8Decode >>> ZPipeline.splitLines)
.via(
ZPipeline.fromChannel(
(ZPipeline.utf8Decode >>> ZPipeline.splitLines).channel.mapError(UnknownProxError.apply)
)
)
.map(_.split(' ').toVector)
.map(v => v.map(_ + " !!!").mkString(" "))
.intersperse("\n")
.flatMap(s => ZStream.fromIterable(s.getBytes(StandardCharsets.UTF_8)))
val processGroup = Process("echo", List("This is a test string")).via(customPipe).to(Process("wc", List("-w"))) ># ZPipeline.utf8Decode
val program = processGroup.run().map(_.output.trim)

assertM(program)(equalTo("10"))
assertZIO(program)(equalTo("10"))
},

test("can be mapped") {
Expand All @@ -68,7 +72,7 @@ object ProcessGroupSpecs extends ZIOSpecDefault with ProxSpecHelpers {

val program = processGroup2.run().map(_.output.trim)

assertM(program)(equalTo("5"))
assertZIO(program)(equalTo("5"))
}
),

Expand All @@ -80,7 +84,7 @@ object ProcessGroupSpecs extends ZIOSpecDefault with ProxSpecHelpers {
Process("sort")
val program = ZIO.scoped { processGroup.start().flatMap { fiber => fiber.interrupt.unit } }

assertM(program)(equalTo(()))
assertZIO(program)(equalTo(()))
} @@ TestAspect.timeout(5.seconds),

test("can be terminated") {
Expand All @@ -95,7 +99,7 @@ object ProcessGroupSpecs extends ZIOSpecDefault with ProxSpecHelpers {
result <- runningProcesses.terminate()
} yield result.exitCodes.toList

assertM(program)(contains[(Process[Unit, Unit], ProxExitCode)](p1 -> ExitCode(1)))
assertZIO(program)(contains[(Process[Unit, Unit], ProxExitCode)](p1 -> ExitCode(1)))
} @@ withLiveClock,

test("can be killed") {
Expand All @@ -112,7 +116,7 @@ object ProcessGroupSpecs extends ZIOSpecDefault with ProxSpecHelpers {

// Note: we can't assert on the second process' exit code because there is a race condition
// between killing it directly and being stopped because of the upstream process got killed.
assertM(program)(
assertZIO(program)(
contains(p1 -> ExitCode(137)
))
} @@ withLiveClock
Expand All @@ -125,7 +129,7 @@ object ProcessGroupSpecs extends ZIOSpecDefault with ProxSpecHelpers {
val processGroup = (Process("cat") | Process("wc", List("-w"))) < stream ># ZPipeline.utf8Decode
val program = processGroup.run().map(_.output.trim)

assertM(program)(equalTo("5"))
assertZIO(program)(equalTo("5"))
},

test("can be fed with an input file") {
Expand All @@ -137,7 +141,7 @@ object ProcessGroupSpecs extends ZIOSpecDefault with ProxSpecHelpers {
result <- processGroup.run()
} yield result.output.trim

assertM(program)(equalTo("5"))
assertZIO(program)(equalTo("5"))
}
}
),
Expand All @@ -151,7 +155,7 @@ object ProcessGroupSpecs extends ZIOSpecDefault with ProxSpecHelpers {
contents <- ZStream.fromFile(tempFile, 1024).via(ZPipeline.utf8Decode).runFold("")(_ + _).mapError(UnknownProxError.apply)
} yield contents.trim

assertM(program)(equalTo("5"))
assertZIO(program)(equalTo("5"))
}
},
),
Expand Down Expand Up @@ -261,8 +265,8 @@ object ProcessGroupSpecs extends ZIOSpecDefault with ProxSpecHelpers {
val program = processGroup.run()

program.map { result =>
assert(result.errors.get(p1))(isSome(equalTo("P1: Hello"))) &&
assert(result.errors.get(p2))(isSome(equalTo("P2: world"))) &&
assert(result.errors.get(p1))(isSome(equalTo("P1: HelloP1: "))) &&
assert(result.errors.get(p2))(isSome(equalTo("P2: worldP2: "))) &&
assert(result.output)(equalTo(())) &&
assert(result.exitCodes.get(p1))(isSome(equalTo(ExitCode(0)))) &&
assert(result.exitCodes.get(p2))(isSome(equalTo(ExitCode(0))))
Expand Down Expand Up @@ -371,7 +375,7 @@ object ProcessGroupSpecs extends ZIOSpecDefault with ProxSpecHelpers {
contents2 <- ZStream.fromFile(tempFile2, 1024).via(ZPipeline.utf8Decode).runFold("")(_ + _).mapError(UnknownProxError.apply)
} yield (contents1, contents2)

assertM(program)(equalTo(("Hello", "world")))
assertZIO(program)(equalTo(("Hello", "world")))
}
}
},
Expand Down Expand Up @@ -482,7 +486,7 @@ object ProcessGroupSpecs extends ZIOSpecDefault with ProxSpecHelpers {
),

test("bound process is not pipeable") {
assertM(
assertZIO(
typeCheck("""val bad = (Process("echo", List("Hello world")) ># ZPipeline.utf8Decode) | Process("wc", List("-w"))"""))(
isLeft(anything)
)
Expand Down
Loading

0 comments on commit 04c0411

Please sign in to comment.