-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added function to run tests by specified compiler version (#2148)
- Loading branch information
Showing
2 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
formats/json-tests/commonTest/src/kotlinx/serialization/test/CompilerVersions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |