diff --git a/kmp-nativecoroutines-core/src/appleMain/kotlin/com/rickclephas/kmp/nativecoroutines/NSError.kt b/kmp-nativecoroutines-core/src/appleMain/kotlin/com/rickclephas/kmp/nativecoroutines/NSError.kt index df2fbc2e..ea6443cb 100644 --- a/kmp-nativecoroutines-core/src/appleMain/kotlin/com/rickclephas/kmp/nativecoroutines/NSError.kt +++ b/kmp-nativecoroutines-core/src/appleMain/kotlin/com/rickclephas/kmp/nativecoroutines/NSError.kt @@ -26,6 +26,3 @@ internal actual fun Throwable.asNativeError(): NativeError { } return NSError.errorWithDomain("KotlinException", 0.convert(), userInfo) } - -internal actual val NativeError.kotlinCause - get() = this.userInfo["KotlinException"] as? Throwable diff --git a/kmp-nativecoroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NSErrorTests.kt b/kmp-nativecoroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NSErrorTests.kt index 96916dd3..6bd018d3 100644 --- a/kmp-nativecoroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NSErrorTests.kt +++ b/kmp-nativecoroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NSErrorTests.kt @@ -2,20 +2,12 @@ package com.rickclephas.kmp.nativecoroutines import kotlinx.cinterop.UnsafeNumber import kotlinx.cinterop.convert -import kotlin.native.concurrent.isFrozen import kotlin.test.* -class NSErrorTests { - - @Test - fun `ensure frozen`() { - val exception = RandomException() - assertFalse(exception.isFrozen, "Exception shouldn't be frozen yet") - val nsError = exception.asNativeError() - assertTrue(nsError.isFrozen, "NSError should be frozen") - assertTrue(exception.isFrozen, "Exception should be frozen") - } +internal actual val NativeError.kotlinCause + get() = this.userInfo["KotlinException"] as? Throwable +class NSErrorTests { @Test @OptIn(UnsafeNumber::class) fun `ensure NSError domain and code are correct`() { @@ -32,11 +24,4 @@ class NSErrorTests { assertEquals(exception.message, nsError.localizedDescription, "Localized description isn't set to message") } - - @Test - fun `ensure exception is part of user info`() { - val exception = RandomException() - val nsError = exception.asNativeError() - assertSame(exception, nsError.kotlinCause, "Exception isn't part of the user info") - } } \ No newline at end of file diff --git a/kmp-nativecoroutines-core/src/nativeCoroutinesMain/kotlin/com/rickclephas/kmp/nativecoroutines/NativeError.kt b/kmp-nativecoroutines-core/src/nativeCoroutinesMain/kotlin/com/rickclephas/kmp/nativecoroutines/NativeError.kt index 393f986c..0c44b12b 100644 --- a/kmp-nativecoroutines-core/src/nativeCoroutinesMain/kotlin/com/rickclephas/kmp/nativecoroutines/NativeError.kt +++ b/kmp-nativecoroutines-core/src/nativeCoroutinesMain/kotlin/com/rickclephas/kmp/nativecoroutines/NativeError.kt @@ -9,5 +9,3 @@ expect class NativeError * Converts a [Throwable] to a [NativeError]. */ internal expect fun Throwable.asNativeError(): NativeError - -internal expect val NativeError.kotlinCause: Throwable? \ No newline at end of file diff --git a/kmp-nativecoroutines-core/src/nativeCoroutinesTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeErrorTests.kt b/kmp-nativecoroutines-core/src/nativeCoroutinesTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeErrorTests.kt new file mode 100644 index 00000000..f9346c1f --- /dev/null +++ b/kmp-nativecoroutines-core/src/nativeCoroutinesTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeErrorTests.kt @@ -0,0 +1,27 @@ +package com.rickclephas.kmp.nativecoroutines + +import kotlin.native.concurrent.isFrozen +import kotlin.test.* + +/** + * Get the [Throwable] that is represented by the given [NativeError] + */ +internal expect val NativeError.kotlinCause: Throwable? + +class NativeErrorTests { + @Test + fun `ensure frozen`() { + val exception = RandomException() + assertFalse(exception.isFrozen, "Exception shouldn't be frozen yet") + val nsError = exception.asNativeError() + assertTrue(nsError.isFrozen, "NSError should be frozen") + assertTrue(exception.isFrozen, "Exception should be frozen") + } + + @Test + fun `ensure exception is part of user info`() { + val exception = RandomException() + val nsError = exception.asNativeError() + assertSame(exception, nsError.kotlinCause, "Exception isn't part of the NativeError") + } +}