-
Notifications
You must be signed in to change notification settings - Fork 31
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-29-improve-exception-conversion
- Loading branch information
Showing
22 changed files
with
183 additions
and
115 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
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") | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
...-core/src/nativeCoroutinesTest/kotlin/com/rickclephas/kmp/nativecoroutines/KotlinCause.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,9 @@ | ||
package com.rickclephas.kmp.nativecoroutines | ||
|
||
/** | ||
* Gets the [Throwable] from the [NativeError]. | ||
* | ||
* Note: this doesn't actually convert a [NativeError] to a [Throwable], | ||
* it should only be used to test [asNativeError] logic. | ||
*/ | ||
internal expect val NativeError.kotlinCause: Throwable? |
22 changes: 22 additions & 0 deletions
22
...c/nativeCoroutinesTest/kotlin/com/rickclephas/kmp/nativecoroutines/NativeCallbackTests.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.test.* | ||
|
||
class NativeCallbackTests { | ||
|
||
@Test | ||
fun ensureInvoked() { | ||
var invokeCount = 0 | ||
var receivedValue: RandomValue? = null | ||
val callback: NativeCallback<RandomValue> = callback@{ value, unit -> | ||
receivedValue = value | ||
invokeCount++ | ||
// This isn't required in Kotlin, but it is in Swift, so we'll test it anyway | ||
return@callback unit | ||
} | ||
val value = RandomValue() | ||
callback(value) | ||
assertEquals(1, invokeCount, "NativeCallback should have been invoked once") | ||
assertSame(value, receivedValue, "Received value should be the same as the send value") | ||
} | ||
} |
Oops, something went wrong.