Skip to content

Commit

Permalink
Move to Kotest 6.0.M1 + new arrow-platform (#3506)
Browse files Browse the repository at this point in the history
  • Loading branch information
serras authored Nov 5, 2024
1 parent 20f29ff commit 60ae37b
Show file tree
Hide file tree
Showing 41 changed files with 161 additions and 57 deletions.
1 change: 1 addition & 0 deletions arrow-libs/core/arrow-atomic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ kotlin {
commonTest {
dependencies {
implementation(projects.arrowFxCoroutines)
implementation(projects.arrowPlatform)
implementation(libs.kotlin.test)
implementation(libs.coroutines.test)
implementation(libs.kotest.assertionsCore)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package arrow.atomic

import arrow.fx.coroutines.parMap
import arrow.platform.stackSafeIteration
import kotlin.test.Test
import kotlinx.coroutines.test.runTest
import io.kotest.matchers.shouldBe
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package arrow.atomic

import arrow.fx.coroutines.parMap
import arrow.platform.stackSafeIteration
import kotlin.test.Test
import kotlinx.coroutines.test.runTest
import io.kotest.matchers.shouldBe
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package arrow.atomic

import arrow.fx.coroutines.parMap
import arrow.platform.stackSafeIteration
import kotlin.test.Test
import kotlinx.coroutines.test.runTest
import io.kotest.matchers.shouldBe
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package arrow.atomic

import io.kotest.common.Platform
import io.kotest.common.platform
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.test.TestResult
import kotlinx.coroutines.withContext

fun stackSafeIteration(): Int = when (platform) {
Platform.JVM -> 20_000
else -> 1000
}

fun runTestWithDelay(testBody: suspend () -> Unit): TestResult = runTest {
withContext(Dispatchers.Default) {
testBody()
Expand Down
1 change: 1 addition & 0 deletions arrow-libs/core/arrow-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ kotlin {
commonTest {
dependencies {
implementation(projects.arrowFxCoroutines)
implementation(projects.arrowPlatform)
implementation(libs.kotlin.test)
implementation(libs.coroutines.test)
implementation(libs.kotest.assertionsCore)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package arrow.core

import arrow.core.test.nonEmptyList
import arrow.core.test.stackSafeIteration
import arrow.platform.stackSafeIteration
import io.kotest.assertions.withClue
import io.kotest.inspectors.shouldForAll
import io.kotest.matchers.booleans.shouldBeTrue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package arrow.core

import arrow.core.test.nonEmptySet
import arrow.core.test.stackSafeIteration
import arrow.platform.stackSafeIteration
import io.kotest.assertions.withClue
import io.kotest.matchers.booleans.shouldBeTrue
import io.kotest.matchers.nulls.shouldBeNull
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions arrow-libs/core/arrow-eval/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ kotlin {
implementation(libs.kotlin.test)
implementation(libs.kotest.assertionsCore)
implementation(libs.kotest.property)
implementation(projects.arrowPlatform)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package arrow.eval

import io.kotest.common.Platform
import io.kotest.common.platform
import arrow.platform.stackSafeIteration
import io.kotest.matchers.shouldBe
import kotlin.test.Test

Expand All @@ -24,11 +23,6 @@ private fun recur(limit: Int, sideEffect: SideEffect): (Int) -> Eval<Int> {
}
}

fun stackSafeIteration(): Int = when (platform) {
Platform.JVM -> 200_000
else -> 1000
}

class EvalTest {
@Test
fun mapWrappedValue() {
Expand Down
1 change: 1 addition & 0 deletions arrow-libs/core/arrow-functions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ kotlin {
commonTest {
dependencies {
implementation(projects.arrowFxCoroutines)
implementation(projects.arrowPlatform)
implementation(libs.kotlin.test)
implementation(libs.coroutines.test)
implementation(libs.kotest.assertionsCore)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package arrow.core

import io.kotest.common.Platform
import io.kotest.common.platform
import arrow.platform.Platform
import arrow.platform.platform
import io.kotest.property.Arb
import io.kotest.matchers.shouldBe
import io.kotest.property.arbitrary.arbitrary
Expand Down
18 changes: 18 additions & 0 deletions arrow-libs/core/arrow-platform/api/arrow-platform.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public final class arrow/platform/CurrentPlatform {
public static final fun getPlatform ()Larrow/platform/Platform;
}

public final class arrow/platform/Platform : java/lang/Enum {
public static final field JS Larrow/platform/Platform;
public static final field JVM Larrow/platform/Platform;
public static final field Native Larrow/platform/Platform;
public static final field WebAssembly Larrow/platform/Platform;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Larrow/platform/Platform;
public static fun values ()[Larrow/platform/Platform;
}

public final class arrow/platform/PlatformKt {
public static final fun stackSafeIteration ()I
}

25 changes: 25 additions & 0 deletions arrow-libs/core/arrow-platform/api/arrow-platform.klib.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosSimulatorArm64, watchosX64]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
// - Show declarations: true

// Library unique name: <io.arrow-kt:arrow-platform>
final enum class arrow.platform/Platform : kotlin/Enum<arrow.platform/Platform> { // arrow.platform/Platform|null[0]
enum entry JS // arrow.platform/Platform.JS|null[0]
enum entry JVM // arrow.platform/Platform.JVM|null[0]
enum entry Native // arrow.platform/Platform.Native|null[0]
enum entry WebAssembly // arrow.platform/Platform.WebAssembly|null[0]

final val entries // arrow.platform/Platform.entries|#static{}entries[0]
final fun <get-entries>(): kotlin.enums/EnumEntries<arrow.platform/Platform> // arrow.platform/Platform.entries.<get-entries>|<get-entries>#static(){}[0]

final fun valueOf(kotlin/String): arrow.platform/Platform // arrow.platform/Platform.valueOf|valueOf#static(kotlin.String){}[0]
final fun values(): kotlin/Array<arrow.platform/Platform> // arrow.platform/Platform.values|values#static(){}[0]
}

final val arrow.platform/platform // arrow.platform/platform|{}platform[0]
final fun <get-platform>(): arrow.platform/Platform // arrow.platform/platform.<get-platform>|<get-platform>(){}[0]

final fun arrow.platform/stackSafeIteration(): kotlin/Int // arrow.platform/stackSafeIteration|stackSafeIteration(){}[0]
44 changes: 44 additions & 0 deletions arrow-libs/core/arrow-platform/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@file:Suppress("DSL_SCOPE_VIOLATION")

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion


plugins {
id(libs.plugins.kotlin.multiplatform.get().pluginId)
alias(libs.plugins.arrowGradleConfig.kotlin)
alias(libs.plugins.publish)
alias(libs.plugins.spotless)
}

spotless {
kotlin {
ktlint().editorConfigOverride(mapOf("ktlint_standard_filename" to "disabled"))
}
}

apply(from = property("ANIMALSNIFFER_MPP"))

kotlin {
sourceSets {
commonMain {
dependencies {
implementation(libs.kotlin.stdlib)
}
}
}

jvm {
tasks.jvmJar {
manifest {
attributes["Automatic-Module-Name"] = "arrow.platform"
}
}
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
(project.rootProject.properties["kotlin_language_version"] as? String)?.also { languageVersion = KotlinVersion.fromVersion(it) }
(project.rootProject.properties["kotlin_api_version"] as? String)?.also { apiVersion = KotlinVersion.fromVersion(it) }
}
}
2 changes: 2 additions & 0 deletions arrow-libs/core/arrow-platform/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Maven publishing configuration
POM_NAME=Arrow Platform
5 changes: 5 additions & 0 deletions arrow-libs/core/arrow-platform/knit.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
knit.package=arrow.platform.examples
knit.dir=src/commonTest/kotlin/examples/

test.package=arrow.platform.examples.test
test.dir=src/commonTest/kotlin/examples/autogenerated/
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package arrow.platform

import kotlin.jvm.JvmName

public enum class Platform {
JVM, JS, Native, WebAssembly
}

public expect val platform: Platform

/**
* Heuristic about the maximum amount of stack space
* one can reasonably consume in the executing platform.
*/
public fun stackSafeIteration(): Int = when (platform) {
Platform.JVM -> 200_000
else -> 1000
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package arrow.platform

public actual val platform: Platform = Platform.JS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@file:JvmName("CurrentPlatform")
package arrow.platform

public actual val platform: Platform = Platform.JVM
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package arrow.platform

public actual val platform: Platform = Platform.Native
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package arrow.platform

public actual val platform: Platform = Platform.WebAssembly
1 change: 1 addition & 0 deletions arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ kotlin {
dependencies {
implementation(projects.arrowCore)
implementation(projects.arrowAtomic)
implementation(projects.arrowPlatform)
implementation(libs.kotlin.test)
implementation(libs.coroutines.test)
implementation(libs.kotest.assertionsCore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import arrow.core.Either
import arrow.core.NonEmptyList
import arrow.core.left
import arrow.core.raise.either
import arrow.platform.stackSafeIteration
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package arrow.fx.coroutines

import io.kotest.common.Platform
import io.kotest.common.platform
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.test.TestResult
import kotlinx.coroutines.test.TestScope
Expand All @@ -10,11 +8,6 @@ import kotlinx.coroutines.withContext
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

fun stackSafeIteration(): Int = when (platform) {
Platform.JVM -> 20_000
else -> 1000
}

// The normal dispatcher with 'runTest' does some magic
// which doesn't go well with 'parZip', 'parMap', and 'raceN'
fun runTestUsingDefaultDispatcher(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package arrow.fx.coroutines

import arrow.atomic.AtomicInt
import java.util.concurrent.ThreadFactory

private val namedThreadCount = AtomicInt(0)

class NamedThreadFactory(val name: String): ThreadFactory {
override fun newThread(r: Runnable): Thread? =
Thread(r, "$name-${namedThreadCount.getAndIncrement()}").apply {
uncaughtExceptionHandler = Thread.UncaughtExceptionHandler { _, e ->
e.printStackTrace()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import arrow.core.Either
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.should
import io.kotest.matchers.string.shouldStartWith
import io.kotest.mpp.NamedThreadFactory
import java.util.concurrent.Executors
import kotlin.coroutines.CoroutineContext
import kotlin.test.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import arrow.core.Either
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.should
import io.kotest.matchers.string.shouldStartWith
import io.kotest.mpp.NamedThreadFactory
import io.kotest.property.Arb
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import arrow.core.Tuple4
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.should
import io.kotest.matchers.string.shouldStartWith
import io.kotest.mpp.NamedThreadFactory
import io.kotest.property.Arb
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import arrow.core.Tuple5
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.should
import io.kotest.matchers.string.shouldStartWith
import io.kotest.mpp.NamedThreadFactory
import io.kotest.property.Arb
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.string
import io.kotest.property.checkAll
import kotlinx.coroutines.*
import java.util.concurrent.Executors
import kotlin.test.Test
import kotlin.time.Duration.Companion.seconds

class ParZip5JvmTest {
val threadName: suspend CoroutineScope.() -> String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import arrow.core.Tuple6
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.should
import io.kotest.matchers.string.shouldStartWith
import io.kotest.mpp.NamedThreadFactory
import io.kotest.property.Arb
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.string
import io.kotest.property.checkAll
import kotlinx.coroutines.*
import java.util.concurrent.Executors
import kotlin.test.Test
import kotlin.time.Duration.Companion.seconds

class ParZip6JvmTest {
val threadName: suspend CoroutineScope.() -> String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import arrow.core.Tuple7
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.should
import io.kotest.matchers.string.shouldStartWith
import io.kotest.mpp.NamedThreadFactory
import io.kotest.property.Arb
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.string
import io.kotest.property.checkAll
import kotlinx.coroutines.*
import java.util.concurrent.Executors
import kotlin.test.Test
import kotlin.time.Duration.Companion.seconds

class ParZip7JvmTest {
val threadName: suspend CoroutineScope.() -> String =
Expand Down
Loading

0 comments on commit 60ae37b

Please sign in to comment.