Skip to content

Commit 7a3f48a

Browse files
committed
Refactor UUID generation for platform targets and enhance Kotlin Multiplatform setup
Unified `generateUUID` implementations across platforms, moved common logic to appropriate source sets, and added an Android-specific implementation. Introduced GitHub workflows for macOS, Windows, and Linux targets. Updated Kotlin version to 2.2.0, integrated Android support, and improved dependency resolution.
1 parent ea1be0a commit 7a3f48a

File tree

10 files changed

+238
-10
lines changed

10 files changed

+238
-10
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Kotest Linux Targets
2+
on: [ push ]
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
with:
9+
submodules: recursive
10+
- uses: actions/setup-java@v4
11+
with:
12+
distribution: 'temurin'
13+
java-version: '17'
14+
- name: Enable KVM
15+
run: |
16+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
17+
sudo udevadm control --reload-rules
18+
sudo udevadm trigger --name-match=kvm
19+
- name: Enable aarch64 emulation
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get install --no-install-recommends -y qemu-user-static binfmt-support
23+
sudo update-binfmt --enable qemu-aarch64
24+
continue-on-error: true
25+
- name: jsNodeTest
26+
run: ./gradlew jsNodeTest
27+
continue-on-error: true
28+
- name: jvmKotest
29+
run: ./gradlew jvmKotest
30+
continue-on-error: true
31+
- name: kotestDebugUnitTest
32+
run: ./gradlew kotestDebugUnitTest
33+
continue-on-error: true
34+
- name: kotestReleaseUnitTest
35+
run: ./gradlew kotestReleaseUnitTest
36+
continue-on-error: true
37+
- name: linuxArm64Test
38+
run: ./gradlew linuxArm64Test
39+
continue-on-error: true
40+
- name: linuxX64Test
41+
run: ./gradlew linuxX64Test
42+
continue-on-error: true
43+
- name: wasmJsNodeTest
44+
run: ./gradlew wasmJsNodeTest
45+
continue-on-error: true
46+
- name: androidNativeX86Test
47+
uses: reactivecircus/android-emulator-runner@v2
48+
with:
49+
api-level: 30
50+
arch: x86
51+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
52+
script: ./gradlew androidNativeX86Test
53+
continue-on-error: true
54+
- name: List reports
55+
run: ls -laR shared/build/test-results/
56+
if: success() || failure()
57+
- name: Kotest Report
58+
uses: dorny/test-reporter@v2
59+
if: success() || failure()
60+
with:
61+
name: All Tests
62+
path: build/test-results/**/TEST*.xml
63+
reporter: java-junit
64+
use-actions-summary: true
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Kotest Macos Targets
2+
on: [ push ]
3+
jobs:
4+
build:
5+
runs-on: macos-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
with:
9+
submodules: recursive
10+
- uses: actions/setup-java@v4
11+
with:
12+
distribution: 'temurin'
13+
java-version: '17'
14+
- run: sudo xcodebuild -license accept
15+
- run: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
16+
- name: iosSimulatorArm64Test
17+
run: ./gradlew iosSimulatorArm64Test
18+
continue-on-error: true
19+
- name: iosX64Test
20+
run: ./gradlew iosX64Test
21+
continue-on-error: true
22+
- name: jsNodeTest
23+
run: ./gradlew jsNodeTest
24+
continue-on-error: true
25+
- name: jvmKotest
26+
run: ./gradlew jvmKotest
27+
continue-on-error: true
28+
- name: kotestDebugUnitTest
29+
run: ./gradlew kotestDebugUnitTest
30+
continue-on-error: true
31+
- name: kotestReleaseUnitTest
32+
run: ./gradlew kotestReleaseUnitTest
33+
continue-on-error: true
34+
- name: macosArm64Test
35+
run: ./gradlew macosArm64Test
36+
continue-on-error: true
37+
- name: macosX64Test
38+
run: ./gradlew macosX64Test
39+
continue-on-error: true
40+
- name: tvosSimulatorArm64Test
41+
run: ./gradlew tvosSimulatorArm64Test
42+
continue-on-error: true
43+
- name: tvosX64Test
44+
run: ./gradlew tvosX64Test
45+
continue-on-error: true
46+
- name: wasmJsNodeTest
47+
run: ./gradlew wasmJsNodeTest
48+
continue-on-error: true
49+
- name: watchosSimulatorArm64Test
50+
run: ./gradlew watchosSimulatorArm64Test
51+
continue-on-error: true
52+
- name: watchosX64Test
53+
run: ./gradlew watchosX64Test
54+
continue-on-error: true
55+
- name: androidNativeX86Test
56+
uses: reactivecircus/android-emulator-runner@v2
57+
with:
58+
api-level: 30
59+
arch: x86
60+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
61+
script: ./gradlew androidNativeX86Test
62+
continue-on-error: true
63+
64+
- name: Check
65+
run: ./gradlew check
66+
- name: List reports
67+
run: ls -laR shared/build/test-results/
68+
if: success() || failure()
69+
- name: Kotest Report
70+
uses: dorny/test-reporter@v2
71+
if: success() || failure()
72+
with:
73+
name: All Tests
74+
path: build/test-results/**/TEST*.xml
75+
reporter: java-junit
76+
use-actions-summary: true
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Kotest Windows Targets
2+
on: [ push ]
3+
jobs:
4+
build:
5+
runs-on: windows-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
with:
9+
submodules: recursive
10+
- uses: actions/setup-java@v4
11+
with:
12+
distribution: 'temurin'
13+
java-version: '17'
14+
- name: jsNodeTest
15+
run: .\gradlew.bat jsNodeTest
16+
continue-on-error: true
17+
- name: jvmKotest
18+
run: .\gradlew.bat jvmKotest
19+
continue-on-error: true
20+
- name: kotestDebugUnitTest
21+
run: .\gradlew.bat kotestDebugUnitTest
22+
continue-on-error: true
23+
- name: kotestReleaseUnitTest
24+
run: .\gradlew.bat kotestReleaseUnitTest
25+
continue-on-error: true
26+
- name: mingwX64Test
27+
run: .\gradlew.bat mingwX64Test
28+
continue-on-error: true
29+
- name: wasmJsNodeTest
30+
run: .\gradlew.bat wasmJsNodeKotest
31+
continue-on-error: true
32+
- name: List reports
33+
shell: cmd
34+
run: dir shared\build\test-results /s /a
35+
if: success() || failure()
36+
- name: Kotest Report
37+
uses: dorny/test-reporter@v2
38+
if: success() || failure()
39+
with:
40+
name: All Tests
41+
path: build/test-results/**/TEST*.xml
42+
reporter: java-junit
43+
use-actions-summary: true

