Skip to content

Commit

Permalink
Added function to run tests by specified compiler version (#2148)
Browse files Browse the repository at this point in the history
  • Loading branch information
shanshin authored Feb 6, 2023
1 parent 0b01b53 commit 9e344bd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kotlinx.serialization
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import kotlinx.serialization.json.*
import kotlinx.serialization.test.runSince
import kotlin.test.*

@Serializable
Expand Down Expand Up @@ -82,8 +83,7 @@ class SerializableOnPropertyTypeAndTypealiasTest : JsonTestBase() {
}

@Test
@Ignore // TODO: Unignore in 1.8.20 (#1895)
fun testWithoutDefault() {
fun testWithoutDefault() = runSince("1.8.20") { // Ignored by #1895
val t = TesterWithoutDefault(WithoutDefault("a"), WithoutDefault("b"), WithoutDefault("c"), WithoutDefault("d"))
assertJsonFormAndRestored(
TesterWithoutDefault.serializer(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.serialization.test

import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

private val currentKotlinVersion = KotlinVersion.CURRENT

private fun String.toKotlinVersion(): KotlinVersion {
val parts = split(".")
val intParts = parts.mapNotNull { it.toIntOrNull() }
if (parts.size != 3 || intParts.size != 3) error("Illegal kotlin version, expected format is 1.2.3")

return KotlinVersion(intParts[0], intParts[1], intParts[2])
}

internal fun runSince(kotlinVersion: String, test: () -> Unit) {
if (currentKotlinVersion >= kotlinVersion.toKotlinVersion()) {
test()
}
}

internal class CompilerVersionTest {
@Test
fun testSince() {
var executed = false

runSince("1.0.0") {
executed = true
}
assertTrue(executed)

executed = false
runSince("255.255.255") {
executed = true
}
assertFalse(executed)
}
}

0 comments on commit 9e344bd

Please sign in to comment.