Skip to content

Commit 9e344bd

Browse files
authored
Added function to run tests by specified compiler version (#2148)
1 parent 0b01b53 commit 9e344bd

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

formats/json-tests/commonTest/src/kotlinx/serialization/SerializableOnPropertyTypeAndTypealiasTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package kotlinx.serialization
33
import kotlinx.serialization.descriptors.*
44
import kotlinx.serialization.encoding.*
55
import kotlinx.serialization.json.*
6+
import kotlinx.serialization.test.runSince
67
import kotlin.test.*
78

89
@Serializable
@@ -82,8 +83,7 @@ class SerializableOnPropertyTypeAndTypealiasTest : JsonTestBase() {
8283
}
8384

8485
@Test
85-
@Ignore // TODO: Unignore in 1.8.20 (#1895)
86-
fun testWithoutDefault() {
86+
fun testWithoutDefault() = runSince("1.8.20") { // Ignored by #1895
8787
val t = TesterWithoutDefault(WithoutDefault("a"), WithoutDefault("b"), WithoutDefault("c"), WithoutDefault("d"))
8888
assertJsonFormAndRestored(
8989
TesterWithoutDefault.serializer(),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.serialization.test
6+
7+
import kotlin.test.Test
8+
import kotlin.test.assertFalse
9+
import kotlin.test.assertTrue
10+
11+
private val currentKotlinVersion = KotlinVersion.CURRENT
12+
13+
private fun String.toKotlinVersion(): KotlinVersion {
14+
val parts = split(".")
15+
val intParts = parts.mapNotNull { it.toIntOrNull() }
16+
if (parts.size != 3 || intParts.size != 3) error("Illegal kotlin version, expected format is 1.2.3")
17+
18+
return KotlinVersion(intParts[0], intParts[1], intParts[2])
19+
}
20+
21+
internal fun runSince(kotlinVersion: String, test: () -> Unit) {
22+
if (currentKotlinVersion >= kotlinVersion.toKotlinVersion()) {
23+
test()
24+
}
25+
}
26+
27+
internal class CompilerVersionTest {
28+
@Test
29+
fun testSince() {
30+
var executed = false
31+
32+
runSince("1.0.0") {
33+
executed = true
34+
}
35+
assertTrue(executed)
36+
37+
executed = false
38+
runSince("255.255.255") {
39+
executed = true
40+
}
41+
assertFalse(executed)
42+
}
43+
}

0 commit comments

Comments
 (0)