From 0914107a03ed332bd492118e46f5cea4388b47ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sat, 24 Feb 2024 15:00:26 +0100 Subject: [PATCH] test(state): Migrate all tests to Prepared --- state-arrow/build.gradle.kts | 24 +++------- state-coroutines/build.gradle.kts | 31 +++++-------- state/build.gradle.kts | 24 +++------- .../commonTest/kotlin/ComprehensionsTest.kt | 45 +++++++------------ .../commonTest/kotlin/FailureEndToEndTest.kt | 1 - 5 files changed, 41 insertions(+), 84 deletions(-) diff --git a/state-arrow/build.gradle.kts b/state-arrow/build.gradle.kts index 34b14c7..88a55af 100644 --- a/state-arrow/build.gradle.kts +++ b/state-arrow/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UNUSED_VARIABLE") - plugins { alias(opensavvyConventions.plugins.base) alias(opensavvyConventions.plugins.kotlin.library) @@ -16,23 +14,15 @@ kotlin { iosX64() linuxX64() - sourceSets { - val commonMain by getting { - dependencies { - api(projects.state) - api(libs.arrow.core) - - implementation(projects.logger) - } - } + sourceSets.commonMain.dependencies { + api(projects.state) + api(libs.arrow.core) - val commonTest by getting { - dependencies { - implementation(projects.tester) + implementation(projects.logger) + } - api(libs.kotlinx.coroutines.test) - } - } + sourceSets.commonTest.dependencies { + implementation(projects.tester) } } diff --git a/state-coroutines/build.gradle.kts b/state-coroutines/build.gradle.kts index d422d21..5aeaaeb 100644 --- a/state-coroutines/build.gradle.kts +++ b/state-coroutines/build.gradle.kts @@ -16,26 +16,17 @@ kotlin { iosX64() linuxX64() - sourceSets { - val commonMain by getting { - dependencies { - api(projects.state) - api(libs.kotlinx.coroutines.core) - - api(projects.progress) - api(projects.progressCoroutines) - - implementation(projects.logger) - } - } - - val commonTest by getting { - dependencies { - implementation(projects.tester) - - api(libs.kotlinx.coroutines.test) - } - } + sourceSets.commonMain.dependencies { + api(projects.state) + api(libs.kotlinx.coroutines.core) + + api(projects.progressCoroutines) + + implementation(projects.logger) + } + + sourceSets.commonTest.dependencies { + implementation(projects.tester) } } diff --git a/state/build.gradle.kts b/state/build.gradle.kts index 031310a..1336d48 100644 --- a/state/build.gradle.kts +++ b/state/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UNUSED_VARIABLE") - plugins { alias(opensavvyConventions.plugins.base) alias(opensavvyConventions.plugins.kotlin.library) @@ -16,24 +14,16 @@ kotlin { iosX64() linuxX64() - sourceSets { - val commonMain by getting { - dependencies { - api(projects.progress) - - implementation(projects.logger) - } - } + sourceSets.commonMain.dependencies { + api(projects.progress) - val commonTest by getting { - dependencies { - implementation(projects.tester) + implementation(projects.logger) + } - implementation(projects.stateArrow) + sourceSets.commonTest.dependencies { + implementation(projects.tester) - api(libs.kotlinx.coroutines.test) - } - } + implementation(projects.stateArrow) } } diff --git a/state/src/commonTest/kotlin/ComprehensionsTest.kt b/state/src/commonTest/kotlin/ComprehensionsTest.kt index f5a83ef..df66fec 100644 --- a/state/src/commonTest/kotlin/ComprehensionsTest.kt +++ b/state/src/commonTest/kotlin/ComprehensionsTest.kt @@ -1,42 +1,29 @@ -@file:OptIn(ExperimentalCoroutinesApi::class, ExperimentalCoroutinesApi::class) - package opensavvy.state -import kotlinx.coroutines.ExperimentalCoroutinesApi +import io.kotest.matchers.shouldBe import kotlinx.coroutines.delay import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.toList -import kotlinx.coroutines.test.runTest -import kotlin.test.Test -import kotlin.test.assertEquals +import opensavvy.prepared.runner.kotest.PreparedSpec /** * This is a series of examples of how to combine state instances together. */ -class ComprehensionsTest { - - private fun strings() = flow { - emit("5") - delay(100) - emit("10") - delay(100) - emit("wtf") - } - - @Test - fun mapValue() = runTest { - val results = strings() - .map { it.toIntOrNull() } +@Suppress("unused") +class ComprehensionsTest : PreparedSpec({ + test("Map values") { + val input = flow { + emit("5") + delay(100) + + emit("10") + delay(100) + + emit("test") + }.map { it.toIntOrNull() } .toList() - val expected = listOf( - 5, - 10, - null, - ) - - assertEquals(expected, results) + input shouldBe listOf(5, 10, null) } - -} +}) diff --git a/state/src/commonTest/kotlin/FailureEndToEndTest.kt b/state/src/commonTest/kotlin/FailureEndToEndTest.kt index 8abb921..dcf23ca 100644 --- a/state/src/commonTest/kotlin/FailureEndToEndTest.kt +++ b/state/src/commonTest/kotlin/FailureEndToEndTest.kt @@ -13,7 +13,6 @@ import kotlin.jvm.JvmInline import kotlin.random.Random import kotlin.test.* -@OptIn(ExperimentalCoroutinesApi::class) class FailureEndToEndTest { private data class User( -- 2.51.2