Skip to content

Commit fc6e875

Browse files
committed
Expect CME only on JVM
1 parent f92e96d commit fc6e875

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

core/commonTest/src/contract/list/ImmutableListTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ package kotlinx.collections.immutable.contractTests.immutableList
1919
import kotlinx.collections.immutable.*
2020
import kotlinx.collections.immutable.contractTests.compare
2121
import kotlinx.collections.immutable.contractTests.listBehavior
22-
import kotlinx.collections.immutable.tests.isDigit
23-
import kotlinx.collections.immutable.tests.isUpperCase
22+
import kotlinx.collections.immutable.tests.*
2423
import kotlin.test.*
2524

2625
class ImmutableListTest {
@@ -152,7 +151,9 @@ class ImmutableListTest {
152151
// So, structural changes in builder causes CME on subList iteration.
153152
var subList = builder.subList(2, 5)
154153
builder[4] = 'x'
155-
assertFailsWith<ConcurrentModificationException> { subList.joinToString("") }
154+
testOn(TestPlatform.JVM) {
155+
assertFailsWith<ConcurrentModificationException> { subList.joinToString("") }
156+
}
156157

157158
// builder is the exclusive owner of the inner trie.
158159
// So, `set(index, value)` doesn't lead to structural changes.

core/commonTest/src/stress/list/PersistentListBuilderTest.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import kotlinx.collections.immutable.PersistentList
2020
import kotlinx.collections.immutable.contractTests.compare
2121
import kotlinx.collections.immutable.contractTests.listIteratorProperties
2222
import kotlinx.collections.immutable.persistentListOf
23+
import kotlinx.collections.immutable.tests.*
2324
import kotlin.random.Random
2425
import kotlin.test.*
2526

@@ -282,8 +283,10 @@ class PersistentListBuilderTest {
282283
assertEquals(0, builder[beginIndex * 2])
283284

284285
builder.add(0)
285-
assertFailsWith<ConcurrentModificationException> {
286-
subList.add(0)
286+
testOn(TestPlatform.JVM) {
287+
assertFailsWith<ConcurrentModificationException> {
288+
subList.add(0)
289+
}
287290
}
288291
}
289292

core/commonTest/src/testUtils.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,14 @@ internal fun <K, V> MutableMap<K, V>.remove(key: K, value: V): Boolean =
2929
}
3030

3131
public expect fun assertTypeEquals(expected: Any?, actual: Any?)
32+
33+
public enum class TestPlatform {
34+
JVM,
35+
JS,
36+
Native
37+
}
38+
public expect val currentPlatform: TestPlatform
39+
40+
public inline fun testOn(platform: TestPlatform, action: () -> Unit) {
41+
if (platform == currentPlatform) action()
42+
}

core/jsTest/src/testUtilsJs.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ import kotlin.test.assertEquals
2020

2121
public actual fun assertTypeEquals(expected: Any?, actual: Any?) {
2222
assertEquals(expected?.let { it::class.js }, actual?.let { it::class.js })
23-
}
23+
}
24+
25+
public actual val currentPlatform: TestPlatform get() = TestPlatform.JS

core/jvmTest/src/testUtilsJvm.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ import kotlin.test.assertEquals
2020

2121
public actual fun assertTypeEquals(expected: Any?, actual: Any?) {
2222
assertEquals(expected?.javaClass, actual?.javaClass)
23-
}
23+
}
24+
25+
public actual val currentPlatform: TestPlatform get() = TestPlatform.JVM

core/nativeTest/src/testUtilsNative.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ public actual fun assertTypeEquals(expected: Any?, actual: Any?) {
2626
assertTrue(expected == null && actual == null)
2727
}
2828
}
29+
30+
public actual val currentPlatform: TestPlatform get() = TestPlatform.Native

0 commit comments

Comments
 (0)