diff --git a/modules/core/shared/src/test/scala/InMemory.scala b/modules/core/shared/src/test/scala/InMemory.scala index eecc8a13..a2f600a1 100644 --- a/modules/core/shared/src/test/scala/InMemory.scala +++ b/modules/core/shared/src/test/scala/InMemory.scala @@ -7,7 +7,7 @@ package natchez import java.net.URI import cats.data.{Chain, Kleisli} -import cats.effect.{IO, Ref, Resource} +import cats.effect.{IO, MonadCancelThrow, Ref, Resource} import natchez.Span.Options import munit.CatsEffectSuite @@ -118,15 +118,15 @@ trait InMemorySuite extends CatsEffectSuite { val NatchezCommand = InMemory.NatchezCommand trait TraceTest { - def program[F[_]: Trace]: F[Unit] + def program[F[_]: MonadCancelThrow: Trace]: F[Unit] def expectedHistory: List[(Lineage, NatchezCommand)] } def traceTest(name: String, tt: TraceTest) = { test(s"$name - Kleisli")( - testTraceKleisli(tt.program[Kleisli[IO, Span[IO], *]](_), tt.expectedHistory) + testTraceKleisli(tt.program[Kleisli[IO, Span[IO], *]](implicitly, _), tt.expectedHistory) ) - test(s"$name - IOLocal")(testTraceIoLocal(tt.program[IO](_), tt.expectedHistory)) + test(s"$name - IOLocal")(testTraceIoLocal(tt.program[IO](implicitly, _), tt.expectedHistory)) } def testTraceKleisli( diff --git a/modules/core/shared/src/test/scala/SpanCoalesceTest.scala b/modules/core/shared/src/test/scala/SpanCoalesceTest.scala index a4c693e9..ac44a0f0 100644 --- a/modules/core/shared/src/test/scala/SpanCoalesceTest.scala +++ b/modules/core/shared/src/test/scala/SpanCoalesceTest.scala @@ -4,12 +4,14 @@ package natchez +import cats.effect.MonadCancelThrow + class SpanCoalesceTest extends InMemorySuite { traceTest( "suppress - nominal", new TraceTest { - def program[F[_]: Trace] = { + def program[F[_]: MonadCancelThrow: Trace] = { def detailed = Trace[F].span("parent")(Trace[F].span("child")(Trace[F].put("answer" -> 42))) Trace[F].span("suppressed", Span.Options.Suppress)(detailed) @@ -27,7 +29,7 @@ class SpanCoalesceTest extends InMemorySuite { traceTest( "coaslesce - nominal", new TraceTest { - def program[F[_]: Trace] = { + def program[F[_]: MonadCancelThrow: Trace] = { def detailed = Trace[F].span("parent")(Trace[F].span("child")(Trace[F].put("answer" -> 42))) Trace[F].span("coalesced", Span.Options.Coalesce)(detailed) diff --git a/modules/core/shared/src/test/scala/SpanPropagationTest.scala b/modules/core/shared/src/test/scala/SpanPropagationTest.scala index 13893e74..9d698121 100644 --- a/modules/core/shared/src/test/scala/SpanPropagationTest.scala +++ b/modules/core/shared/src/test/scala/SpanPropagationTest.scala @@ -4,12 +4,15 @@ package natchez +import cats.effect.MonadCancelThrow +import cats.syntax.all._ + class SpanPropagationTest extends InMemorySuite { traceTest( "propagation", new TraceTest { - def program[F[_]: Trace] = + def program[F[_]: MonadCancelThrow: Trace] = Trace[F].span("parent")(Trace[F].span("child")(Trace[F].put("answer" -> 42))) def expectedHistory = List( @@ -23,4 +26,27 @@ class SpanPropagationTest extends InMemorySuite { ) } ) + + traceTest( + "spanR", + new TraceTest { + def program[F[_]: MonadCancelThrow: Trace] = + Trace[F].spanR("spanR").use { f => + Trace[F].span("span")( + f(Trace[F].put("question" -> "ultimate")) *> Trace[F].put("answer" -> 42) + ) + } + + def expectedHistory = List( + (Lineage.Root, NatchezCommand.CreateRootSpan("root", Kernel(Map()))), + (Lineage.Root, NatchezCommand.CreateSpan("spanR", None)), + (Lineage.Root, NatchezCommand.CreateSpan("span", None)), + (Lineage.Root / "spanR", NatchezCommand.Put(List("question" -> "ultimate"))), + (Lineage.Root / "span", NatchezCommand.Put(List("answer" -> 42))), + (Lineage.Root, NatchezCommand.ReleaseSpan("span")), + (Lineage.Root, NatchezCommand.ReleaseSpan("spanR")), + (Lineage.Root, NatchezCommand.ReleaseRootSpan("root")) + ) + } + ) }