Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] add support for Gen/check #879

Merged
merged 1 commit into from
Dec 1, 2024
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
40 changes: 27 additions & 13 deletions kyo-test/shared/src/main/scala/kyo/test/KyoSpecAbstract.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,39 @@ abstract class KyoSpecAbstract[S] extends ZIOSpecAbstract:

def spec: Spec[Environment, Any]

def run[In: Flat](v: => In < S)(using Frame): ZIO[Environment, Throwable, In]
protected def run[In: Flat](v: => In < S)(using Frame): ZIO[Environment, Throwable, In]

def test[In <: TestResult: Flat](label: String)(assertion: => In < S)(using
final def test[In](label: String)(assertion: => In)(using
tc: TestConstructor[Nothing, In],
sl: SourceLocation,
tr: Trace,
fr: Frame
): Spec[Any, Throwable] =
Spec.labeled(
label,
Spec
.test(ZTest(label, run(assertion)), TestAnnotationMap.empty)
.annotate(trace, sl :: Nil)
)

def suite[In](label: String)(specs: In*)(using
tr: Trace
): tc.Out =
tc(label)(assertion)

final def suite[In](label: String)(specs: In*)(using
sc: SuiteConstructor[In],
sl: SourceLocation,
tr: Trace
): Spec[sc.OutEnvironment, sc.OutError] =
zio.test.suite(label)(specs*)

given KyoTestConstructor[S1 >: S, A <: TestResult: Flat](using Frame): TestConstructor.WithOut[Any, A < S1, Spec[Any, Throwable]] =
new TestConstructor[Any, A < S1]:
type Out = Spec[Any, Throwable]
def apply(
label: String
)(assertion: => A < S1)(using sl: SourceLocation, tr: Trace): Out =
Spec.labeled(
label,
Spec
.test(ZTest(label, run[A](assertion)), TestAnnotationMap.empty)
.annotate(trace, sl :: Nil)
)

given KyoCheckConstructor[S1 >: S, A <: TestResult: Flat](using Frame): CheckConstructor.WithOut[Any, A < S1, Any, Throwable] =
new CheckConstructor[Any, A < S1]:
type OutEnvironment = Any
type OutError = Throwable
def apply(input: => A < S1)(using Trace): ZIO[OutEnvironment, OutError, TestResult] = run(input)

end KyoSpecAbstract
24 changes: 23 additions & 1 deletion kyo-test/shared/src/test/scala/kyo/test/KyoSpecDefaultSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,29 @@ object KyoSpecDefaultSpec extends KyoSpecDefault:
test("Async.delay") {
Async.delay(Duration.Infinity)(assertCompletes)
} @@ TestAspect.timeout(Duration.Zero.toJava)
) @@ TestAspect.failing
) @@ TestAspect.failing,
suite("Gen")(
test("check1")(
check(Gen.boolean) { b =>
assertTrue(b == b)
}
),
test("check2")(
check(Gen.boolean, Gen.int) { (b, i) =>
assertTrue(b == b && i == i)
}
),
test("check3")(
check(Gen.boolean, Gen.int, Gen.string) { (b, i, s) =>
assertTrue(b == b && i == i && s == s)
}
),
test("checkKyo")(
check(Gen.boolean) { b =>
IO(assertTrue(b == b))
}
)
)
) @@ TestAspect.timed

end KyoSpecDefaultSpec
Loading