Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions core-tests/shared/src/test/scala/zio/ZIOAppSpec.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package zio

import zio.test._
import scala.annotation.nowarn

object ZIOAppSpec extends ZIOBaseSpec {
def spec = suite("ZIOAppSpec")(
Expand All @@ -13,12 +14,12 @@ object ZIOAppSpec extends ZIOBaseSpec {
},
test("failure translates into ExitCode.failure") {
for {
code <- ZIOApp.fromZIO(ZIO.fail("Uh oh!")).invoke(Chunk.empty).exitCode
code <- ZIOApp.fromZIO(ZIO.fail("Uh oh!")).invoke(Chunk.empty).exitCode: @nowarn("cat=deprecation")
} yield assertTrue(code == ExitCode.failure)
},
test("success translates into ExitCode.success") {
for {
code <- ZIOApp.fromZIO(ZIO.succeed("Hurray!")).invoke(Chunk.empty).exitCode
code <- ZIOApp.fromZIO(ZIO.succeed("Hurray!")).invoke(Chunk.empty).exitCode: @nowarn("cat=deprecation")
} yield assertTrue(code == ExitCode.success)
},
test("composed app logic runs component logic") {
Expand Down Expand Up @@ -52,7 +53,7 @@ object ZIOAppSpec extends ZIOBaseSpec {
val app1 = ZIOApp(ZIO.fail("Uh oh!"), Runtime.addLogger(logger1))

for {
c <- app1.invoke(Chunk.empty).exitCode
c <- app1.invoke(Chunk.empty).exitCode: @nowarn("cat=deprecation")
v <- ZIO.succeed(counter.get())
} yield assertTrue(c == ExitCode.failure) && assertTrue(v == 1)
},
Expand Down
5 changes: 4 additions & 1 deletion core/js/src/main/scala/zio/ZIOAppPlatformSpecific.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package zio

import zio.internal.stacktracer.Tracer
import zio.stacktracer.TracingImplicits.disableAutoTrace
import scala.annotation.nowarn

private[zio] trait ZIOAppPlatformSpecific { self: ZIOApp =>

Expand All @@ -21,7 +22,9 @@ private[zio] trait ZIOAppPlatformSpecific { self: ZIOApp =>
runtime <- ZIO.runtime[Environment with ZIOAppArgs]
_ <- installSignalHandlers(runtime)
_ <- runtime.run(ZIO.scoped[Environment with ZIOAppArgs](run)).tapErrorCause(ZIO.logErrorCause(_))
} yield ()).provideLayer(newLayer.tapErrorCause(ZIO.logErrorCause(_))).exitCode.tap(exit)
} yield ()).provideLayer(newLayer.tapErrorCause(ZIO.logErrorCause(_))).exitCode.tap(exit): @nowarn(
Copy link
Member

Choose a reason for hiding this comment

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

Do we need it here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The JVM/native version does not have this. I will followup with a separate PR if that's alright.

"cat=deprecation"
)
}
}
}
1 change: 1 addition & 0 deletions core/shared/src/main/scala/zio/ZIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ sealed trait ZIO[-R, +E, +A]
/**
* Maps this effect to the default exit codes.
*/
@deprecated("This operator swallows errors and is no longer necessary to create a ZIO App.", "2.1.20")
final def exitCode(implicit trace: Trace): URIO[R, ExitCode] =
self.foldCause(
_ => ExitCode.failure,
Expand Down
26 changes: 16 additions & 10 deletions test-tests/shared/src/test/scala/zio/test/ZIOSpecAbstractSpec.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package zio.test
import zio.{Scope, ZIO, ZIOAppArgs, ZLayer}
import zio.internal.ansi.AnsiStringOps
import scala.annotation.nowarn

object ZIOSpecAbstractSpec extends ZIOBaseSpec {
private val basicSpec: ZIOSpecAbstract = new ZIOSpecDefault {
Expand Down Expand Up @@ -32,22 +33,22 @@ object ZIOSpecAbstractSpec extends ZIOBaseSpec {
.runSpecAsApp(composedSpec.spec, TestArgs.empty, console)
.provideSome[zio.Scope with TestEnvironment](composedSpec.bootstrap)
.catchAllCause(t => console.printLine(t.toString))
.exitCode
.exitCode: @nowarn("cat=deprecation")
}
output <- TestConsole.output.map(_.mkString("\n"))
} yield assertTrue(output.contains("scala.NotImplementedError: an implementation is missing")) &&
assertTrue(
// Brittle with the line numbers
// number of line with "override val bootstrap = ZLayer.fromZIO(ZIO.attempt(???))"
output.contains("ZIOSpecAbstractSpec.scala:22")
output.contains("ZIOSpecAbstractSpec.scala:23")
) &&
assertTrue(
// number of line with "_ <- ZIO.consoleWith { console =>"
output.contains("ZIOSpecAbstractSpec.scala:30")
output.contains("ZIOSpecAbstractSpec.scala:31")
) &&
assertTrue(
// number of line with ".provideSome[zio.Scope with TestEnvironment](composedSpec.bootstrap)"
output.contains("ZIOSpecAbstractSpec.scala:33")
output.contains("ZIOSpecAbstractSpec.scala:34")
)
} @@ TestAspect.flaky @@ TestAspect.silent @@ TestAspect.scala2Only,
test("highlighting composed layer failures - scala 3") {
Expand All @@ -66,22 +67,22 @@ object ZIOSpecAbstractSpec extends ZIOBaseSpec {
.runSpecAsApp(composedSpec.spec, TestArgs.empty, console)
.provideSome[zio.Scope with TestEnvironment](composedSpec.bootstrap)
.catchAllCause(t => console.printLine(t.toString))
.exitCode
.exitCode: @nowarn("cat=deprecation")
}
output <- TestConsole.output.map(_.mkString("\n"))
} yield assertTrue(output.contains("scala.NotImplementedError: an implementation is missing")) &&
assertTrue(
// Brittle with the line numbers
// number of line with "override val bootstrap = ZLayer.fromZIO(ZIO.attempt(???))"
output.contains("ZIOSpecAbstractSpec.scala:56")
output.contains("ZIOSpecAbstractSpec.scala:57")
) &&
assertTrue(
// number of line next to "_ <- ZIO.consoleWith { console =>"
output.contains("ZIOSpecAbstractSpec.scala:65")
output.contains("ZIOSpecAbstractSpec.scala:66")
) &&
assertTrue(
// number of line next to ".provideSome[zio.Scope with TestEnvironment](composedSpec.bootstrap)"
output.contains("ZIOSpecAbstractSpec.scala:68")
output.contains("ZIOSpecAbstractSpec.scala:69")
)
} @@ TestAspect.flaky @@ TestAspect.silent @@ TestAspect.scala3Only,
test("run method reports successes sanely")(
Expand All @@ -106,12 +107,17 @@ object ZIOSpecAbstractSpec extends ZIOBaseSpec {
},
test("run method reports exitcode=1 sanely")(
for {
exitCode <- basicFailSpec.run.provideSome[zio.ZIOAppArgs with zio.Scope](basicFailSpec.bootstrap).exitCode
exitCode <-
basicFailSpec.run.provideSome[zio.ZIOAppArgs with zio.Scope](basicFailSpec.bootstrap).exitCode: @nowarn(
"cat=deprecation"
)
} yield assertTrue(exitCode.code == 1)
),
test("run method reports exitcode=0 sanely")(
for {
exitCode <- basicSpec.run.provideSome[zio.ZIOAppArgs with zio.Scope](basicSpec.bootstrap).exitCode
exitCode <- basicSpec.run.provideSome[zio.ZIOAppArgs with zio.Scope](basicSpec.bootstrap).exitCode: @nowarn(
"cat=deprecation"
)
} yield assertTrue(exitCode.code == 0)
)
)
Expand Down