diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCase.java b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCase.java index 9aca849b09a..35e57d7482b 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCase.java +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCase.java @@ -271,7 +271,7 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { } } - private static void setFileContent(final VirtualFile file, final String content, final boolean advanceStamps) throws IOException { + protected static void setFileContent(final VirtualFile file, final String content, final boolean advanceStamps) throws IOException { new WriteAction() { @Override protected void run(@NotNull Result result) throws Throwable { diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleTestRunConfigurationAndHighlightingTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleTestRunConfigurationAndHighlightingTest.kt new file mode 100644 index 00000000000..5494b630fae --- /dev/null +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleTestRunConfigurationAndHighlightingTest.kt @@ -0,0 +1,90 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.codeInsight.gradle + +import com.intellij.codeInsight.daemon.LineMarkerInfo +import com.intellij.execution.PsiLocation +import com.intellij.execution.actions.ConfigurationContext +import com.intellij.execution.actions.ConfigurationFromContext +import org.jetbrains.kotlin.gradle.GradleDaemonAnalyzerTestCase +import org.jetbrains.kotlin.gradle.checkFiles +import org.jetbrains.kotlin.idea.run.KotlinGradleRunConfiguration +import org.jetbrains.kotlin.test.TagsTestDataUtil +import org.junit.Test + +class GradleTestRunConfigurationAndHighlightingTest : GradleImportingTestCase() { + @Test + fun testExpectClassWithTests() { + doTest() + } + + @Test + fun testKotlinJUnitSettings() { + doTest() + } + + @Test + fun preferredConfigurations() { + doTest() + } + + private fun doTest() { + val files = importProjectFromTestData() + val project = myTestFixture.project + + checkFiles( + files.filter { it.extension == "kt" }, + project, + object : GradleDaemonAnalyzerTestCase(testLineMarkers = true, checkWarnings = true, checkInfos = false) { + override fun renderAdditionalAttributeForTag(tag: TagsTestDataUtil.TagInfo<*>): String? { + val lineMarkerInfo = tag.data as? LineMarkerInfo<*> ?: return null + + // Hacky way to check if it's test line-marker info. Can't rely on extractConfigurationsFromContext returning no + // suitable configurationsFromContext, because it basically works on offsets, so if for some range we have two + // line markers - one with tests, and one without, - then we'll get proper ConfigurationFromContext for both + if ("Run Test" !in lineMarkerInfo.lineMarkerTooltip.orEmpty()) return null + + val kotlinConfigsFromContext = lineMarkerInfo.extractConfigurationsFromContext() + .filter { it.configuration is KotlinGradleRunConfiguration } + + if (kotlinConfigsFromContext.isEmpty()) return "settings=\"Nothing here\"" + + val configFromContext = kotlinConfigsFromContext.single() // can we have more than one? + + return "settings=\"${configFromContext.renderDescription().replace("\"", "\\\"")}\"" + } + } + ) + } + + private fun ConfigurationFromContext.renderDescription(): String { + val configuration = configuration as KotlinGradleRunConfiguration + + val location = PsiLocation(sourceElement) + val context = ConfigurationContext.createEmptyContextForLocation(location) + + var result: String? = null + + // We can not use settings straight away, because exact settings are determined only after 'onFirstRun' + // (see MultiplatformTestTasksChooser) + onFirstRun(context) { + result = configuration.settings.toString() + } + + return result!! + } + + private fun LineMarkerInfo<*>.extractConfigurationsFromContext(): List { + val location = PsiLocation(element) + + // TODO(dsavvinov): consider getting proper context somehow + val context = ConfigurationContext.createEmptyContextForLocation(location) + + return context.configurationsFromContext.orEmpty() + } + + override fun testDataDirName(): String = "testRunConfigurations" +} \ No newline at end of file diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleTestRunConfigurationTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleTestRunConfigurationCustomTest.kt similarity index 89% rename from idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleTestRunConfigurationTest.kt rename to idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleTestRunConfigurationCustomTest.kt index 32424920b8a..930abfe6147 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleTestRunConfigurationTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleTestRunConfigurationCustomTest.kt @@ -10,16 +10,19 @@ import com.intellij.execution.configurations.ConfigurationType import com.intellij.execution.configurations.ConfigurationTypeUtil import com.intellij.execution.junit.JUnitConfiguration import com.intellij.execution.junit.JUnitConfigurationType -import org.junit.Test +import com.intellij.openapi.vfs.VirtualFile import com.intellij.testFramework.runInEdtAndWait import com.intellij.util.PlatformUtils +import org.jetbrains.kotlin.gradle.textWithoutTags import org.jetbrains.kotlin.idea.run.* import org.jetbrains.kotlin.idea.util.application.runReadAction +import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer import org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions +import org.junit.Test -class GradleTestRunConfigurationTest : GradleImportingTestCase() { +class GradleTestRunConfigurationCustomTest : GradleImportingTestCase() { @Test @TargetVersions("4.7+") fun testPreferredConfigurations() { @@ -87,4 +90,10 @@ class GradleTestRunConfigurationTest : GradleImportingTestCase() { override fun testDataDirName(): String { return "testRunConfigurations" } + + override fun createProjectSubFile(relativePath: String, content: String): VirtualFile { + val file = createProjectSubFile(relativePath) + ExternalSystemTestCase.setFileContent(file, textWithoutTags(content), /* advanceStamps = */ false) + return file + } } \ No newline at end of file diff --git a/idea/testData/gradle/testRunConfigurations/kotlinJUnitSettings/src/test/kotlin/MyKotlinTest.kt b/idea/testData/gradle/testRunConfigurations/kotlinJUnitSettings/src/test/kotlin/MyKotlinTest.kt index 275124faed4..bb3f0efe827 100755 --- a/idea/testData/gradle/testRunConfigurations/kotlinJUnitSettings/src/test/kotlin/MyKotlinTest.kt +++ b/idea/testData/gradle/testRunConfigurations/kotlinJUnitSettings/src/test/kotlin/MyKotlinTest.kt @@ -1,7 +1,7 @@ import org.junit.Test -class MyKotlinTest { +class MyKotlinTest { @Test - fun testA() { + fun testA() { } } \ No newline at end of file diff --git a/idea/testData/gradle/testRunConfigurations/preferredConfigurations/src/test/kotlin/MyKotlinTest.kt b/idea/testData/gradle/testRunConfigurations/preferredConfigurations/src/test/kotlin/MyKotlinTest.kt index b716ac97ded..62944811dec 100755 --- a/idea/testData/gradle/testRunConfigurations/preferredConfigurations/src/test/kotlin/MyKotlinTest.kt +++ b/idea/testData/gradle/testRunConfigurations/preferredConfigurations/src/test/kotlin/MyKotlinTest.kt @@ -1,11 +1,11 @@ import org.junit.Test -class MyKotlinTest { +class MyKotlinTest { @Test - fun testA() { + fun testA() { } @Test - fun testB() { + fun testB() { } } \ No newline at end of file