[Kotlin] Added and fixed tests for updating Kotlin language version in Gradle projects

KTIJ-25700

GitOrigin-RevId: 11b65ac516b2e6836d6e5922b26a335dbf65c29c
This commit is contained in:
Frederik Haselmeier
2024-07-18 21:01:57 +00:00
committed by intellij-monorepo-bot
parent 50e4931ee8
commit f1b3b73d49
25 changed files with 355 additions and 42 deletions
@@ -45,9 +45,51 @@ class GradleUpdateConfigurationQuickFixTest : GradleImportingTestCase() {
}
@Test
@TargetVersions("4.7 <=> 6.0")
@TargetVersions("7.0 <=> 9.0")
fun testUpdateExistingLanguageVersion() {
doTest("Set module language version to 1.9")
}
@Test
@TargetVersions("7.0 <=> 9.0")
fun testUpdateExistingLanguageVersionKts() {
doTest("Set module language version to 1.9")
}
@Test
@TargetVersions("7.0 <=> 9.0")
fun testUpdateExistingLanguageVersionKMP() {
doKMPTest("Set module language version to 1.9")
}
@Test
@TargetVersions("7.0 <=> 9.0")
fun testUpdateExistingLanguageVersionKMPKts() {
doKMPTest("Set module language version to 1.9")
}
@Test
@TargetVersions("7.0 <=> 9.0")
fun testUpdateLanguageVersion() {
doTest("Set module language version to 1.1")
doTest("Set module language version to 1.9")
}
@Test
@TargetVersions("7.0 <=> 9.0")
fun testUpdateLanguageVersionKts() {
doTest("Set module language version to 1.9")
}
@Test
@TargetVersions("7.0 <=> 9.0")
fun testUpdateLanguageVersionKMP() {
doKMPTest("Set module language version to 1.9")
}
@Test
@TargetVersions("7.0 <=> 9.0")
fun testUpdateLanguageVersionKMPKts() {
doKMPTest("Set module language version to 1.9")
}
@Test
@@ -71,9 +113,16 @@ class GradleUpdateConfigurationQuickFixTest : GradleImportingTestCase() {
doTest("Add 'kotlin-reflect.jar' to the classpath")
}
private fun doTest(intentionName: String) {
val buildGradleVFile = createProjectSubFile("build.gradle", File(getTestDataDirectory(), "build.gradle").readText())
val sourceVFile = createProjectSubFile("src/main/kotlin/src.kt", File(getTestDataDirectory(), "src.kt").readText())
private fun doKMPTest(intentionName: String) = doTest(intentionName, "src/jvmMain/kotlin/src.kt")
private fun doTest(intentionName: String, srcFilePath: String = "src/main/kotlin/src.kt") {
var gradleKtsFile = File(getTestDataDirectory(), "build.gradle.kts")
val buildGradleVFile = if (gradleKtsFile.exists()) {
createProjectSubFile("build.gradle.kts", gradleKtsFile.readText())
} else {
createProjectSubFile("build.gradle", File(getTestDataDirectory(), "build.gradle").readText())
}
val sourceVFile = createProjectSubFile(srcFilePath, File(getTestDataDirectory(), "src.kt").readText())
importProject()
runInEdtAndWait {
codeInsightTestFixture.configureFromExistingVirtualFile(sourceVFile)
@@ -84,11 +133,11 @@ class GradleUpdateConfigurationQuickFixTest : GradleImportingTestCase() {
}
private fun checkResult(file: VirtualFile) {
val expectedPath = File(getTestDataDirectory(), "build.gradle.after")
val expectedPath = File(getTestDataDirectory(), file.name + ".after")
val expectedContent = StringUtil.convertLineSeparators(expectedPath.readText())
val actualContent = StringUtil.convertLineSeparators(LoadTextUtil.loadText(file).toString())
if (actualContent != expectedContent) {
throw FileComparisonFailedError("build.gradle doesn't match", expectedContent, actualContent, expectedPath.path)
throw FileComparisonFailedError("${file.name} doesn't match", expectedContent, actualContent, expectedPath.path)
}
}
}
@@ -0,0 +1,15 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.8.0'
}
group = 'org.example'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
compileKotlin {
kotlinOptions {
languageVersion = "1.8"
}
}
@@ -0,0 +1,15 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.8.0'
}
group = 'org.example'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
compileKotlin {
kotlinOptions {
languageVersion = "1.9"
}
}
@@ -0,0 +1,23 @@
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.8.0'
}
repositories {
mavenCentral()
}
kotlin {
jvm {
withJava()
}
sourceSets {
jvmMain {
}
all {
languageSettings {
languageVersion = "1.8"
}
}
}
}
@@ -0,0 +1,23 @@
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.8.0'
}
repositories {
mavenCentral()
}
kotlin {
jvm {
withJava()
}
sourceSets {
jvmMain {
}
all {
languageSettings {
languageVersion = "1.9"
}
}
}
}
@@ -0,0 +1,25 @@
plugins {
kotlin("multiplatform") version "1.8.0"
}
repositories {
mavenCentral()
}
group = "com.example"
version = "1.0-SNAPSHOT"
kotlin {
jvm {
withJava()
}
sourceSets {
val jvmMain by getting {
}
all {
languageSettings {
languageVersion = "1.8"
}
}
}
}
@@ -0,0 +1,25 @@
plugins {
kotlin("multiplatform") version "1.8.0"
}
repositories {
mavenCentral()
}
group = "com.example"
version = "1.0-SNAPSHOT"
kotlin {
jvm {
withJava()
}
sourceSets {
val jvmMain by getting {
}
all {
languageSettings {
languageVersion = "1.9"
}
}
}
}
@@ -0,0 +1,16 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.8.0"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
languageVersion = "1.8"
}
@@ -0,0 +1,16 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.8.0"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
languageVersion = "1.9"
}
@@ -1,22 +1,10 @@
group 'Again'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.8.0'
}
apply plugin: 'kotlin'
group = 'org.example'
version = '1.0-SNAPSHOT'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
}
compileKotlin {
kotlinOptions.languageVersion = "1.0"
repositories {
mavenCentral()
}
@@ -1,22 +1,15 @@
group 'Again'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.8.0'
}
apply plugin: 'kotlin'
group = 'org.example'
version = '1.0-SNAPSHOT'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
repositories {
mavenCentral()
}
compileKotlin {
kotlinOptions.languageVersion = "1.1"
kotlinOptions {
languageVersion = "1.9"
}
}
@@ -1 +1 @@
val x get() = 1
data object Test
@@ -0,0 +1,21 @@
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.8.0'
}
repositories {
mavenCentral()
}
group = 'com.example'
version = '1.0-SNAPSHOT'
kotlin {
jvm {
withJava()
}
sourceSets {
jvmMain {
}
}
}
@@ -0,0 +1,26 @@
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.8.0'
}
repositories {
mavenCentral()
}
group = 'com.example'
version = '1.0-SNAPSHOT'
kotlin {
jvm {
withJava()
}
sourceSets {
jvmMain {
}
all {
languageSettings {
languageVersion = "1.9"
}
}
}
}
@@ -0,0 +1,20 @@
plugins {
kotlin("multiplatform") version "1.8.0"
}
repositories {
mavenCentral()
}
group = "com.example"
version = "1.0-SNAPSHOT"
kotlin {
jvm {
withJava()
}
sourceSets {
val jvmMain by getting {
}
}
}
@@ -0,0 +1,25 @@
plugins {
kotlin("multiplatform") version "1.8.0"
}
repositories {
mavenCentral()
}
group = "com.example"
version = "1.0-SNAPSHOT"
kotlin {
jvm {
withJava()
}
sourceSets {
val jvmMain by getting {
}
all {
languageSettings {
languageVersion = "1.9"
}
}
}
}
@@ -0,0 +1,10 @@
plugins {
kotlin("jvm") version "1.8.0"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
@@ -0,0 +1,16 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.8.0"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
languageVersion = "1.9"
}