From 1df8f7273199e34e7ca94e461d61dde418cf00eb Mon Sep 17 00:00:00 2001 From: Michael Bull Date: Sun, 10 Mar 2024 23:20:34 +0000 Subject: [PATCH] Run coroutine tests on all platforms Some were previously restricted to specific platforms, however kotlinx-coroutines-test now targets them all. --- .../RunSuspendCatchingTest.kt | 0 .../binding/AsyncSuspendableBindingTest.kt | 6 +- .../binding/AsyncSuspendableBindingTest.kt | 118 ------------------ 3 files changed, 3 insertions(+), 121 deletions(-) rename kotlin-result-coroutines/src/{jvmTest/kotlin/com/github/michaelbull/result/coroutines => commonTest/kotlin/com.github.michaelbull.result.coroutines}/RunSuspendCatchingTest.kt (100%) rename kotlin-result-coroutines/src/{jvmTest/kotlin/com/github/michaelbull/result/coroutines => commonTest/kotlin/com.github.michaelbull.result.coroutines}/binding/AsyncSuspendableBindingTest.kt (97%) delete mode 100644 kotlin-result-coroutines/src/jsTest/kotlin/com.github.michaelbull.result.coroutines/binding/AsyncSuspendableBindingTest.kt diff --git a/kotlin-result-coroutines/src/jvmTest/kotlin/com/github/michaelbull/result/coroutines/RunSuspendCatchingTest.kt b/kotlin-result-coroutines/src/commonTest/kotlin/com.github.michaelbull.result.coroutines/RunSuspendCatchingTest.kt similarity index 100% rename from kotlin-result-coroutines/src/jvmTest/kotlin/com/github/michaelbull/result/coroutines/RunSuspendCatchingTest.kt rename to kotlin-result-coroutines/src/commonTest/kotlin/com.github.michaelbull.result.coroutines/RunSuspendCatchingTest.kt diff --git a/kotlin-result-coroutines/src/jvmTest/kotlin/com/github/michaelbull/result/coroutines/binding/AsyncSuspendableBindingTest.kt b/kotlin-result-coroutines/src/commonTest/kotlin/com.github.michaelbull.result.coroutines/binding/AsyncSuspendableBindingTest.kt similarity index 97% rename from kotlin-result-coroutines/src/jvmTest/kotlin/com/github/michaelbull/result/coroutines/binding/AsyncSuspendableBindingTest.kt rename to kotlin-result-coroutines/src/commonTest/kotlin/com.github.michaelbull.result.coroutines/binding/AsyncSuspendableBindingTest.kt index d04a356..866f6ff 100644 --- a/kotlin-result-coroutines/src/jvmTest/kotlin/com/github/michaelbull/result/coroutines/binding/AsyncSuspendableBindingTest.kt +++ b/kotlin-result-coroutines/src/commonTest/kotlin/com.github.michaelbull.result.coroutines/binding/AsyncSuspendableBindingTest.kt @@ -17,9 +17,9 @@ import kotlin.test.assertTrue @ExperimentalCoroutinesApi class AsyncSuspendableBindingTest { - private sealed class BindingError { - data object BindingErrorA : BindingError() - data object BindingErrorB : BindingError() + private sealed interface BindingError { + data object BindingErrorA : BindingError + data object BindingErrorB : BindingError } @Test diff --git a/kotlin-result-coroutines/src/jsTest/kotlin/com.github.michaelbull.result.coroutines/binding/AsyncSuspendableBindingTest.kt b/kotlin-result-coroutines/src/jsTest/kotlin/com.github.michaelbull.result.coroutines/binding/AsyncSuspendableBindingTest.kt deleted file mode 100644 index 1b77609..0000000 --- a/kotlin-result-coroutines/src/jsTest/kotlin/com.github.michaelbull.result.coroutines/binding/AsyncSuspendableBindingTest.kt +++ /dev/null @@ -1,118 +0,0 @@ -package com.github.michaelbull.result.coroutines.binding - -import com.github.michaelbull.result.Err -import com.github.michaelbull.result.Ok -import com.github.michaelbull.result.Result -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.async -import kotlinx.coroutines.delay -import kotlinx.coroutines.test.runTest -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertTrue - -@ExperimentalCoroutinesApi -class AsyncSuspendableBindingTest { - - private sealed interface BindingError { - data object BindingErrorA : BindingError - data object BindingErrorB : BindingError - } - - @Test - fun returnsOkIfAllBindsSuccessful() = runTest { - suspend fun provideX(): Result { - delay(100) - return Ok(1) - } - - suspend fun provideY(): Result { - delay(100) - return Ok(2) - } - - val result = binding { - val x = async { provideX().bind() } - val y = async { provideY().bind() } - x.await() + y.await() - } - - assertEquals( - expected = Ok(3), - actual = result, - ) - } - - @Test - fun returnsFirstErrIfBindingFailed() = runTest { - suspend fun provideX(): Result { - delay(10) - return Ok(1) - } - - suspend fun provideY(): Result { - delay(20) - return Err(BindingError.BindingErrorA) - } - - suspend fun provideZ(): Result { - delay(1) - return Err(BindingError.BindingErrorB) - } - - val result = binding { - val x = async { provideX().bind() } - val y = async { provideY().bind() } - val z = async { provideZ().bind() } - x.await() + y.await() + z.await() - } - - assertEquals( - expected = Err(BindingError.BindingErrorB), - actual = result - ) - } - - @Test - fun returnsStateChangedForOnlyTheFirstAsyncBindFailWhenEagerlyCancellingBinding() = runTest { - var xStateChange = false - var yStateChange = false - var zStateChange = false - - suspend fun provideX(): Result { - delay(20) - xStateChange = true - return Ok(1) - } - - suspend fun provideY(): Result { - delay(10) - yStateChange = true - return Err(BindingError.BindingErrorA) - } - - suspend fun provideZ(): Result { - delay(1) - zStateChange = true - return Err(BindingError.BindingErrorB) - } - - val result = binding { - val x = async { provideX().bind() } - val y = async { provideY().bind() } - val z = async { provideZ().bind() } - - x.await() + y.await() + z.await() - } - - assertEquals( - expected = Err(BindingError.BindingErrorB), - actual = result, - ) - - assertFalse(xStateChange) - assertFalse(yStateChange) - assertTrue(zStateChange) - } -}