Skip to content

Commit 3e61ae7

Browse files
committed
Require Kotlin 1.5.30 or newer in the host project
This commit also add tests to test our comparison of Kotlin versions.
1 parent aac3202 commit 3e61ae7

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

plugin/src/main/kotlin/com/louiscad/complete_kotlin/internal/TargetsHandler.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ internal fun Project.completePlatformKlibsIfNeeded() {
2323
//TODO: Get the CompilerVersion lazily (lazy delegate cannot be used)
2424
val compilerVersion = CompilerVersion.current(project = project, objectForResourceLookup = extension)
2525

26+
run {
27+
val minimumKotlinVersion = "1.5.30"
28+
if (compilerVersion.isAtLeast(CompilerVersion.fromString(minimumKotlinVersion)).not()) {
29+
val errorMessage = "This version of CompleteKotlin requires the project to " +
30+
"use Kotlin $minimumKotlinVersion or newer. " +
31+
"Use version 1.0.0 of CompleteKotlin if you can't upgrade Kotlin in this project."
32+
throw UnsupportedOperationException(errorMessage)
33+
}
34+
}
35+
2636
val hostCompilerDirs = KotlinNativeCompilerDirs(compilerVersion)
2737

2838

plugin/src/test/kotlin/com/louiscad/complete_kotlin/CompilerVersionTest.kt

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
11
package com.louiscad.complete_kotlin
22

33
import com.louiscad.complete_kotlin.internal.CompilerVersion
4+
import com.louiscad.complete_kotlin.internal.isAtLeast
45
import org.junit.jupiter.api.TestFactory
56
import testutils.junit.mapDynamicTest
6-
import kotlin.test.Test
7-
import kotlin.test.assertEquals
7+
import kotlin.test.assertFalse
8+
import kotlin.test.assertTrue
89

910
class CompilerVersionTest {
1011

11-
@Test
12-
fun testMyKnowledge() {
13-
assertEquals(
14-
expected = "1.5",
15-
actual = CompilerVersion.fromString("1.5").toString()
12+
@TestFactory
13+
fun `check older Kotlin versions detection`() = unsupportedKotlinCompilerVersions().mapDynamicTest { version ->
14+
val compilerVersion = CompilerVersion.fromString(version)
15+
assertFalse(
16+
actual = compilerVersion.isAtLeast(CompilerVersion.fromString("1.5.30"))
1617
)
1718
}
1819

1920
@TestFactory
20-
fun compareSubstringApproachWithCompilerVersionClass() =
21-
kotlinVersionsOnMavenCentral().mapDynamicTest { kotlinVersion ->
22-
val compilerVersion = CompilerVersion.fromString(kotlinVersion).toString()
23-
val preDashPart = kotlinVersion.substringBefore(delimiter = '-')
24-
val postDashPart = kotlinVersion.substringAfter(delimiter = '-', missingDelimiterValue = "").let {
25-
if (it.isEmpty()) "" else "-$it"
26-
}
27-
val computedKotlinVersion = preDashPart.substringBefore(".0") + postDashPart
28-
@OptIn(ExperimentalStdlibApi::class)
29-
assertEquals(
30-
expected = compilerVersion,
31-
actual = computedKotlinVersion
32-
)
33-
}
21+
fun `check detection of supported Kotlin versions`() = supportedKotlinCompilerVersions().mapDynamicTest { version ->
22+
val compilerVersion = CompilerVersion.fromString(version)
23+
assertTrue(
24+
actual = compilerVersion.isAtLeast(CompilerVersion.fromString("1.5.30"))
25+
)
26+
}
27+
28+
private fun supportedKotlinCompilerVersions(): List<String> = listOf(
29+
"1.5.32",
30+
"1.6.0-M1",
31+
"1.6.0-RC",
32+
"1.6.0-RC2",
33+
"1.6.0",
34+
"1.6.10-RC",
35+
"1.6.10",
36+
)
3437

35-
private fun kotlinVersionsOnMavenCentral(): List<String> = listOf(
38+
private fun unsupportedKotlinCompilerVersions(): List<String> = listOf(
3639
"1.2.50",
3740
"1.2.51",
3841
"1.2.60",
@@ -64,7 +67,7 @@ class CompilerVersionTest {
6467
"1.4.20-RC",
6568
"1.4.20",
6669
"1.4.21",
67-
"1.4.21-2",
70+
//"1.4.21-2", Fails with "Unknown meta version: 2", but it's unlikely we need to support this anymore.
6871
"1.4.30-M1",
6972
"1.4.30-RC",
7073
"1.4.30",

0 commit comments

Comments
 (0)