-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into update/sbt-scalajs-1.13.0
- Loading branch information
Showing
10 changed files
with
144 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
59 changes: 59 additions & 0 deletions
59
modules/core-tests/shared/src/test/scala/InMemorySuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2019-2020 by Rob Norris and Contributors | ||
// This software is licensed under the MIT License (MIT). | ||
// For more information see LICENSE or https://opensource.org/licenses/MIT | ||
|
||
package natchez | ||
|
||
import cats.data.Kleisli | ||
import cats.effect.{IO, MonadCancelThrow} | ||
import munit.CatsEffectSuite | ||
import natchez.InMemory.Lineage.defaultRootName | ||
|
||
trait InMemorySuite extends CatsEffectSuite { | ||
type Lineage = InMemory.Lineage | ||
val Lineage = InMemory.Lineage | ||
type NatchezCommand = InMemory.NatchezCommand | ||
val NatchezCommand = InMemory.NatchezCommand | ||
|
||
trait TraceTest { | ||
def program[F[_]: MonadCancelThrow: Trace]: F[Unit] | ||
def expectedHistory: List[(Lineage, NatchezCommand)] | ||
} | ||
|
||
def traceTest(name: String, tt: TraceTest): Unit = { | ||
test(s"$name - Kleisli")( | ||
testTraceKleisli(tt.program[Kleisli[IO, Span[IO], *]](implicitly, _), tt.expectedHistory) | ||
) | ||
test(s"$name - IOLocal")(testTraceIoLocal(tt.program[IO](implicitly, _), tt.expectedHistory)) | ||
} | ||
|
||
def testTraceKleisli( | ||
traceProgram: Trace[Kleisli[IO, Span[IO], *]] => Kleisli[IO, Span[IO], Unit], | ||
expectedHistory: List[(Lineage, NatchezCommand)] | ||
): IO[Unit] = testTrace[Kleisli[IO, Span[IO], *]]( | ||
traceProgram, | ||
root => IO.pure(Trace[Kleisli[IO, Span[IO], *]] -> (k => k.run(root))), | ||
expectedHistory | ||
) | ||
|
||
def testTraceIoLocal( | ||
traceProgram: Trace[IO] => IO[Unit], | ||
expectedHistory: List[(Lineage, NatchezCommand)] | ||
): IO[Unit] = testTrace[IO](traceProgram, Trace.ioTrace(_).map(_ -> identity), expectedHistory) | ||
|
||
def testTrace[F[_]]( | ||
traceProgram: Trace[F] => F[Unit], | ||
makeTraceAndResolver: Span[IO] => IO[(Trace[F], F[Unit] => IO[Unit])], | ||
expectedHistory: List[(Lineage, NatchezCommand)] | ||
): IO[Unit] = | ||
InMemory.EntryPoint.create[IO].flatMap { ep => | ||
val traced = ep.root(defaultRootName).use { r => | ||
makeTraceAndResolver(r).flatMap { case (traceInstance, resolve) => | ||
resolve(traceProgram(traceInstance)) | ||
} | ||
} | ||
traced *> ep.ref.get.map { history => | ||
assertEquals(history.toList, expectedHistory) | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.