Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit 8fa66cb

Browse files
authored
Upgrading to Arrow v2 (#269)
* migrating to Arrow v2 * re-adding composeModify laws * upgrade yarn lock * Removing SetterLaws arrow-kt/arrow#2859 * Cleaning up build warnings Example of warning: > > Configure project :kotest-assertions-arrow-fx-coroutines > w: A compileOnly dependency is used in targets: Kotlin/JS. > Dependencies: > - io.arrow-kt:arrow-fx-coroutines:2.0.0 (source sets: jsMain) > > Using compileOnly dependencies in these targets is not currently supported, because compileOnly dependencies must be present during the compilation of projects that depend on this project. > > To ensure consistent compilation behaviour, compileOnly dependencies should be exposed as api dependencies. > > Example: > > kotlin { > sourceSets { > nativeMain { > dependencies { > compileOnly("org.example:lib:1.2.3") > // additionally add the compileOnly dependency as an api dependency: > api("org.example:lib:1.2.3") > } > } > } > } > > This warning can be suppressed in gradle.properties: > > kotlin.suppressGradlePluginWarnings=IncorrectCompileOnlyDependencyWarning
1 parent 6918f2a commit 8fa66cb

File tree

31 files changed

+776
-1259
lines changed

31 files changed

+776
-1259
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ project/plugins/project/
1616
credentials.sbt
1717
/.idea/
1818
.DS_Store
19+
.kotlin

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ The project is not shipping the arrow jars because this leads to dependency conf
5050

5151
## Changelog
5252

53+
### 2.0.0
54+
55+
* Release for Kotlin 2.1.0 and Arrow 2.0
56+
5357
### 1.4.0
5458

5559
* Release for Kotlin 1.8 and Kotest 5.7 and Arrow 1.2

buildSrc/src/main/kotlin/kotest-conventions.gradle.kts

Lines changed: 26 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import org.gradle.api.tasks.testing.Test
22
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
33
import org.gradle.api.tasks.testing.logging.TestLogEvent
4-
import org.gradle.kotlin.dsl.all
5-
import org.gradle.kotlin.dsl.dependencies
64
import org.gradle.kotlin.dsl.named
75

86
plugins {
9-
`java-library`
107
kotlin("multiplatform")
118
id("ru.vyarus.animalsniffer")
129
}
@@ -22,144 +19,47 @@ version = Ci.version
2219
kotlin {
2320
explicitApi()
2421

25-
targets {
26-
metadata()
22+
metadata()
2723

28-
jvm {
29-
compilations.all {
30-
kotlinOptions.jvmTarget = "1.8"
31-
}
32-
}
33-
34-
js(IR) {
35-
browser()
36-
nodejs()
24+
jvm {
25+
compilations.all {
26+
kotlinOptions.jvmTarget = "1.8"
3727
}
28+
}
3829

39-
linuxX64()
40-
41-
mingwX64()
42-
43-
iosArm32()
44-
iosArm64()
45-
iosSimulatorArm64()
46-
iosX64()
47-
macosArm64()
48-
macosX64()
49-
tvosArm64()
50-
tvosSimulatorArm64()
51-
tvosX64()
52-
watchosArm32()
53-
watchosArm64()
54-
watchosSimulatorArm64()
55-
watchosX64()
56-
watchosX86()
30+
js(IR) {
31+
browser()
32+
nodejs()
5733
}
5834

59-
sourceSets {
60-
val commonMain by getting
61-
val commonTest by getting {
62-
dependsOn(commonMain)
63-
}
35+
linuxX64()
6436

65-
val jvmMain by getting {
66-
dependsOn(commonMain)
67-
}
37+
mingwX64()
38+
39+
iosArm64()
40+
iosSimulatorArm64()
41+
iosX64()
42+
macosArm64()
43+
macosX64()
44+
tvosArm64()
45+
tvosSimulatorArm64()
46+
tvosX64()
47+
watchosArm32()
48+
watchosArm64()
49+
watchosSimulatorArm64()
50+
watchosX64()
51+
52+
applyDefaultHierarchyTemplate()
6853

54+
sourceSets {
6955
val kotestVersion = resolveVersion("kotest")
7056

7157
val jvmTest by getting {
72-
dependsOn(commonTest)
73-
dependsOn(jvmMain)
7458
dependencies {
7559
implementation("io.kotest:kotest-runner-junit5:$kotestVersion")
7660
}
7761
}
7862

79-
val jsMain by getting {
80-
dependsOn(commonMain)
81-
}
82-
83-
val jsTest by getting {
84-
dependsOn(commonTest)
85-
dependsOn(jsMain)
86-
}
87-
88-
val mingwX64Main by getting
89-
val linuxX64Main by getting
90-
val iosArm32Main by getting
91-
val iosArm64Main by getting
92-
val iosSimulatorArm64Main by getting
93-
val iosX64Main by getting
94-
val macosArm64Main by getting
95-
val macosX64Main by getting
96-
val tvosArm64Main by getting
97-
val tvosSimulatorArm64Main by getting
98-
val tvosX64Main by getting
99-
val watchosArm32Main by getting
100-
val watchosArm64Main by getting
101-
val watchosSimulatorArm64Main by getting
102-
val watchosX64Main by getting
103-
val watchosX86Main by getting
104-
105-
val nativeMain by creating {
106-
dependsOn(commonMain)
107-
mingwX64Main.dependsOn(this)
108-
linuxX64Main.dependsOn(this)
109-
iosArm32Main.dependsOn(this)
110-
iosArm64Main.dependsOn(this)
111-
iosSimulatorArm64Main.dependsOn(this)
112-
iosX64Main.dependsOn(this)
113-
macosArm64Main.dependsOn(this)
114-
macosX64Main.dependsOn(this)
115-
tvosArm64Main.dependsOn(this)
116-
tvosSimulatorArm64Main.dependsOn(this)
117-
tvosX64Main.dependsOn(this)
118-
watchosArm32Main.dependsOn(this)
119-
watchosArm64Main.dependsOn(this)
120-
watchosSimulatorArm64Main.dependsOn(this)
121-
watchosX64Main.dependsOn(this)
122-
watchosX86Main.dependsOn(this)
123-
}
124-
125-
val mingwX64Test by getting
126-
val linuxX64Test by getting
127-
val iosArm32Test by getting
128-
val iosArm64Test by getting
129-
val iosSimulatorArm64Test by getting
130-
val iosX64Test by getting
131-
val macosArm64Test by getting
132-
val macosX64Test by getting
133-
val tvosArm64Test by getting
134-
val tvosSimulatorArm64Test by getting
135-
val tvosX64Test by getting
136-
val watchosArm32Test by getting
137-
val watchosArm64Test by getting
138-
val watchosSimulatorArm64Test by getting
139-
val watchosX64Test by getting
140-
val watchosX86Test by getting
141-
142-
create("nativeTest") {
143-
dependsOn(nativeMain)
144-
dependsOn(commonTest)
145-
mingwX64Test.dependsOn(this)
146-
linuxX64Test.dependsOn(this)
147-
iosArm32Test.dependsOn(this)
148-
iosArm64Test.dependsOn(this)
149-
iosSimulatorArm64Test.dependsOn(this)
150-
iosX64Test.dependsOn(this)
151-
macosArm64Test.dependsOn(this)
152-
macosX64Test.dependsOn(this)
153-
tvosArm64Test.dependsOn(this)
154-
tvosSimulatorArm64Test.dependsOn(this)
155-
tvosX64Test.dependsOn(this)
156-
watchosArm32Test.dependsOn(this)
157-
watchosArm64Test.dependsOn(this)
158-
watchosSimulatorArm64Test.dependsOn(this)
159-
watchosX64Test.dependsOn(this)
160-
watchosX86Test.dependsOn(this)
161-
}
162-
16363
all {
16464
languageSettings.optIn("kotlin.RequiresOptIn")
16565
}

gradle/libs.versions.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[versions]
2-
arrow = "1.2.4"
3-
kotlin = "1.8.10"
2+
arrow = "2.0.0"
3+
kotlin = "2.1.0"
44
kotest = "5.8.1"
55
kotlinx-coroutines = "1.6.4"
6-
animalsniffer = "1.7.1"
6+
animalsniffer = "1.7.2"
77
kotlinBinaryCompatibilityValidator = "0.14.0"
88

99
[libraries]
@@ -18,6 +18,7 @@ kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-c
1818
arrow-fx-coroutines = { module = "io.arrow-kt:arrow-fx-coroutines", version.ref = "arrow" }
1919
arrow-core = { module = "io.arrow-kt:arrow-core", version.ref = "arrow" }
2020
arrow-optics = { module = "io.arrow-kt:arrow-optics", version.ref = "arrow" }
21+
arrow-functions = { module = "io.arrow-kt:arrow-functions", version.ref = "arrow" }
2122

2223
# Gradle plugins used in buildSrc
2324
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

kotest-assertions-arrow-fx-coroutines/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ kotlin {
2121
}
2222
}
2323

24+
jsMain {
25+
dependencies {
26+
api(libs.arrow.fx.coroutines)
27+
}
28+
}
29+
2430
nativeMain {
2531
dependencies {
2632
implementation(libs.arrow.fx.coroutines)

kotest-assertions-arrow-fx-coroutines/src/commonMain/kotlin/io/kotest/assertions/arrow/fx/coroutines/ProjectResource.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package io.kotest.assertions.arrow.fx.coroutines
22

33
import arrow.fx.coroutines.Resource
4-
import arrow.fx.coroutines.continuations.ResourceScope
5-
import arrow.fx.coroutines.continuations.resource
64
import io.kotest.core.extensions.LazyMaterialized
75
import io.kotest.core.listeners.ProjectListener
86

@@ -32,7 +30,6 @@ public class ProjectResource<A> private constructor(
3230
) : ProjectListener, LazyMaterialized<A> by default {
3331

3432
public constructor(resource: Resource<A>) : this(resource, ResourceLazyMaterialized(resource))
35-
public constructor(block: suspend ResourceScope.() -> Resource<A>) : this(resource { block().bind() })
3633

3734
override suspend fun beforeProject() {
3835
default.init()
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package io.kotest.assertions.arrow.fx.coroutines
22

3-
import arrow.core.identity
43
import arrow.fx.coroutines.Resource
5-
import arrow.fx.coroutines.continuations.resource
4+
import arrow.fx.coroutines.resourceScope
65

76
public suspend infix fun <A> Resource<A>.shouldBeResource(a: A): A =
8-
use { it shouldBe a }
7+
resourceScope {
8+
bind() shouldBe a
9+
}
910

1011
public suspend infix fun <A> Resource<A>.shouldBeResource(expected: Resource<A>): A =
11-
resource {
12+
resourceScope {
1213
bind() shouldBe expected.bind()
13-
}.use(::identity)
14+
}

kotest-assertions-arrow-fx-coroutines/src/commonMain/kotlin/io/kotest/assertions/arrow/fx/coroutines/ResourceExtension.kt

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.kotest.assertions.arrow.fx.coroutines
22

3-
import arrow.fx.coroutines.ExitCase
4-
import arrow.fx.coroutines.Resource
3+
import arrow.fx.coroutines.*
54
import io.kotest.core.extensions.LazyMaterialized
65
import io.kotest.core.extensions.LazyMountableExtension
76
import io.kotest.core.listeners.AfterSpecListener
@@ -62,28 +61,28 @@ public fun <A> Resource<A>.extension(lifecycleMode: LifecycleMode = LifecycleMod
6261
public class ResourceExtension<A>(
6362
public val resource: Resource<A>, public val lifecycleMode: LifecycleMode = LifecycleMode.Spec,
6463
) : LazyMountableExtension<A, A>, TestListener, AfterSpecListener {
65-
64+
6665
private var underlying: ResourceLazyMaterialized<A>? = null
67-
66+
6867
override fun mount(configure: A.() -> Unit): LazyMaterialized<A> =
6968
ResourceLazyMaterialized(resource, configure).also {
7069
underlying = it
7170
}
72-
71+
7372
override suspend fun beforeSpec(spec: Spec) {
7473
super.beforeSpec(spec)
7574
if (lifecycleMode == LifecycleMode.Spec) {
7675
underlying?.init()
7776
}
7877
}
79-
78+
8079
override suspend fun afterSpec(spec: Spec) {
8180
if (lifecycleMode == LifecycleMode.Spec) {
8281
underlying?.release()
8382
}
8483
underlying?.close()
8584
}
86-
85+
8786
override suspend fun beforeAny(testCase: TestCase) {
8887
val every = lifecycleMode == LifecycleMode.EveryTest
8988
val root = lifecycleMode == LifecycleMode.Root && testCase.isRootTest()
@@ -92,7 +91,7 @@ public class ResourceExtension<A>(
9291
underlying?.init()
9392
}
9493
}
95-
94+
9695
override suspend fun afterAny(testCase: TestCase, result: TestResult) {
9796
val every = lifecycleMode == LifecycleMode.EveryTest
9897
val root = lifecycleMode == LifecycleMode.Root && testCase.isRootTest()
@@ -107,22 +106,22 @@ internal class ResourceLazyMaterialized<A>(
107106
private val resource: Resource<A>,
108107
private val configure: A.() -> Unit = {},
109108
) : LazyMaterialized<A> {
110-
109+
111110
sealed interface State<out A> {
112-
object Empty : State<Nothing>
113-
object Closed : State<Nothing>
111+
data object Empty : State<Nothing>
112+
data object Closed : State<Nothing>
114113
data class Loading<A>(
115114
val acquiring: CompletableDeferred<A> = CompletableDeferred(),
116115
val finalizers: CompletableDeferred<suspend (ExitCase) -> Unit> = CompletableDeferred(),
117116
) : State<A>
118-
117+
119118
data class Done<A>(val value: A, val finalizers: suspend (ExitCase) -> Unit) : State<A>
120119
}
121-
120+
122121
private val state = AtomicReference<State<A>>(State.Empty)
123-
122+
124123
override suspend fun get(): A = init()
125-
124+
126125
@OptIn(DelicateCoroutinesApi::class)
127126
tailrec suspend fun init(): A = when (val current = state.value) {
128127
is State.Done -> current.value
@@ -131,11 +130,10 @@ internal class ResourceLazyMaterialized<A>(
131130
State.Empty -> {
132131
val loading = State.Loading<A>()
133132
if (state.compareAndSet(State.Empty, loading)) {
134-
val (res, fin) = resource.allocated()
135-
.let { (acquire, finalizer) ->
136-
val a = acquire()
133+
val (res, fin) = resource.allocate()
134+
.let { (a, finalizer) ->
137135
@Suppress("NAME_SHADOWING")
138-
val finalizer: suspend (ExitCase) -> Unit = { finalizer(a, it) }
136+
val finalizer: suspend (ExitCase) -> Unit = { finalizer(it) }
139137
Pair(a, finalizer)
140138
}
141139
state.value = State.Done(res, fin)
@@ -145,19 +143,19 @@ internal class ResourceLazyMaterialized<A>(
145143
} else init()
146144
}
147145
}
148-
146+
149147
tailrec suspend fun release(): Unit = when (val current = state.value) {
150148
State.Empty -> Unit
151149
is State.Done -> if (state.compareAndSet(current, State.Empty)) current.finalizers(ExitCase.Completed)
152150
else release()
153-
151+
154152
is State.Loading -> if (state.compareAndSet(current, State.Empty)) current.finalizers.await()
155153
.invoke(ExitCase.Completed)
156154
else release()
157-
155+
158156
State.Closed -> Unit
159157
}
160-
158+
161159
fun close() {
162160
state.value = State.Closed
163161
}

0 commit comments

Comments
 (0)