Skip to content

Commit 003a220

Browse files
committed
Move krpc-test to commonMain
1 parent 7d40d29 commit 003a220

File tree

13 files changed

+206
-127
lines changed

13 files changed

+206
-127
lines changed

krpc/krpc-test/build.gradle.kts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
@@ -22,11 +22,7 @@ kotlin {
2222
// Workaround for
2323
// KLIB resolver: Could not find "org.jetbrains.kotlinx:atomicfu"
2424
api(libs.atomicfu)
25-
}
26-
}
2725

28-
jvmMain {
29-
dependencies {
3026
api(projects.krpc.krpcCore)
3127
api(projects.krpc.krpcServer)
3228
api(projects.krpc.krpcClient)
@@ -35,6 +31,12 @@ kotlin {
3531

3632
implementation(libs.serialization.core)
3733
implementation(libs.kotlin.test)
34+
implementation(libs.coroutines.test)
35+
}
36+
}
37+
38+
jvmMain {
39+
dependencies {
3840
implementation(libs.kotlin.test.junit)
3941
}
4042
}
@@ -72,7 +74,7 @@ tasks.named<Delete>("clean") {
7274
delete(resourcesPath.walk().filter { it.isFile && it.extension == tmpExt }.toList())
7375
}
7476

75-
tasks.create("moveToGold") {
77+
tasks.register("moveToGold") {
7678
doLast {
7779
resourcesPath.walk().forEach {
7880
if (it.isFile && it.extension == tmpExt) {

krpc/krpc-test/src/commonMain/kotlin/Stub.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestClient.kt renamed to krpc/krpc-test/src/commonMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.krpc.test

krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServer.kt renamed to krpc/krpc-test/src/commonMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.krpc.test

krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestService.kt renamed to krpc/krpc-test/src/commonMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestService.kt

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,37 @@ import kotlinx.rpc.RemoteService
1111
import kotlinx.rpc.annotations.Rpc
1212
import kotlinx.serialization.Contextual
1313
import kotlinx.serialization.Serializable
14-
import java.time.LocalDate
15-
import java.time.LocalDateTime
14+
15+
data class LocalDate(
16+
val year: Int,
17+
val month: Int,
18+
val day: Int,
19+
) {
20+
override fun toString(): String {
21+
return "$year-$month-$day"
22+
}
23+
24+
companion object {
25+
fun parse(str: String): LocalDate = str.split('-').let {
26+
LocalDate(it[0].toInt(), it[1].toInt(), it[2].toInt())
27+
}
28+
}
29+
}
30+
31+
data class LocalDateTime(
32+
val date: LocalDate,
33+
val time: String,
34+
) {
35+
override fun toString(): String {
36+
return "$date $time"
37+
}
38+
39+
companion object {
40+
fun parse(str: String): LocalDateTime = str.split(' ').let {
41+
LocalDateTime(LocalDate.parse(it[0]), it[1])
42+
}
43+
}
44+
}
1645

1746
@Suppress("detekt.TooManyFunctions")
1847
@Rpc

krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServiceBackend.kt renamed to krpc/krpc-test/src/commonMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServiceBackend.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ package kotlinx.rpc.krpc.test
77
import kotlinx.coroutines.*
88
import kotlinx.coroutines.flow.*
99
import kotlinx.serialization.Serializable
10-
import java.time.LocalDate
11-
import java.time.LocalDateTime
12-
import java.time.format.DateTimeFormatter
1310
import kotlin.coroutines.CoroutineContext
1411
import kotlin.coroutines.resumeWithException
1512
import kotlin.test.assertContentEquals
@@ -110,11 +107,18 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
110107
}
111108

112109
override suspend fun nonSerializableClass(localDate: LocalDate): LocalDate {
113-
return localDate.plusDays(1)
110+
return LocalDate(localDate.year, localDate.month, localDate.day + 1)
114111
}
115112

116113
override suspend fun nonSerializableClassWithSerializer(localDateTime: LocalDateTime): String {
117-
return localDateTime.plusDays(1).format(DateTimeFormatter.ISO_DATE_TIME)
114+
return LocalDateTime(
115+
date = LocalDate(
116+
year = localDateTime.date.year,
117+
month = localDateTime.date.month,
118+
day = localDateTime.date.day + 1,
119+
),
120+
time = localDateTime.time,
121+
).toString()
118122
}
119123

120124
override suspend fun incomingStreamSyncCollect(arg1: Flow<String>): Int {
@@ -240,9 +244,9 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
240244

241245
override suspend fun throwsUNSTOPPABLEThrowable(message: String) {
242246
suspendCancellableCoroutine<Unit> { continuation ->
243-
Thread {
247+
runThreadIfPossible {
244248
continuation.resumeWithException(Throwable(message))
245-
}.start()
249+
}
246250
}
247251
}
248252

@@ -320,3 +324,5 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
320324
return state
321325
}
322326
}
327+
328+
internal expect fun runThreadIfPossible(runner: () -> Unit)

0 commit comments

Comments
 (0)