diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleInspectionTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleInspectionTest.kt index 049dcb6b4eb..9914b00360d 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleInspectionTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleInspectionTest.kt @@ -20,20 +20,17 @@ import com.intellij.codeInspection.LocalInspectionTool import com.intellij.codeInspection.ProblemDescriptorBase import com.intellij.openapi.util.Ref import com.intellij.openapi.vfs.VirtualFile -import org.jetbrains.kotlin.idea.inspections.gradle.DeprecatedGradleDependencyInspection import org.jetbrains.kotlin.idea.inspections.gradle.DifferentKotlinGradleVersionInspection -import org.jetbrains.kotlin.idea.inspections.gradle.DifferentStdlibGradleVersionInspection -import org.jetbrains.kotlin.idea.inspections.gradle.GradleKotlinxCoroutinesDeprecationInspection import org.jetbrains.kotlin.idea.inspections.runInspection import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions import org.junit.Assert import org.junit.Test +import java.io.File class GradleInspectionTest : GradleImportingTestCase() { @Test fun testDifferentStdlibGradleVersion() { - val tool = DifferentStdlibGradleVersionInspection() - val problems = getInspectionResultFromTestDataProject(tool) + val problems = getInspectionResultFromTestDataProject() Assert.assertTrue(problems.size == 1) Assert.assertEquals("Plugin version (1.0.2) is not the same as library version (1.0.3)", problems.single()) @@ -41,8 +38,7 @@ class GradleInspectionTest : GradleImportingTestCase() { @Test fun testDifferentStdlibGradleVersionWithImplementation() { - val tool = DifferentStdlibGradleVersionInspection() - val problems = getInspectionResultFromTestDataProject(tool) + val problems = getInspectionResultFromTestDataProject() Assert.assertTrue(problems.size == 1) Assert.assertEquals("Plugin version (1.0.2) is not the same as library version (1.0.3)", problems.single()) @@ -50,8 +46,7 @@ class GradleInspectionTest : GradleImportingTestCase() { @Test fun testDifferentStdlibJre7GradleVersion() { - val tool = DifferentStdlibGradleVersionInspection() - val problems = getInspectionResultFromTestDataProject(tool) + val problems = getInspectionResultFromTestDataProject() Assert.assertTrue(problems.size == 1) Assert.assertEquals("Plugin version (1.1.0-beta-17) is not the same as library version (1.1.0-beta-22)", problems.single()) @@ -59,8 +54,7 @@ class GradleInspectionTest : GradleImportingTestCase() { @Test fun testDifferentStdlibJdk7GradleVersion() { - val tool = DifferentStdlibGradleVersionInspection() - val problems = getInspectionResultFromTestDataProject(tool) + val problems = getInspectionResultFromTestDataProject() Assert.assertTrue(problems.size == 1) Assert.assertEquals("Plugin version (1.1.0-beta-17) is not the same as library version (1.1.0-beta-22)", problems.single()) @@ -68,8 +62,7 @@ class GradleInspectionTest : GradleImportingTestCase() { @Test fun testDifferentStdlibGradleVersionWithVariables() { - val tool = DifferentStdlibGradleVersionInspection() - val problems = getInspectionResultFromTestDataProject(tool) + val problems = getInspectionResultFromTestDataProject() Assert.assertTrue(problems.size == 1) Assert.assertEquals("Plugin version (1.0.1) is not the same as library version (1.0.3)", problems.single()) @@ -90,16 +83,14 @@ class GradleInspectionTest : GradleImportingTestCase() { @Test fun testJreInOldVersion() { - val tool = DeprecatedGradleDependencyInspection() - val problems = getInspectionResultFromTestDataProject(tool) + val problems = getInspectionResultFromTestDataProject() Assert.assertTrue(problems.isEmpty()) } @Test fun testJreIsDeprecated() { - val tool = DeprecatedGradleDependencyInspection() - val problems = getInspectionResultFromTestDataProject(tool) + val problems = getInspectionResultFromTestDataProject() Assert.assertTrue(problems.size == 1) Assert.assertEquals( @@ -110,8 +101,7 @@ class GradleInspectionTest : GradleImportingTestCase() { @Test fun testJreIsDeprecatedWithImplementation() { - val tool = DeprecatedGradleDependencyInspection() - val problems = getInspectionResultFromTestDataProject(tool) + val problems = getInspectionResultFromTestDataProject() Assert.assertTrue(problems.size == 1) Assert.assertEquals( @@ -123,8 +113,7 @@ class GradleInspectionTest : GradleImportingTestCase() { @TargetVersions("4.9+") @Test fun testJreIsDeprecatedWithoutImplicitVersion() { - val tool = DeprecatedGradleDependencyInspection() - val problems = getInspectionResultFromTestDataProject(tool) + val problems = getInspectionResultFromTestDataProject() Assert.assertTrue(problems.size == 1) Assert.assertEquals( @@ -135,24 +124,21 @@ class GradleInspectionTest : GradleImportingTestCase() { @Test fun testNoDifferentStdlibCommonGradleVersion() { - val tool = DifferentStdlibGradleVersionInspection() - val problems = getInspectionResultFromTestDataProject(tool) + val problems = getInspectionResultFromTestDataProject() Assert.assertTrue(problems.toString(), problems.isEmpty()) } @Test fun testNoDifferentStdlibJdk7GradleVersion() { - val tool = DifferentStdlibGradleVersionInspection() - val problems = getInspectionResultFromTestDataProject(tool) + val problems = getInspectionResultFromTestDataProject() Assert.assertTrue(problems.toString(), problems.isEmpty()) } @Test fun testObsoleteCoroutinesUsage() { - val tool = GradleKotlinxCoroutinesDeprecationInspection() - val problems = getInspectionResultFromTestDataProject(tool) + val problems = getInspectionResultFromTestDataProject() Assert.assertTrue(problems.size == 1) Assert.assertEquals( @@ -161,8 +147,12 @@ class GradleInspectionTest : GradleImportingTestCase() { ) } - private fun getInspectionResultFromTestDataProject(tool: LocalInspectionTool): List { + private fun getInspectionResultFromTestDataProject(explicitTool: LocalInspectionTool? = null): List { val buildGradle = importProjectFromTestData().find { it.name == "build.gradle" }!! + val tool = explicitTool ?: run { + val toolName = File(buildGradle.path).readLines().find { it.startsWith(TOOL) }!!.substring(TOOL.length) + Class.forName("org.jetbrains.kotlin.idea.inspections.gradle.$toolName").newInstance() as LocalInspectionTool + } return getInspectionResult(tool, buildGradle) } @@ -185,4 +175,8 @@ class GradleInspectionTest : GradleImportingTestCase() { override fun testDataDirName(): String { return "inspections" } + + companion object { + private const val TOOL = "// TOOL: " + } } \ No newline at end of file diff --git a/idea/testData/gradle/inspections/differentKotlinGradleVersion/build.gradle b/idea/testData/gradle/inspections/differentKotlinGradleVersion/build.gradle index 9514792202e..f691e1922d4 100644 --- a/idea/testData/gradle/inspections/differentKotlinGradleVersion/build.gradle +++ b/idea/testData/gradle/inspections/differentKotlinGradleVersion/build.gradle @@ -1,3 +1,5 @@ +// TOOL: DifferentKotlinGradleVersionInspection + group 'Again' version '1.0-SNAPSHOT' diff --git a/idea/testData/gradle/inspections/differentStdlibGradleVersion/build.gradle b/idea/testData/gradle/inspections/differentStdlibGradleVersion/build.gradle index 475abbc9577..16327230374 100644 --- a/idea/testData/gradle/inspections/differentStdlibGradleVersion/build.gradle +++ b/idea/testData/gradle/inspections/differentStdlibGradleVersion/build.gradle @@ -1,3 +1,5 @@ +// TOOL: DifferentStdlibGradleVersionInspection + group 'Again' version '1.0-SNAPSHOT' diff --git a/idea/testData/gradle/inspections/differentStdlibGradleVersionWithImplementation/build.gradle b/idea/testData/gradle/inspections/differentStdlibGradleVersionWithImplementation/build.gradle index 657e98c3ebb..8b1e99ca460 100644 --- a/idea/testData/gradle/inspections/differentStdlibGradleVersionWithImplementation/build.gradle +++ b/idea/testData/gradle/inspections/differentStdlibGradleVersionWithImplementation/build.gradle @@ -1,3 +1,5 @@ +// TOOL: DifferentStdlibGradleVersionInspection + group 'Again' version '1.0-SNAPSHOT' diff --git a/idea/testData/gradle/inspections/differentStdlibGradleVersionWithVariables/build.gradle b/idea/testData/gradle/inspections/differentStdlibGradleVersionWithVariables/build.gradle index d21a71f6eef..a3a3f9ea7c3 100644 --- a/idea/testData/gradle/inspections/differentStdlibGradleVersionWithVariables/build.gradle +++ b/idea/testData/gradle/inspections/differentStdlibGradleVersionWithVariables/build.gradle @@ -1,3 +1,5 @@ +// TOOL: DifferentStdlibGradleVersionInspection + group 'Again' version '1.0-SNAPSHOT' diff --git a/idea/testData/gradle/inspections/differentStdlibJdk7GradleVersion/build.gradle b/idea/testData/gradle/inspections/differentStdlibJdk7GradleVersion/build.gradle index 180e5747b8b..d2d55e45e7c 100644 --- a/idea/testData/gradle/inspections/differentStdlibJdk7GradleVersion/build.gradle +++ b/idea/testData/gradle/inspections/differentStdlibJdk7GradleVersion/build.gradle @@ -1,3 +1,5 @@ +// TOOL: DifferentStdlibGradleVersionInspection + group 'Again' version '1.0-SNAPSHOT' diff --git a/idea/testData/gradle/inspections/differentStdlibJre7GradleVersion/build.gradle b/idea/testData/gradle/inspections/differentStdlibJre7GradleVersion/build.gradle index 1371971ece6..49b9fb2bc64 100644 --- a/idea/testData/gradle/inspections/differentStdlibJre7GradleVersion/build.gradle +++ b/idea/testData/gradle/inspections/differentStdlibJre7GradleVersion/build.gradle @@ -1,3 +1,5 @@ +// TOOL: DifferentStdlibGradleVersionInspection + group 'Again' version '1.0-SNAPSHOT' diff --git a/idea/testData/gradle/inspections/jreInOldVersion/build.gradle b/idea/testData/gradle/inspections/jreInOldVersion/build.gradle index 4d1e61c137e..158c136b0c1 100644 --- a/idea/testData/gradle/inspections/jreInOldVersion/build.gradle +++ b/idea/testData/gradle/inspections/jreInOldVersion/build.gradle @@ -1,3 +1,5 @@ +// TOOL: DeprecatedGradleDependencyInspection + group 'Again' version '1.0-SNAPSHOT' diff --git a/idea/testData/gradle/inspections/jreIsDeprecated/build.gradle b/idea/testData/gradle/inspections/jreIsDeprecated/build.gradle index 9a28826bd50..cd74993de6f 100644 --- a/idea/testData/gradle/inspections/jreIsDeprecated/build.gradle +++ b/idea/testData/gradle/inspections/jreIsDeprecated/build.gradle @@ -1,3 +1,5 @@ +// TOOL: DeprecatedGradleDependencyInspection + group 'Again' version '1.0-SNAPSHOT' diff --git a/idea/testData/gradle/inspections/jreIsDeprecatedWithImplementation/build.gradle b/idea/testData/gradle/inspections/jreIsDeprecatedWithImplementation/build.gradle index 1b6e584664d..e51e4e91fd2 100644 --- a/idea/testData/gradle/inspections/jreIsDeprecatedWithImplementation/build.gradle +++ b/idea/testData/gradle/inspections/jreIsDeprecatedWithImplementation/build.gradle @@ -1,3 +1,5 @@ +// TOOL: DeprecatedGradleDependencyInspection + group 'Again' version '1.0-SNAPSHOT' diff --git a/idea/testData/gradle/inspections/jreIsDeprecatedWithoutImplicitVersion/build.gradle b/idea/testData/gradle/inspections/jreIsDeprecatedWithoutImplicitVersion/build.gradle index b0bce5605c4..77b1fdb493c 100644 --- a/idea/testData/gradle/inspections/jreIsDeprecatedWithoutImplicitVersion/build.gradle +++ b/idea/testData/gradle/inspections/jreIsDeprecatedWithoutImplicitVersion/build.gradle @@ -1,3 +1,5 @@ +// TOOL: DeprecatedGradleDependencyInspection + group 'Again' version '1.0-SNAPSHOT' diff --git a/idea/testData/gradle/inspections/noDifferentStdlibCommonGradleVersion/build.gradle b/idea/testData/gradle/inspections/noDifferentStdlibCommonGradleVersion/build.gradle index 73f5a13c72a..e0694e9bd49 100644 --- a/idea/testData/gradle/inspections/noDifferentStdlibCommonGradleVersion/build.gradle +++ b/idea/testData/gradle/inspections/noDifferentStdlibCommonGradleVersion/build.gradle @@ -1,3 +1,5 @@ +// TOOL: DifferentStdlibGradleVersionInspection + group 'Again' version '1.0-SNAPSHOT' diff --git a/idea/testData/gradle/inspections/noDifferentStdlibJdk7GradleVersion/build.gradle b/idea/testData/gradle/inspections/noDifferentStdlibJdk7GradleVersion/build.gradle index 422b710fd65..bf49d4b43cc 100644 --- a/idea/testData/gradle/inspections/noDifferentStdlibJdk7GradleVersion/build.gradle +++ b/idea/testData/gradle/inspections/noDifferentStdlibJdk7GradleVersion/build.gradle @@ -1,3 +1,5 @@ +// TOOL: DifferentStdlibGradleVersionInspection + group 'Again' version '1.0-SNAPSHOT' diff --git a/idea/testData/gradle/inspections/obsoleteCoroutinesUsage/build.gradle b/idea/testData/gradle/inspections/obsoleteCoroutinesUsage/build.gradle index d15ae9aaa48..92fd6babea5 100644 --- a/idea/testData/gradle/inspections/obsoleteCoroutinesUsage/build.gradle +++ b/idea/testData/gradle/inspections/obsoleteCoroutinesUsage/build.gradle @@ -1,3 +1,5 @@ +// TOOL: GradleKotlinxCoroutinesDeprecationInspection + group 'Again' version '1.0-SNAPSHOT'