kotest-multiplatform/build.gradle.kts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
44

55
plugins {
66
alias(libs.plugins.kotlin.multiplatform)
7+
alias(libs.plugins.androidLibrary)
78
alias(libs.plugins.kotest)
8-
id("com.google.devtools.ksp") version "2.2.0-2.0.2"
9+
alias(libs.plugins.ksp)
910
}
1011

1112
repositories {
@@ -83,3 +84,15 @@ kotlin {
8384
}
8485
}
8586
}
87+
88+
android {
89+
namespace = "io.kotest.test.shared"
90+
compileSdk = libs.versions.android.compileSdk.get().toInt()
91+
compileOptions {
92+
sourceCompatibility = JavaVersion.VERSION_11
93+
targetCompatibility = JavaVersion.VERSION_11
94+
}
95+
defaultConfig {
96+
minSdk = libs.versions.android.minSdk.get().toInt()
97+
}
98+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
[versions]
2+
agp = "8.7.3"
23
kotlin = "2.2.0"
34
kotest = "6.0.0.M17"
5+
ksp = "2.2.0-2.0.2"
6+
android-compileSdk = "35"
7+
android-minSdk = "24"
48

59
[libraries]
610
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
711
kotest-framework-engine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" }
812

913
[plugins]
14+
androidLibrary = { id = "com.android.library", version.ref = "agp" }
1015
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
1116
kotest = { id = "io.kotest", version.ref = "kotest" }
17+
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
pluginManagement {
22
repositories {
3+
google {
4+
mavenContent {
5+
includeGroupAndSubgroups("androidx")
6+
includeGroupAndSubgroups("com.android")
7+
includeGroupAndSubgroups("com.google")
8+
}
9+
}
10+
mavenCentral()
311
gradlePluginPortal()
412
mavenLocal()
513
}
614
}
15+
16+
dependencyResolutionManagement {
17+
repositories {
18+
google {
19+
mavenContent {
20+
includeGroupAndSubgroups("androidx")
21+
includeGroupAndSubgroups("com.android")
22+
includeGroupAndSubgroups("com.google")
23+
}
24+
}
25+
mavenCentral()
26+
mavenLocal()
27+
}
28+
}

kotest-multiplatform/src/linuxX64Main/kotlin/io/kotest/examples/multiplatform/generateUUID.kt renamed to kotest-multiplatform/src/androidMain/kotlin/io/kotest/examples/multiplatform/UUID.android.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package io.kotest.examples.multiplatform
33
import kotlin.random.Random
44

55
actual fun generateUUID(): UUID {
6-
// this is not meant to be a real uuid, just showing the principal of each platform
7-
// having its own implementation
8-
return UUID("Linux" + Random.nextInt(10000000, 99999999).toString())
6+
// this is not meant to be a real uuid, just showing the principal of each platform having its own implementation
7+
return UUID("android-" + Random.nextInt(10000000, 99999999).toString())
98
}

kotest-multiplatform/src/commonMain/kotlin/io/kotest/examples/multiplatform/UUID.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@ package io.kotest.examples.multiplatform
66
*/
77
data class UUID(val value: String)
88

9+
/**
10+
* This function will generate a UUID on each platform.
11+
*
12+
* This is a toy example of a multiplatform library and not intended to be accurate in
13+
* terms of uuid format! It exists to show how each platform can supply their own implementation
14+
* and Kotest can test them all!
15+
*/
916
expect fun generateUUID(): UUID

kotest-multiplatform/src/macosX64Main/kotlin/io/kotest/examples/multiplatform/generateUUID.kt renamed to kotest-multiplatform/src/nativeMain/kotlin/io/kotest/examples/multiplatform/UUID.native.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import kotlin.time.TimeSource
66
private val mark = TimeSource.Monotonic.markNow()
77

88
actual fun generateUUID(): UUID {
9-
// this is not meant to be a real uuid, just showing the principal of each platform
10-
// having its own implementation
11-
return UUID(mark.elapsedNow().inWholeMilliseconds.toString() + Random.nextInt(10000000, 99999999).toString())
9+
// this is not meant to be a real uuid, just showing the principal of each platform having its own implementation
10+
return UUID(mark.elapsedNow().inWholeMilliseconds.toString() + "-" + Random.nextInt(10000000, 99999999).toString())
1211
}

kotest-multiplatform/src/mingwX64Main/kotlin/io/kotest/examples/multiplatform/generateUUID.kt renamed to kotest-multiplatform/src/wasmJsMain/kotlin/io/kotest/examples/multiplatform/UUID.wasmJs.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package io.kotest.examples.multiplatform
33
import kotlin.random.Random
44

55
actual fun generateUUID(): UUID {
6-
// this is not meant to be a real uuid, just showing the principal of each platform
7-
// having its own implementation
8-
return UUID("Windows" + Random.nextInt(10000000, 99999999).toString())
6+
// this is not meant to be a real uuid, just showing the principal of each platform having its own implementation
7+
return UUID(Random.nextInt(10000000, 99999999).toString() + "-" + Random.nextInt(10000000, 99999999))
98
}

0 commit comments

Comments
 (0)