Skip to content

Commit 73a2c8c

Browse files
committed
Test quickfixes for updating language/API version and coroutine support in Gradle projects
1 parent 5d461ec commit 73a2c8c

File tree

14 files changed

+267
-3
lines changed

14 files changed

+267
-3
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
group 'Again'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
11+
}
12+
}
13+
14+
apply plugin: 'kotlin'
15+
16+
dependencies {
17+
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
group 'Again'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
11+
}
12+
}
13+
14+
apply plugin: 'kotlin'
15+
16+
dependencies {
17+
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
18+
}
19+
kotlin {
20+
experimental {
21+
coroutines "enable"
22+
}
23+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
suspend fun foo() {
2+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
group 'Again'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
11+
}
12+
}
13+
14+
apply plugin: 'kotlin'
15+
16+
dependencies {
17+
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
18+
}
19+
20+
compileKotlin {
21+
kotlinOptions.apiVersion = "1.0"
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
group 'Again'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
11+
}
12+
}
13+
14+
apply plugin: 'kotlin'
15+
16+
dependencies {
17+
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
18+
}
19+
20+
compileKotlin {
21+
kotlinOptions.apiVersion = "1.1"
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val x = <caret>"s"::length
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
group 'Again'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
11+
}
12+
}
13+
14+
apply plugin: 'kotlin'
15+
16+
dependencies {
17+
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
18+
}
19+
20+
compileKotlin {
21+
kotlinOptions.languageVersion = "1.0"
22+
kotlinOptions.apiVersion = "1.0"
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
group 'Again'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
11+
}
12+
}
13+
14+
apply plugin: 'kotlin'
15+
16+
dependencies {
17+
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
18+
}
19+
20+
compileKotlin {
21+
kotlinOptions.languageVersion = "1.1"
22+
kotlinOptions.apiVersion = "1.1"
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val x = <caret>"s"::length
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
group 'Again'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
11+
}
12+
}
13+
14+
apply plugin: 'kotlin'
15+
16+
dependencies {
17+
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
18+
}
19+
20+
compileKotlin {
21+
kotlinOptions.languageVersion = "1.0"
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
group 'Again'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
11+
}
12+
}
13+
14+
apply plugin: 'kotlin'
15+
16+
dependencies {
17+
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
18+
}
19+
20+
compileKotlin {
21+
kotlinOptions.languageVersion = "1.1"
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val x get() = 1

idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
public abstract class ExternalSystemTestCase extends UsefulTestCase {
5656
private File ourTempDir;
5757

58-
private IdeaProjectTestFixture myTestFixture;
58+
protected IdeaProjectTestFixture myTestFixture;
5959

6060
protected Project myProject;
6161

@@ -141,7 +141,7 @@ private void ensureTempDirCreated() throws IOException {
141141

142142
protected abstract String getTestsTempDir();
143143

144-
private void setUpFixtures() throws Exception {
144+
protected void setUpFixtures() throws Exception {
145145
myTestFixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName()).getFixture();
146146
myTestFixture.setUp();
147147
}
@@ -176,7 +176,7 @@ public void run() throws Throwable {
176176
}
177177
}
178178

179-
private void tearDownFixtures() throws Exception {
179+
protected void tearDownFixtures() throws Exception {
180180
myTestFixture.tearDown();
181181
myTestFixture = null;
182182
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2010-2017 JetBrains s.r.o.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jetbrains.kotlin.idea.codeInsight.gradle
18+
19+
import com.intellij.openapi.fileEditor.FileDocumentManager
20+
import com.intellij.openapi.fileEditor.impl.LoadTextUtil
21+
import com.intellij.openapi.vfs.VirtualFile
22+
import com.intellij.rt.execution.junit.FileComparisonFailure
23+
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
24+
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
25+
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
26+
import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait
27+
import org.junit.Test
28+
import java.io.File
29+
import kotlin.reflect.KMutableProperty0
30+
31+
class GradleLanguageFeatureQuickFixTest : GradleImportingTestCase() {
32+
private lateinit var codeInsightTestFixture: CodeInsightTestFixture
33+
34+
fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/gradle/languageFeature/" + getTestName(true).substringBefore('_')
35+
36+
override fun setUpFixtures() {
37+
myTestFixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName()).fixture
38+
codeInsightTestFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(myTestFixture)
39+
codeInsightTestFixture.setUp()
40+
}
41+
42+
override fun tearDownFixtures() {
43+
codeInsightTestFixture.tearDown()
44+
(this::codeInsightTestFixture as KMutableProperty0<CodeInsightTestFixture?>).set(null)
45+
myTestFixture = null
46+
}
47+
48+
@Test fun testUpdateLanguageVersion() {
49+
doTest("Set module language version to 1.1")
50+
}
51+
52+
@Test fun testUpdateApiVersion() {
53+
doTest("Set module API version to 1.1")
54+
}
55+
56+
@Test fun testUpdateLanguageAndApiVersion() {
57+
doTest("Set module language version to 1.1")
58+
}
59+
60+
@Test fun testEnableCoroutines() {
61+
doTest("Enable coroutine support in the current module")
62+
}
63+
64+
private fun doTest(intentionName: String) {
65+
val buildGradleVFile = createProjectSubFile("build.gradle", File(getTestDataPath(), "build.gradle").readText())
66+
importProject()
67+
runInEdtAndWait {
68+
val sourceVFile = createProjectSubFile("src/main/kotlin/src.kt", File(getTestDataPath(), "src.kt").readText())
69+
codeInsightTestFixture.configureFromExistingVirtualFile(sourceVFile)
70+
codeInsightTestFixture.launchAction(codeInsightTestFixture.findSingleIntention(intentionName))
71+
FileDocumentManager.getInstance().saveAllDocuments()
72+
checkResult(buildGradleVFile)
73+
}
74+
}
75+
76+
private fun checkResult(file: VirtualFile) {
77+
val expectedPath = File(getTestDataPath(), "build.gradle.after")
78+
val expectedContent = expectedPath.readText()
79+
val actualContent = LoadTextUtil.loadText(file).toString()
80+
if (actualContent != expectedContent) {
81+
throw FileComparisonFailure("build.gradle doesn't match", expectedContent, actualContent, expectedPath.path)
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)