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
14 changes: 3 additions & 11 deletions test/shared/src/main/scala/zio/test/TestExecutor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,10 @@ object TestExecutor {
): UIO[Summary] =
(for {
sink <- ZIO.service[ExecutionEventSink]
summary <- Ref.make[Summary](Summary.empty)
topParent = SuiteId.global
_ <- {
def processEvent(
event: ExecutionEvent
) =
summary.update(
_.add(event)
) *>
sink.process(
event
) *> eventHandlerZ.handle(event)
def processEvent(event: ExecutionEvent) =
sink.process(event) *> eventHandlerZ.handle(event)

def loop(
labels: List[String],
Expand Down Expand Up @@ -167,7 +159,7 @@ object TestExecutor {
} *> processEvent(topLevelFlush) *> TestDebug.deleteIfEmpty(fullyQualifiedName)

}
summary <- summary.get
summary <- sink.getSummary
} yield summary).provideLayer(sinkLayer)

private def extractAnnotations(result: Either[TestFailure[E], TestSuccess]) =
Expand Down
22 changes: 4 additions & 18 deletions test/shared/src/main/scala/zio/test/TestRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ import java.util.concurrent.TimeUnit
* require an environment `R` and may fail with an error `E`. Test runners
* require a test executor, a runtime configuration, and a reporter.
*/
final case class TestRunner[R, E](
executor: TestExecutor[R, E],
bootstrap: ULayer[ExecutionEventSink] = TestRunner.defaultBootstrap
) { self =>
final case class TestRunner[R, E](executor: TestExecutor[R, E]) { self =>

val runtime: Runtime[Any] = Runtime.default

Expand Down Expand Up @@ -61,15 +58,15 @@ final case class TestRunner[R, E](
*/
def run(spec: Spec[R, E])(implicit trace: Trace, unsafe: Unsafe): Unit =
runtime.unsafe
.run(self.run("Test Task name unavailable in this context.", spec).provideLayer(bootstrap))
.run(self.run("Test Task name unavailable in this context.", spec))
.getOrThrowFiberFailure()

/**
* An unsafe, asynchronous run of the specified spec.
*/
def runAsync(spec: Spec[R, E])(k: => Unit)(implicit trace: Trace, unsafe: Unsafe): Unit = {
val fiber =
runtime.unsafe.fork(self.run("Test Task name unavailable in this context.", spec).provideLayer(bootstrap))
runtime.unsafe.fork(self.run("Test Task name unavailable in this context.", spec))
fiber.unsafe.addObserver {
case Exit.Success(_) => k
case Exit.Failure(c) => throw FiberFailure(c)
Expand All @@ -80,17 +77,6 @@ final case class TestRunner[R, E](
* An unsafe, synchronous run of the specified spec.
*/
def runSync(spec: Spec[R, E])(implicit trace: Trace, unsafe: Unsafe): Exit[Nothing, Unit] =
runtime.unsafe.run(self.run("Test Task name unavailable in this context.", spec).unit.provideLayer(bootstrap))
runtime.unsafe.run(self.run("Test Task name unavailable in this context.", spec).unit)
}

private[test] def buildRuntime(implicit
trace: Trace
): ZIO[Scope, Nothing, Runtime[ExecutionEventSink]] =
bootstrap.toRuntime
}

object TestRunner {
private lazy val defaultBootstrap: ZLayer[Any, Nothing, ExecutionEventSink] = {
ExecutionEventSink.live(Console.ConsoleLive, ConsoleEventRenderer)
}
}