Add tests for "add kotlin-reflect.jar" quickfix

This commit is contained in:
Dmitry Jemerov
2017-08-30 14:29:10 +02:00
parent feeacda12b
commit 92103ff393
9 changed files with 199 additions and 6 deletions
@@ -29,7 +29,7 @@ import org.junit.Test
import java.io.File
import kotlin.reflect.KMutableProperty0
class MavenLanguageFeatureQuickFixTest : MavenImportingTestCase() {
class MavenUpdateConfigurationQuickFixTest : MavenImportingTestCase() {
private lateinit var codeInsightTestFixture: CodeInsightTestFixture
fun getTestDataPath() = KotlinTestUtils.getHomeDirectory() + "/idea/idea-maven/testData/languageFeature/" + getTestName(true).substringBefore('_')
@@ -66,6 +66,10 @@ class MavenLanguageFeatureQuickFixTest : MavenImportingTestCase() {
doTest("Enable coroutine support in the current module")
}
@Test fun testAddKotlinReflect() {
doTest("Add kotlin-reflect.jar to the classpath")
}
private fun doTest(intentionName: String) {
val pomVFile = createProjectSubFile("pom.xml", File(getTestDataPath(), "pom.xml").readText())
val sourceVFile = createProjectSubFile("src/main/kotlin/src.kt", File(getTestDataPath(), "src.kt").readText())
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>maventest</groupId>
<artifactId>maventest</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<kotlin.version>$VERSION$</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jre8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>wrong-goal</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>maventest</groupId>
<artifactId>maventest</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<kotlin.version>$VERSION$</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jre8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>wrong-goal</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,7 @@
import kotlin.reflect.full.*
class Foo(val prop: Any) {
fun func() {}
}
fun y01() = Foo::prop.gett<caret>er
@@ -0,0 +1,18 @@
group 'Again'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
}
}
apply plugin: 'kotlin'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
}
@@ -0,0 +1,19 @@
group 'Again'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
}
}
apply plugin: 'kotlin'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
compile "org.jetbrains.kotlin:kotlin-reflect:1.1.0"
}
@@ -0,0 +1,7 @@
import kotlin.reflect.full.*
class Foo(val prop: Any) {
fun func() {}
}
fun y01() = Foo::prop.gett<caret>er
@@ -29,7 +29,7 @@ import org.junit.Test
import java.io.File
import kotlin.reflect.KMutableProperty0
class GradleLanguageFeatureQuickFixTest : GradleImportingTestCase() {
class GradleUpdateConfigurationQuickFixTest : GradleImportingTestCase() {
private lateinit var codeInsightTestFixture: CodeInsightTestFixture
fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/gradle/languageFeature/" + getTestName(true).substringBefore('_')
@@ -62,6 +62,10 @@ class GradleLanguageFeatureQuickFixTest : GradleImportingTestCase() {
doTest("Enable coroutine support in the current module")
}
@Test fun testAddKotlinReflect() {
doTest("Add kotlin-reflect.jar to the classpath")
}
private fun doTest(intentionName: String) {
val buildGradleVFile = createProjectSubFile("build.gradle", File(getTestDataPath(), "build.gradle").readText())
importProject()
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
import org.jetbrains.kotlin.idea.configuration.KotlinJavaModuleConfigurator
import org.jetbrains.kotlin.idea.facet.KotlinFacetType
import org.jetbrains.kotlin.idea.facet.getRuntimeLibraryVersion
import org.jetbrains.kotlin.idea.project.getLanguageVersionSettings
@@ -38,7 +39,7 @@ import org.jetbrains.kotlin.idea.test.configureKotlinFacet
import org.jetbrains.kotlin.idea.versions.bundledRuntimeVersion
import java.io.File
class LanguageFeatureQuickFixTest : LightPlatformCodeInsightFixtureTestCase() {
class UpdateConfigurationQuickFixTest : LightPlatformCodeInsightFixtureTestCase() {
fun testEnableCoroutines() {
configureRuntime("mockRuntime11")
resetProjectSettings(LanguageVersion.KOTLIN_1_1)
@@ -148,10 +149,26 @@ class LanguageFeatureQuickFixTest : LightPlatformCodeInsightFixtureTestCase() {
assertEquals(bundledRuntimeVersion(), getRuntimeLibraryVersion(myFixture.module))
}
fun testAddKotlinReflect() {
configureRuntime("mockRuntime11")
myFixture.configureByText("foo.kt", """class Foo(val prop: Any) {
fun func() {}
}
fun y01() = Foo::prop.gett<caret>er
""")
myFixture.launchAction(myFixture.findSingleIntention("Add kotlin-reflect.jar to the classpath"))
val kotlinRuntime = KotlinJavaModuleConfigurator.instance.getKotlinLibrary(myModule)!!
val classes = kotlinRuntime.getFiles(OrderRootType.CLASSES).map { it.name }
assertContainsElements(classes, "kotlin-reflect.jar")
val sources = kotlinRuntime.getFiles(OrderRootType.SOURCES)
assertContainsElements(sources.map { it.name }, "kotlin-reflect-sources.jar")
}
private fun configureRuntime(path: String) {
val name = if (path == "mockRuntime106") "kotlin-runtime" else "kotlin-stdlib"
val tempFile = FileUtil.createTempFile(name, ".jar")
FileUtil.copy(File("idea/testData/configuration/$path/$name.jar"), tempFile)
val name = if (path == "mockRuntime106") "kotlin-runtime.jar" else "kotlin-stdlib.jar"
val tempFile = File(FileUtil.createTempDirectory("kotlin-update-configuration", null), name)
FileUtil.copy(File("idea/testData/configuration/$path/$name"), tempFile)
val tempVFile = LocalFileSystem.getInstance().findFileByIoFile(tempFile)!!
updateModel(myFixture.module) { model ->