diff --git a/compat/compat-java-time/src/jvmMain/kotlin/JavaTime.kt b/compat/compat-java-time/src/jvmMain/kotlin/JavaTime.kt index 3ae7a5e..7ca0771 100644 --- a/compat/compat-java-time/src/jvmMain/kotlin/JavaTime.kt +++ b/compat/compat-java-time/src/jvmMain/kotlin/JavaTime.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2025, OpenSavvy and contributors. + * Copyright (c) 2023-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import java.time.Clock import java.time.Instant import java.time.ZoneId import java.time.ZoneOffset +import kotlin.time.Duration.Companion.milliseconds @ExperimentalCoroutinesApi private class JavaClock(private val scheduler: TestCoroutineScheduler, private val timeZone: ZoneId) : Clock() { @@ -94,5 +95,5 @@ suspend fun Time.set(instant: Instant) { suspend fun Time.delayUntil(instant: Instant) { val diff = instant.toEpochMilli() - nowMillis require(diff >= 0) { "Cannot delay until $instant, which is in the past of the current virtual time, $nowJava" } - delay(diff) + delay(diff.milliseconds) } diff --git a/runners/runner-kotest/src/commonTest/kotlin/KotestTest.kt b/runners/runner-kotest/src/commonTest/kotlin/KotestTest.kt index b4ad6bd..e8a6c6b 100644 --- a/runners/runner-kotest/src/commonTest/kotlin/KotestTest.kt +++ b/runners/runner-kotest/src/commonTest/kotlin/KotestTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2025, OpenSavvy and contributors. + * Copyright (c) 2023-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package opensavvy.prepared.runner.kotest import io.kotest.core.spec.style.StringSpec import kotlinx.coroutines.delay import opensavvy.prepared.suite.config.Ignored +import kotlin.time.Duration.Companion.milliseconds class KotestTest : StringSpec({ // Vanilla Kotest declarations… @@ -27,6 +28,7 @@ class KotestTest : StringSpec({ } "Hello world from Kotest" { + @Suppress("SimplifyBooleanWithConstants") check("hello".length == 5) } @@ -35,7 +37,7 @@ class KotestTest : StringSpec({ suite("Prepared") { suite("Nested") { test("Prepared") { - delay(1000) + delay(1000.milliseconds) println("Done") } diff --git a/runners/runner-kotlin-test/src/commonTest/kotlin/AsyncTest.kt b/runners/runner-kotlin-test/src/commonTest/kotlin/AsyncTest.kt index 160f204..8fd132f 100644 --- a/runners/runner-kotlin-test/src/commonTest/kotlin/AsyncTest.kt +++ b/runners/runner-kotlin-test/src/commonTest/kotlin/AsyncTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2025, OpenSavvy and contributors. + * Copyright (c) 2023-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,19 +20,20 @@ import kotlinx.coroutines.delay import opensavvy.prepared.suite.SuiteDsl import opensavvy.prepared.suite.launch import opensavvy.prepared.suite.launchInBackground +import kotlin.time.Duration.Companion.seconds class AsyncTest : TestExecutor() { override fun SuiteDsl.register() { test("Start a job and wait for it to finish") { launch { - delay(1000) + delay(1.seconds) println("Done") } } test("Start a job, but do not wait for it") { launchInBackground { - delay(1000) + delay(1.seconds) error("Not printed") } } diff --git a/runners/runner-kotlin-test/src/commonTest/kotlin/ExecuteTest.kt b/runners/runner-kotlin-test/src/commonTest/kotlin/ExecuteTest.kt index db1a481..a01cf7f 100644 --- a/runners/runner-kotlin-test/src/commonTest/kotlin/ExecuteTest.kt +++ b/runners/runner-kotlin-test/src/commonTest/kotlin/ExecuteTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2025, OpenSavvy and contributors. + * Copyright (c) 2023-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import opensavvy.prepared.suite.config.Ignored import opensavvy.prepared.suite.prepared import opensavvy.prepared.suite.shared import kotlin.random.Random +import kotlin.time.Duration.Companion.seconds @Suppress("unused") class ExecuteTest : TestExecutor() { @@ -42,7 +43,7 @@ class ExecuteTest : TestExecutor() { } val longTask by shared { - delay(10_000) + delay(10.seconds) } suite("Group of tests") { diff --git a/runners/runner-kotlin-test/src/commonTest/kotlin/TimeTest.kt b/runners/runner-kotlin-test/src/commonTest/kotlin/TimeTest.kt index 0026ab8..1325931 100644 --- a/runners/runner-kotlin-test/src/commonTest/kotlin/TimeTest.kt +++ b/runners/runner-kotlin-test/src/commonTest/kotlin/TimeTest.kt @@ -21,13 +21,14 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.launch import opensavvy.prepared.suite.* import kotlin.test.assertEquals +import kotlin.time.Duration.Companion.milliseconds @OptIn(ExperimentalCoroutinesApi::class) class TimeTest : TestExecutor() { override fun SuiteDsl.register() { test("Elapsed time") { val start = time.source.markNow() - delay(1000) + delay(1000.milliseconds) val end = start.elapsedNow() assertEquals(1000, end.inWholeMilliseconds) @@ -37,12 +38,12 @@ class TimeTest : TestExecutor() { var executed = false launchInBackground { - delay(1000) + delay(1000.milliseconds) executed = true } launchInBackground { - delay(1001) + delay(1001.milliseconds) error("Never executed!") } @@ -59,17 +60,17 @@ class TimeTest : TestExecutor() { test("Advance until idle") { launch { - delay(1000) + delay(1000.milliseconds) println("After 1 second") launch { - delay(3000) + delay(3000.milliseconds) println("After 4 seconds") } } launch { - delay(2000) + delay(2000.milliseconds) println("After 2 seconds") } @@ -80,7 +81,7 @@ class TimeTest : TestExecutor() { test("Set the time") { time.set("2023-09-20T15:58:17.151Z") - delay(1000) + delay(1000.milliseconds) assertEquals("2023-09-20T15:58:18.151Z", time.now.toString()) } diff --git a/runners/runner-test-initiative/src/commonMain/kotlin/Suite.kt b/runners/runner-test-initiative/src/commonMain/kotlin/Suite.kt index 9cc2ad0..66c861b 100644 --- a/runners/runner-test-initiative/src/commonMain/kotlin/Suite.kt +++ b/runners/runner-test-initiative/src/commonMain/kotlin/Suite.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import opensavvy.prepared.suite.config.TestConfig import opensavvy.prepared.suite.config.get import opensavvy.prepared.suite.config.plus import opensavvy.prepared.suite.runTestDslSuspend -import kotlin.coroutines.coroutineContext @ExperimentalKtiApi fun preparedSuite(@TestName name: String, block: SuiteDsl.() -> Unit): TestRoot = @@ -156,7 +155,7 @@ private sealed class PreparedTestTree { get() = name }) } catch (e: Exception) { - coroutineContext.ensureActive() + currentCoroutineContext().ensureActive() println("Failed with: $e") // In the future, report that in the test event somehow reporter.report(object : TestEvent.Failed { override val testName: String diff --git a/runners/runner-testballoon/src/commonTest/kotlin/TestBalloonTest.kt b/runners/runner-testballoon/src/commonTest/kotlin/TestBalloonTest.kt index 39f3b35..dd6f718 100644 --- a/runners/runner-testballoon/src/commonTest/kotlin/TestBalloonTest.kt +++ b/runners/runner-testballoon/src/commonTest/kotlin/TestBalloonTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import de.infix.testBalloon.framework.core.testSuite val TestBalloonSuite by testSuite { test("string length") { + @Suppress("SimplifyBooleanWithConstants") check(8 == "Test me!".length) } diff --git a/suite/src/commonMain/kotlin/Prepared.kt b/suite/src/commonMain/kotlin/Prepared.kt index 12e1fa4..6686dbe 100644 --- a/suite/src/commonMain/kotlin/Prepared.kt +++ b/suite/src/commonMain/kotlin/Prepared.kt @@ -156,7 +156,6 @@ class PreparedProvider internal constructor( /** * Provides a [Prepared] instance bound to the given [name]. */ - @Suppress("MemberVisibilityCanBePrivate") fun named(name: String) = Prepared(name = name, block = block, display = display) diff --git a/suite/src/commonMain/kotlin/assertions/Logs.kt b/suite/src/commonMain/kotlin/assertions/Logs.kt index 3de7294..9a10fde 100644 --- a/suite/src/commonMain/kotlin/assertions/Logs.kt +++ b/suite/src/commonMain/kotlin/assertions/Logs.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -120,6 +120,7 @@ suspend fun TestDsl.log(value: T): T { * * @param additionalInfo A lambda that generates a [String] that will be printed alongside the message. */ +@Suppress("RedundantSuspendModifier", "UnusedReceiverParameter") // In the future, we want to integrate logging facilities individual tests, these are necessary to avoid breaking the API then suspend fun TestDsl.log(value: T, additionalInfo: () -> String): T { val message = additionalInfo() diff --git a/suite/src/commonTest/kotlin/RandomTest.kt b/suite/src/commonTest/kotlin/RandomTest.kt index abc6912..67e36f6 100644 --- a/suite/src/commonTest/kotlin/RandomTest.kt +++ b/suite/src/commonTest/kotlin/RandomTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package opensavvy.prepared.suite import opensavvy.prepared.runner.testballoon.preparedSuite import opensavvy.prepared.suite.random.* +@Suppress("SimplifyBooleanWithConstants") val RandomTest by preparedSuite { test("Generate random values without setting a seed") {