-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/GH-42-swift-to-kotlin-wrappers
- Loading branch information
Showing
25 changed files
with
249 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...oroutines-core/src/appleMain/kotlin/com/rickclephas/kmp/nativecoroutines/FreezingApple.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.rickclephas.kmp.nativecoroutines | ||
|
||
import kotlin.native.concurrent.freeze | ||
|
||
actual fun <T> T.freeze(): T = this.freeze() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...utines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/KotlinCauseApple.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.rickclephas.kmp.nativecoroutines | ||
|
||
internal actual val NativeError.kotlinCause: Throwable? | ||
get() = this.userInfo["KotlinException"] as? Throwable |
22 changes: 22 additions & 0 deletions
22
...ore/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeCallbackAppleTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.rickclephas.kmp.nativecoroutines | ||
|
||
import kotlin.native.concurrent.isFrozen | ||
import kotlin.test.* | ||
|
||
class NativeCallbackAppleTests { | ||
|
||
@Test | ||
fun ensureFrozen() { | ||
var receivedValue: RandomValue? = null | ||
val callback: NativeCallback<RandomValue> = callback@{ value, unit -> | ||
receivedValue = value | ||
// This isn't required in Kotlin, but it is in Swift, so we'll test it anyway | ||
return@callback unit | ||
} | ||
val value = RandomValue() | ||
assertFalse(value.isFrozen, "Value shouldn't be frozen yet") | ||
callback(value) | ||
assertTrue(value.isFrozen, "Value should be frozen") | ||
assertTrue(receivedValue?.isFrozen == true, "Received value should be frozen") | ||
} | ||
} |
38 changes: 0 additions & 38 deletions
38
...nes-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeCallbackTests.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...es-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeFlowAppleTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.rickclephas.kmp.nativecoroutines | ||
|
||
import kotlinx.coroutines.flow.flow | ||
import kotlin.native.concurrent.isFrozen | ||
import kotlin.test.* | ||
|
||
class NativeFlowAppleTests { | ||
|
||
@Test | ||
fun ensureFrozen() { | ||
val flow = flow<RandomValue> { } | ||
assertFalse(flow.isFrozen, "Flow shouldn't be frozen yet") | ||
val nativeFlow = flow.asNativeFlow() | ||
assertTrue(nativeFlow.isFrozen, "NativeFlow should be frozen") | ||
assertTrue(flow.isFrozen, "Flow should be frozen") | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeSuspendAppleTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.rickclephas.kmp.nativecoroutines | ||
|
||
import kotlinx.coroutines.delay | ||
import kotlin.native.concurrent.isFrozen | ||
import kotlin.test.* | ||
|
||
class NativeSuspendAppleTests { | ||
|
||
private suspend fun delayAndReturn(delay: Long, value: RandomValue): RandomValue { | ||
delay(delay) | ||
return value | ||
} | ||
|
||
@Test | ||
fun ensureFrozen() { | ||
val value = RandomValue() | ||
assertFalse(value.isFrozen, "Value shouldn't be frozen yet") | ||
val nativeSuspend = nativeSuspend { delayAndReturn(0, value) } | ||
assertTrue(nativeSuspend.isFrozen, "NativeSuspend should be frozen") | ||
assertTrue(value.isFrozen, "Value should be frozen") | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...coroutines-core/src/appleTest/kotlin/com/rickclephas/kmp/nativecoroutines/RunTestApple.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.rickclephas.kmp.nativecoroutines | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.runBlocking | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
@Suppress("ACTUAL_WITHOUT_EXPECT") | ||
actual typealias TestResult = Unit | ||
|
||
internal actual fun runTest( | ||
context: CoroutineContext, | ||
block: suspend CoroutineScope.() -> Unit | ||
): TestResult = runBlocking(context, block) | ||
|
||
@Suppress("SuspendFunctionOnCoroutineScope") | ||
internal actual suspend fun CoroutineScope.runCurrent() { | ||
coroutineContext[Job]?.children?.forEach { it.join() } | ||
} |
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
...nes-core/src/nativeCoroutinesMain/kotlin/com/rickclephas/kmp/nativecoroutines/Freezing.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.rickclephas.kmp.nativecoroutines | ||
|
||
/** | ||
* Freezes this object in Kotlin/Native. | ||
*/ | ||
internal expect fun <T> T.freeze(): T |
4 changes: 1 addition & 3 deletions
4
...as/kmp/nativecoroutines/NativeCallback.kt → ...as/kmp/nativecoroutines/NativeCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...kmp/nativecoroutines/NativeCancellable.kt → ...kmp/nativecoroutines/NativeCancellable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...-core/src/nativeCoroutinesMain/kotlin/com/rickclephas/kmp/nativecoroutines/NativeError.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.rickclephas.kmp.nativecoroutines | ||
|
||
/** | ||
* Represents an error in a way that the specific platform is able to handle | ||
*/ | ||
expect class NativeError | ||
|
||
/** | ||
* Converts a [Throwable] to a [NativeError]. | ||
*/ | ||
internal expect fun Throwable.asNativeError(): NativeError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.