diff --git a/kmp-nativecoroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeCallbackTests.kt b/kmp-nativecoroutines-core/src/supportedTargetTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeCallbackTests.kt similarity index 100% rename from kmp-nativecoroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeCallbackTests.kt rename to kmp-nativecoroutines-core/src/supportedTargetTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeCallbackTests.kt diff --git a/kmp-nativecoroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeCancellableTests.kt b/kmp-nativecoroutines-core/src/supportedTargetTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeCancellableTests.kt similarity index 100% rename from kmp-nativecoroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeCancellableTests.kt rename to kmp-nativecoroutines-core/src/supportedTargetTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeCancellableTests.kt diff --git a/kmp-nativecoroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeFlowTests.kt b/kmp-nativecoroutines-core/src/supportedTargetTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeFlowTests.kt similarity index 74% rename from kmp-nativecoroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeFlowTests.kt rename to kmp-nativecoroutines-core/src/supportedTargetTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeFlowTests.kt index ce5dce3f..b04491aa 100644 --- a/kmp-nativecoroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeFlowTests.kt +++ b/kmp-nativecoroutines-core/src/supportedTargetTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeFlowTests.kt @@ -1,9 +1,11 @@ package com.rickclephas.kmp.nativecoroutines -import kotlinx.coroutines.* +import kotlinx.coroutines.CancellationException +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Job +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.flow -import kotlin.native.concurrent.AtomicInt import kotlin.native.concurrent.isFrozen import kotlin.test.* @@ -11,7 +13,7 @@ class NativeFlowTests { @Test fun `ensure frozen`() { - val flow = flow { } + val flow = flow { } assertFalse(flow.isFrozen, "Flow shouldn't be frozen yet") val nativeFlow = flow.asNativeFlow() assertTrue(nativeFlow.isFrozen, "NativeFlow should be frozen") @@ -19,11 +21,11 @@ class NativeFlowTests { } @Test - fun `ensure completion callback is invoked`() = runBlocking { - val flow = flow { } + fun `ensure completion callback is invoked`() = kotlinx.coroutines.runBlocking { + val flow = flow { } val job = Job() val nativeFlow = flow.asNativeFlow(CoroutineScope(job)) - val completionCount = AtomicInt(0) + val completionCount = kotlin.native.concurrent.AtomicInt(0) nativeFlow({ _, _ -> }, { error, _ -> assertNull(error, "Flow should complete without an error") completionCount.increment() @@ -33,12 +35,12 @@ class NativeFlowTests { } @Test - fun `ensure exceptions are received as errors`() = runBlocking { + fun `ensure exceptions are received as errors`() = kotlinx.coroutines.runBlocking { val exception = RandomException() val flow = flow { throw exception } val job = Job() val nativeFlow = flow.asNativeFlow(CoroutineScope(job)) - val completionCount = AtomicInt(0) + val completionCount = kotlin.native.concurrent.AtomicInt(0) nativeFlow({ _, _ -> }, { error, _ -> assertNotNull(error, "Flow should complete with an error") val kotlinException = error.userInfo["KotlinException"] @@ -50,26 +52,30 @@ class NativeFlowTests { } @Test - fun `ensure values are received`() = runBlocking { + fun `ensure values are received`() = kotlinx.coroutines.runBlocking { val values = listOf(RandomValue(), RandomValue(), RandomValue(), RandomValue()) val flow = flow { values.forEach { emit(it) } } val job = Job() val nativeFlow = flow.asNativeFlow(CoroutineScope(job)) - val receivedValueCount = AtomicInt(0) + val receivedValueCount = kotlin.native.concurrent.AtomicInt(0) nativeFlow({ value, _ -> assertSame(values[receivedValueCount.value], value, "Received incorrect value") receivedValueCount.increment() }, { _, _ -> }) job.children.forEach { it.join() } // Waits for the collection to complete - assertEquals(values.size, receivedValueCount.value, "Item callback should be called for every value") + assertEquals( + values.size, + receivedValueCount.value, + "Item callback should be called for every value" + ) } @Test - fun `ensure collection is cancelled`() = runBlocking { + fun `ensure collection is cancelled`() = kotlinx.coroutines.runBlocking { val flow = MutableSharedFlow() val job = Job() val nativeFlow = flow.asNativeFlow(CoroutineScope(job)) - val completionCount = AtomicInt(0) + val completionCount = kotlin.native.concurrent.AtomicInt(0) val cancel = nativeFlow({ _, _ -> }, { error, _ -> assertNotNull(error, "Flow should complete with an error") val exception = error.userInfo["KotlinException"] diff --git a/kmp-nativecoroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeSuspendTests.kt b/kmp-nativecoroutines-core/src/supportedTargetTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeSuspendTests.kt similarity index 80% rename from kmp-nativecoroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeSuspendTests.kt rename to kmp-nativecoroutines-core/src/supportedTargetTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeSuspendTests.kt index 40d14a7d..372da4ac 100644 --- a/kmp-nativecoroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeSuspendTests.kt +++ b/kmp-nativecoroutines-core/src/supportedTargetTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeSuspendTests.kt @@ -3,9 +3,7 @@ package com.rickclephas.kmp.nativecoroutines import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.delay -import kotlinx.coroutines.runBlocking import kotlin.coroutines.cancellation.CancellationException -import kotlin.native.concurrent.AtomicInt import kotlin.native.concurrent.isFrozen import kotlin.test.* @@ -31,12 +29,12 @@ class NativeSuspendTests { } @Test - fun `ensure correct result is received`() = runBlocking { + fun `ensure correct result is received`() = kotlinx.coroutines.runBlocking { val value = RandomValue() val job = Job() val nativeSuspend = nativeSuspend(CoroutineScope(job)) { delayAndReturn(100, value) } - val receivedResultCount = AtomicInt(0) - val receivedErrorCount = AtomicInt(0) + val receivedResultCount = kotlin.native.concurrent.AtomicInt(0) + val receivedErrorCount = kotlin.native.concurrent.AtomicInt(0) nativeSuspend({ receivedValue, _ -> assertSame(value, receivedValue, "Received incorrect value") receivedResultCount.increment() @@ -49,12 +47,12 @@ class NativeSuspendTests { } @Test - fun `ensure exceptions are received as errors`() = runBlocking { + fun `ensure exceptions are received as errors`() = kotlinx.coroutines.runBlocking { val exception = RandomException() val job = Job() val nativeSuspend = nativeSuspend(CoroutineScope(job)) { delayAndThrow(100, exception) } - val receivedResultCount = AtomicInt(0) - val receivedErrorCount = AtomicInt(0) + val receivedResultCount = kotlin.native.concurrent.AtomicInt(0) + val receivedErrorCount = kotlin.native.concurrent.AtomicInt(0) nativeSuspend({ _, _ -> receivedResultCount.increment() }, { error, _ -> @@ -69,11 +67,12 @@ class NativeSuspendTests { } @Test - fun `ensure function is cancelled`() = runBlocking { + fun `ensure function is cancelled`() = kotlinx.coroutines.runBlocking { val job = Job() - val nativeSuspend = nativeSuspend(CoroutineScope(job)) { delayAndReturn(5_000, RandomValue()) } - val receivedResultCount = AtomicInt(0) - val receivedErrorCount = AtomicInt(0) + val nativeSuspend = + nativeSuspend(CoroutineScope(job)) { delayAndReturn(5_000, RandomValue()) } + val receivedResultCount = kotlin.native.concurrent.AtomicInt(0) + val receivedErrorCount = kotlin.native.concurrent.AtomicInt(0) val cancel = nativeSuspend({ _, _ -> receivedResultCount.increment() }, { error, _ ->