diff --git a/idea/idea-fir-performance-tests/tests/org/jetbrains/kotlin/idea/perf/AbstractHighLevelPerformanceCompletionHandlerTests.kt b/idea/idea-fir-performance-tests/tests/org/jetbrains/kotlin/idea/perf/AbstractHighLevelPerformanceCompletionHandlerTests.kt index 036130ee40a..da8d952199e 100644 --- a/idea/idea-fir-performance-tests/tests/org/jetbrains/kotlin/idea/perf/AbstractHighLevelPerformanceCompletionHandlerTests.kt +++ b/idea/idea-fir-performance-tests/tests/org/jetbrains/kotlin/idea/perf/AbstractHighLevelPerformanceCompletionHandlerTests.kt @@ -6,7 +6,7 @@ package org.jetbrains.kotlin.idea.perf import com.intellij.codeInsight.completion.CompletionType -import org.jetbrains.kotlin.idea.completion.FIR_COMPARISON +import org.jetbrains.kotlin.test.uitls.IgnoreTests.DIRECTIVES import org.jetbrains.kotlin.test.InTextDirectivesUtils abstract class AbstractHighLevelPerformanceCompletionHandlerTests( @@ -17,7 +17,7 @@ abstract class AbstractHighLevelPerformanceCompletionHandlerTests( override val statsPrefix: String = "fir-completion" override fun doPerfTest(unused: String) { - if (!InTextDirectivesUtils.isDirectiveDefined(testDataFile().readText(), FIR_COMPARISON)) return + if (!InTextDirectivesUtils.isDirectiveDefined(testDataFile().readText(), DIRECTIVES.FIR_COMPARISON)) return super.doPerfTest(unused) } diff --git a/idea/idea-fir/build.gradle.kts b/idea/idea-fir/build.gradle.kts index 40925a12564..e90d560910b 100644 --- a/idea/idea-fir/build.gradle.kts +++ b/idea/idea-fir/build.gradle.kts @@ -21,6 +21,7 @@ dependencies { testCompile(projectTests(":idea:idea-frontend-fir")) testCompile(project(":kotlin-test:kotlin-test-junit")) testCompile(commonDep("junit:junit")) + testCompile(projectTests(":idea:idea-frontend-independent")) testCompileOnly(intellijDep()) testRuntime(intellijDep()) diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/AbstractFirClassLoadingTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/AbstractFirClassLoadingTest.kt index 7cc888354e2..207a50fe5b8 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/AbstractFirClassLoadingTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/AbstractFirClassLoadingTest.kt @@ -5,13 +5,10 @@ package org.jetbrains.kotlin.asJava.classes -import com.intellij.openapi.application.ApplicationManager import org.jetbrains.kotlin.asJava.KotlinAsJavaSupport -import org.jetbrains.kotlin.doTestWithFIRFlagsByPath import org.jetbrains.kotlin.executeOnPooledThreadInReadAction -import org.jetbrains.kotlin.idea.debugger.readAction +import org.jetbrains.kotlin.findUsages.doTestWithFIRFlagsByPath import org.jetbrains.kotlin.idea.perf.UltraLightChecker -import org.jetbrains.kotlin.idea.perf.UltraLightChecker.checkByJavaFile import org.jetbrains.kotlin.idea.perf.UltraLightChecker.getJavaFileForTest import org.jetbrains.kotlin.idea.perf.UltraLightChecker.renderLightClasses import org.jetbrains.kotlin.psi.KtFile diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/AbstractFirLightClassTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/AbstractFirLightClassTest.kt index 3555abe7814..574316ee496 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/AbstractFirLightClassTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/AbstractFirLightClassTest.kt @@ -6,8 +6,8 @@ package org.jetbrains.kotlin.asJava.classes import org.jetbrains.kotlin.asJava.LightClassTestCommon -import org.jetbrains.kotlin.doTestWithFIRFlagsByPath import org.jetbrains.kotlin.executeOnPooledThreadInReadAction +import org.jetbrains.kotlin.findUsages.doTestWithFIRFlagsByPath import org.jetbrains.kotlin.idea.caches.resolve.PsiElementChecker import org.jetbrains.kotlin.idea.caches.resolve.findClass import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/AbstractFirLightFacadeClassTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/AbstractFirLightFacadeClassTest.kt index 7844c1322d5..12920cc8a04 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/AbstractFirLightFacadeClassTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/AbstractFirLightFacadeClassTest.kt @@ -7,8 +7,8 @@ package org.jetbrains.kotlin.asJava.classes import com.intellij.psi.search.GlobalSearchScope import org.jetbrains.kotlin.asJava.KotlinAsJavaSupport -import org.jetbrains.kotlin.doTestWithFIRFlagsByPath import org.jetbrains.kotlin.executeOnPooledThreadInReadAction +import org.jetbrains.kotlin.findUsages.doTestWithFIRFlagsByPath import org.jetbrains.kotlin.idea.perf.UltraLightChecker import org.jetbrains.kotlin.idea.perf.UltraLightChecker.checkByJavaFile import org.jetbrains.kotlin.name.FqName diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/checkers/AbstractFirPsiCheckerTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/checkers/AbstractFirPsiCheckerTest.kt index dccabc251a7..ca86505e14f 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/checkers/AbstractFirPsiCheckerTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/checkers/AbstractFirPsiCheckerTest.kt @@ -6,11 +6,9 @@ package org.jetbrains.kotlin.checkers import com.intellij.rt.execution.junit.FileComparisonFailure -import org.jetbrains.kotlin.idea.completion.FIR_COMPARISON -import org.jetbrains.kotlin.idea.completion.runTestWithCustomEnableDirective import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions import org.jetbrains.kotlin.idea.withPossiblyDisabledDuplicatedFirSourceElementsException -import org.jetbrains.kotlin.test.InTextDirectivesUtils +import org.jetbrains.kotlin.test.uitls.IgnoreTests import java.io.File abstract class AbstractFirPsiCheckerTest : AbstractPsiCheckerTest() { @@ -19,7 +17,7 @@ abstract class AbstractFirPsiCheckerTest : AbstractPsiCheckerTest() { override fun isFirPlugin(): Boolean = true override fun doTest(filePath: String) { - runTestWithCustomEnableDirective(FIR_COMPARISON, testDataFile()) { + IgnoreTests.runTestIfEnabledByFileDirective(testDataFilePath(), IgnoreTests.DIRECTIVES.FIR_COMPARISON) { myFixture.configureByFile(fileName()) checkHighlighting(checkWarnings = false, checkInfos = false, checkWeakWarnings = false) } diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesFirTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesFirTest.kt new file mode 100644 index 00000000000..4c2a7f5b44b --- /dev/null +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesFirTest.kt @@ -0,0 +1,16 @@ +/* + * 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.findUsages + +import com.intellij.psi.PsiElement + +abstract class AbstractFindUsagesFirTest : AbstractFindUsagesTest() { + override fun isFirPlugin(): Boolean = true + + override fun doTest(path: String) = doTestWithFIRFlagsByPath(path) { + super.doTest(path) + } +} \ No newline at end of file diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesWithDisableComponentSearchFirTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesWithDisableComponentSearchFirTest.kt new file mode 100644 index 00000000000..6f653576a19 --- /dev/null +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesWithDisableComponentSearchFirTest.kt @@ -0,0 +1,17 @@ +/* + * 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.findUsages + +import com.intellij.psi.PsiElement + +abstract class AbstractFindUsagesWithDisableComponentSearchFirTest : AbstractFindUsagesWithDisableComponentSearchTest() { + override fun isFirPlugin(): Boolean = true + + override fun doTest(path: String) = doTestWithFIRFlagsByPath(path) { + super.doTest(path) + } +} + diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesWithLibraryTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesWithLibraryTest.kt new file mode 100644 index 00000000000..ae5fc2ee12b --- /dev/null +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesWithLibraryTest.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2010-2019 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.findUsages + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.idea.test.PluginTestCaseBase +import org.jetbrains.kotlin.idea.test.SdkAndMockLibraryProjectDescriptor + +abstract class AbstractKotlinFindUsagesWithLibraryFirTest : AbstractKotlinFindUsagesWithLibraryTest() { + override fun isFirPlugin(): Boolean = true + + override fun doTest(path: String) = doTestWithFIRFlagsByPath(path) { + super.doTest(path) + } +} \ No newline at end of file diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesWithStdlibTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesWithStdlibTest.kt new file mode 100644 index 00000000000..1a00a9b04dc --- /dev/null +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesWithStdlibTest.kt @@ -0,0 +1,17 @@ +/* + * 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.findUsages + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.idea.test.KotlinJdkAndMultiplatformStdlibDescriptor + +abstract class AbstractKotlinFindUsagesWithStdlibFirTest : AbstractKotlinFindUsagesWithStdlibTest() { + override fun isFirPlugin(): Boolean = true + + override fun doTest(path: String) = doTestWithFIRFlagsByPath(path) { + super.doTest(path) + } +} diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/FindUsagesMultiModuleFirTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/FindUsagesMultiModuleFirTest.kt index 470b4351ac3..13dca27b257 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/FindUsagesMultiModuleFirTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/FindUsagesMultiModuleFirTest.kt @@ -5,12 +5,12 @@ package org.jetbrains.kotlin.findUsages -import org.jetbrains.kotlin.doTestWithFIRFlags +import java.nio.file.Paths class FindUsagesMultiModuleFirTest : FindUsagesMultiModuleTest() { override val isFirPlugin: Boolean = true - override fun doFindUsagesTest() = doTestWithFIRFlags(mainFile.text) { + override fun doFindUsagesTest() = doTestWithFIRFlags(Paths.get(mainFile.virtualFilePath)) { super.doFindUsagesTest() } } \ No newline at end of file diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/findUsagesTestUtils.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/findUsagesTestUtils.kt new file mode 100644 index 00000000000..2fec0588665 --- /dev/null +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/findUsages/findUsagesTestUtils.kt @@ -0,0 +1,21 @@ +/* + * 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.findUsages + +import org.jetbrains.kotlin.test.InTextDirectivesUtils +import org.jetbrains.kotlin.test.uitls.IgnoreTests +import java.nio.file.Path +import java.nio.file.Paths + + +fun doTestWithFIRFlagsByPath(path: String, body: () -> Unit) = + doTestWithFIRFlags(Paths.get(path), body) + +fun doTestWithFIRFlags(testFile: Path, body: () -> Unit) { + if (InTextDirectivesUtils.isDirectiveDefined(testFile.toFile().readText(), "FIR_IGNORE")) return + IgnoreTests.runTestIfEnabledByFileDirective(testFile, IgnoreTests.DIRECTIVES.FIR_COMPARISON) { + body() + } +} \ No newline at end of file diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/completion/AbstractHighLevelJvmBasicCompletionTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/completion/AbstractHighLevelJvmBasicCompletionTest.kt index 3e732678647..afe751eaff8 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/completion/AbstractHighLevelJvmBasicCompletionTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/completion/AbstractHighLevelJvmBasicCompletionTest.kt @@ -6,12 +6,14 @@ package org.jetbrains.kotlin.idea.completion import org.jetbrains.kotlin.idea.completion.test.AbstractJvmBasicCompletionTest -import org.jetbrains.kotlin.test.InTextDirectivesUtils +import org.jetbrains.kotlin.test.uitls.IgnoreTests abstract class AbstractHighLevelJvmBasicCompletionTest : AbstractJvmBasicCompletionTest() { override val captureExceptions: Boolean = false override fun executeTest(test: () -> Unit) { - runTestWithCustomEnableDirective(FIR_COMPARISON, testDataFile()) { super.executeTest(test) } + IgnoreTests.runTestIfEnabledByFileDirective(testDataFile().toPath(), IgnoreTests.DIRECTIVES.FIR_COMPARISON, ".after") { + super.executeTest(test) + } } } \ No newline at end of file diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/completion/highLevelCompletionTestUtils.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/completion/highLevelCompletionTestUtils.kt deleted file mode 100644 index 26edc6a77ef..00000000000 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/completion/highLevelCompletionTestUtils.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.completion - -import org.jetbrains.kotlin.test.InTextDirectivesUtils -import java.io.File - -const val FIR_COMPARISON = "// FIR_COMPARISON" - -/** - * Set this flag to `true` to insert directive automatically to all files - * that pass tests but do not already have the directive. - */ -private const val insertDirectiveAutomatically = false - -fun runTestWithCustomEnableDirective(directive: String, testFile: File, test: () -> Unit) { - val testFileAfter = testFile.resolveSibling(testFile.name + ".after").takeIf { it.exists() } - - val testEnabled = InTextDirectivesUtils.isDirectiveDefined(testFile.readText(), directive) - - try { - test() - } catch (e: Throwable) { - if (testEnabled) throw e - return - } - - if (!testEnabled) { - if (insertDirectiveAutomatically) { - testFile.insertDirective(directive) - testFileAfter?.insertDirective(directive) - } - - throw AssertionError("Looks like test is passing, please add ${directive.removePrefix("// ")} at the beginning of the file") - } -} - -private fun File.insertDirective(directive: String) { - val originalText = readText() - writeText("$directive\n$originalText") -} diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractHighLevelBasicCompletionHandlerTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractHighLevelBasicCompletionHandlerTest.kt index f42cf2e47fc..2f952051e3b 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractHighLevelBasicCompletionHandlerTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractHighLevelBasicCompletionHandlerTest.kt @@ -5,13 +5,14 @@ package org.jetbrains.kotlin.idea.completion.test.handlers -import org.jetbrains.kotlin.idea.completion.FIR_COMPARISON -import org.jetbrains.kotlin.idea.completion.runTestWithCustomEnableDirective +import org.jetbrains.kotlin.test.uitls.IgnoreTests abstract class AbstractHighLevelBasicCompletionHandlerTest : AbstractBasicCompletionHandlerTest() { override val captureExceptions: Boolean = false override fun doTest(testPath: String) { - runTestWithCustomEnableDirective(FIR_COMPARISON, testDataFile()) { super.doTest(testPath) } + IgnoreTests.runTestIfEnabledByFileDirective(testDataFilePath(), IgnoreTests.DIRECTIVES.FIR_COMPARISON, ".after") { + super.doTest(testPath) + } } } \ No newline at end of file diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/highlighter/AbstractFirHighlightingTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/highlighter/AbstractFirHighlightingTest.kt index 57918f63403..555cc646ace 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/highlighter/AbstractFirHighlightingTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/highlighter/AbstractFirHighlightingTest.kt @@ -6,10 +6,10 @@ package org.jetbrains.kotlin.idea.highlighter import org.jetbrains.kotlin.idea.addExternalTestFiles -import org.jetbrains.kotlin.idea.shouldBeRethrown import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources import org.jetbrains.kotlin.idea.withPossiblyDisabledDuplicatedFirSourceElementsException import org.jetbrains.kotlin.test.InTextDirectivesUtils +import org.jetbrains.kotlin.test.uitls.IgnoreTests abstract class AbstractFirHighlightingTest : AbstractHighlightingTest() { override val captureExceptions: Boolean = false @@ -24,20 +24,13 @@ abstract class AbstractFirHighlightingTest : AbstractHighlightingTest() { } override fun checkHighlighting(fileText: String) { - val doComparison = !InTextDirectivesUtils.isDirectiveDefined(myFixture.file.text, "IGNORE_FIR") val checkInfos = !InTextDirectivesUtils.isDirectiveDefined(fileText, NO_CHECK_INFOS_PREFIX); - try { + IgnoreTests.runTestIfNotDisabledByFileDirective(testDataFile().toPath(), IgnoreTests.DIRECTIVES.IGNORE_FIR) { // warnings are not supported yet withPossiblyDisabledDuplicatedFirSourceElementsException(fileText) { myFixture.checkHighlighting(/* checkWarnings= */ false, checkInfos, /* checkWeakWarnings= */ false) } - } catch (e: Throwable) { - if (doComparison || e.shouldBeRethrown()) throw e - return - } - if (!doComparison) { - throw AssertionError("Looks like test is passing, please remove IGNORE_FIR") } } } \ No newline at end of file diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/resolve/AbstractFirReferenceResolveTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/resolve/AbstractFirReferenceResolveTest.kt index 9b4644f3e97..ac6db4c5f5f 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/resolve/AbstractFirReferenceResolveTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/resolve/AbstractFirReferenceResolveTest.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.idea.shouldBeRethrown import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor import org.jetbrains.kotlin.test.InTextDirectivesUtils +import org.jetbrains.kotlin.test.uitls.IgnoreTests abstract class AbstractFirReferenceResolveTest : AbstractReferenceResolveTest() { override fun isFirPlugin(): Boolean = true @@ -20,15 +21,9 @@ abstract class AbstractFirReferenceResolveTest : AbstractReferenceResolveTest() override fun doTest(path: String) { assert(path.endsWith(".kt")) { path } myFixture.configureWithExtraFile(path, ".Data") - if (InTextDirectivesUtils.isDirectiveDefined(myFixture.file.text, "IGNORE_FIR")) { - try { - performChecks() - } catch (t: Throwable) { - if (t.shouldBeRethrown()) throw t - return - } - throw AssertionError("Looks like test is passing, please remove IGNORE_FIR") + + IgnoreTests.runTestIfNotDisabledByFileDirective(testDataFile().toPath(), IgnoreTests.DIRECTIVES.IGNORE_FIR) { + performChecks() } - performChecks() } } \ No newline at end of file diff --git a/idea/idea-frontend-independent/build.gradle.kts b/idea/idea-frontend-independent/build.gradle.kts index 4628368ba5b..17ccdde53bf 100644 --- a/idea/idea-frontend-independent/build.gradle.kts +++ b/idea/idea-frontend-independent/build.gradle.kts @@ -20,6 +20,8 @@ dependencies { compileOnly(intellijDep()) compileOnly(project(":compiler:light-classes")) compileOnly(intellijPluginDep("java")) { includeJars("java-api", "java-impl") } + + testCompile(projectTests(":compiler:tests-common")) } sourceSets { diff --git a/idea/idea-frontend-independent/tests/org/jetbrains/kotlin/test/uitls/IgnoreTests.kt b/idea/idea-frontend-independent/tests/org/jetbrains/kotlin/test/uitls/IgnoreTests.kt new file mode 100644 index 00000000000..8e37b2b02a0 --- /dev/null +++ b/idea/idea-frontend-independent/tests/org/jetbrains/kotlin/test/uitls/IgnoreTests.kt @@ -0,0 +1,126 @@ +/* + * 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.test.uitls + +import org.jetbrains.kotlin.test.InTextDirectivesUtils +import java.nio.file.Files +import java.nio.file.Path + +object IgnoreTests { + private const val INSERT_DIRECTIVE_AUTOMATICALLY = false // TODO use environment variable instead + + fun runTestIfEnabledByFileDirective( + testFile: Path, + enableTestDirective: String, + vararg additionalFilesExtensions: String, + test: () -> Unit, + ) { + runTestIfEnabledByDirective( + testFile, + EnableOrDisableTestDirective.Enable(enableTestDirective), + additionalFilesExtensions.toList(), + test + ) + } + + fun runTestIfNotDisabledByFileDirective( + testFile: Path, + disableTestDirective: String, + vararg additionalFilesExtensions: String, + test: () -> Unit + ) { + runTestIfEnabledByDirective( + testFile, + EnableOrDisableTestDirective.Disable(disableTestDirective), + additionalFilesExtensions.toList(), + test + ) + } + + private fun runTestIfEnabledByDirective( + testFile: Path, + directive: EnableOrDisableTestDirective, + additionalFilesExtensions: List, + test: () -> Unit + ) { + val testIsEnabled = directive.isEnabledInFile(testFile) + + try { + test() + } catch (e: Throwable) { + if (testIsEnabled) throw e + return + } + + if (!testIsEnabled) { + handlePassingButNotEnabledTest(testFile, directive, additionalFilesExtensions) + } + } + + private fun handlePassingButNotEnabledTest( + testFile: Path, + directive: EnableOrDisableTestDirective, + additionalFilesExtensions: List, + ) { + if (INSERT_DIRECTIVE_AUTOMATICALLY) { + testFile.insertDirectivesToFileAndAdditionalFile(directive, additionalFilesExtensions) + } + + throw AssertionError( + "Looks like the test passes, please ${directive.fixDirectiveMessage} the beginning of the testdata file" + ) + } + + private fun Path.insertDirectivesToFileAndAdditionalFile( + directive: EnableOrDisableTestDirective, + additionalFilesExtensions: List, + ) { + insertDirective(directive) + additionalFilesExtensions.forEach { extension -> + getSiblingFile(extension)?.insertDirective(directive) + } + } + + private fun Path.getSiblingFile(extension: String): Path? { + val siblingName = fileName.toString() + "." + extension.removePrefix(".") + return resolveSibling(siblingName).takeIf(Files::exists) + } + + private sealed class EnableOrDisableTestDirective { + abstract val directiveText: String + abstract val fixDirectiveMessage: String + + abstract fun isEnabledIfDirectivePresent(isDirectivePresent: Boolean): Boolean + + data class Enable(override val directiveText: String) : EnableOrDisableTestDirective() { + override val fixDirectiveMessage: String get() = "add $directiveText to" + + override fun isEnabledIfDirectivePresent(isDirectivePresent: Boolean): Boolean = isDirectivePresent + } + + data class Disable(override val directiveText: String) : EnableOrDisableTestDirective() { + override val fixDirectiveMessage: String get() = "remove $directiveText from" + override fun isEnabledIfDirectivePresent(isDirectivePresent: Boolean): Boolean = !isDirectivePresent + } + } + + private fun EnableOrDisableTestDirective.isEnabledInFile(file: Path): Boolean { + val isDirectivePresent = InTextDirectivesUtils.isDirectiveDefined(file.toFile().readText(), directiveText) + return isEnabledIfDirectivePresent(isDirectivePresent) + } + + private fun Path.insertDirective(directive: EnableOrDisableTestDirective) { + toFile().apply { + val originalText = readText() + writeText("${directive.directiveText}\n$originalText") + } + } + + object DIRECTIVES { + const val FIR_COMPARISON = "// FIR_COMPARISON" + const val IGNORE_FIR = "// IGNORE_FIR" + } +} \ No newline at end of file diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt index 5a2c759e453..5a4322310cf 100644 --- a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt @@ -57,6 +57,7 @@ import java.io.File import java.io.IOException import java.util.* import kotlin.reflect.full.findAnnotation +import java.nio.file.Path abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFixtureTestCaseBase() { @@ -68,6 +69,8 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix protected fun testDataFile(): File = testDataFile(fileName()) + protected fun testDataFilePath(): Path = testDataFile().toPath() + protected fun testPath(fileName: String = fileName()): String = testDataFile(fileName).toString() protected fun testPath(): String = testPath(fileName()) diff --git a/idea/tests/org/jetbrains/kotlin/FirTestUtils.kt b/idea/tests/org/jetbrains/kotlin/FirTestUtils.kt index be11365a623..b83af9d8114 100644 --- a/idea/tests/org/jetbrains/kotlin/FirTestUtils.kt +++ b/idea/tests/org/jetbrains/kotlin/FirTestUtils.kt @@ -7,9 +7,6 @@ package org.jetbrains.kotlin import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.runReadAction -import com.intellij.openapi.util.io.FileUtil -import org.jetbrains.kotlin.test.InTextDirectivesUtils -import java.io.File fun executeOnPooledThreadInReadAction(action: () -> R): R? { var exception: Exception? = null @@ -26,23 +23,4 @@ fun executeOnPooledThreadInReadAction(action: () -> R): R? { throw this } return result -} - -inline fun doTestWithFIRFlagsByPath(path: String, body: () -> Unit) = - doTestWithFIRFlags(FileUtil.loadFile(File(path)), body) - -inline fun doTestWithFIRFlags(mainFileText: String, body: () -> Unit) { - - if (InTextDirectivesUtils.isDirectiveDefined(mainFileText, "FIR_IGNORE")) return - val isFirComparison = InTextDirectivesUtils.isDirectiveDefined(mainFileText, "FIR_COMPARISON") - - try { - body() - } catch (e: Throwable) { - if (isFirComparison) throw e - return - } - if (!isFirComparison) { - throw AssertionError("Looks like test is passing, please add // FIR_COMPARISON at the beginning of the file") - } } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesTest.kt b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesTest.kt index 24bdaf08624..4aef720429a 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesTest.kt +++ b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesTest.kt @@ -38,7 +38,6 @@ import com.intellij.usages.impl.rules.UsageTypeProvider import com.intellij.usages.rules.UsageFilteringRule import com.intellij.usages.rules.UsageGroupingRule import com.intellij.util.CommonProcessors -import org.jetbrains.kotlin.doTestWithFIRFlagsByPath import org.jetbrains.kotlin.executeOnPooledThreadInReadAction import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager @@ -59,21 +58,6 @@ import java.io.File import java.util.* import kotlin.collections.LinkedHashSet -abstract class AbstractFindUsagesWithDisableComponentSearchFirTest : AbstractFindUsagesWithDisableComponentSearchTest() { - override fun isFirPlugin(): Boolean = true - - override fun doTest(path: String) = doTestWithFIRFlagsByPath(path) { - super.doTest(path) - } -} - -abstract class AbstractFindUsagesFirTest : AbstractFindUsagesTest() { - override fun isFirPlugin(): Boolean = true - - override fun doTest(path: String) = doTestWithFIRFlagsByPath(path) { - super.doTest(path) - } -} abstract class AbstractFindUsagesWithDisableComponentSearchTest : AbstractFindUsagesTest() { diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesWithLibraryTest.kt b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesWithLibraryTest.kt index e6a79323fbb..0268bd69fcc 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesWithLibraryTest.kt +++ b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesWithLibraryTest.kt @@ -1,23 +1,13 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.findUsages -import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.doTestWithFIRFlagsByPath import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.idea.test.SdkAndMockLibraryProjectDescriptor -abstract class AbstractKotlinFindUsagesWithLibraryFirTest : AbstractKotlinFindUsagesWithLibraryTest() { - override fun isFirPlugin(): Boolean = true - - override fun doTest(path: String) = doTestWithFIRFlagsByPath(path) { - super.doTest(path) - } -} - abstract class AbstractKotlinFindUsagesWithLibraryTest : AbstractFindUsagesTest() { override fun getProjectDescriptor() = SdkAndMockLibraryProjectDescriptor( diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesWithStdlibTest.kt b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesWithStdlibTest.kt index d8ce3617fe6..f3e6923e74a 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesWithStdlibTest.kt +++ b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesWithStdlibTest.kt @@ -1,22 +1,12 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.findUsages -import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.doTestWithFIRFlagsByPath import org.jetbrains.kotlin.idea.test.KotlinJdkAndMultiplatformStdlibDescriptor -abstract class AbstractKotlinFindUsagesWithStdlibFirTest : AbstractKotlinFindUsagesWithStdlibTest() { - override fun isFirPlugin(): Boolean = true - - override fun doTest(path: String) = doTestWithFIRFlagsByPath(path) { - super.doTest(path) - } -} - abstract class AbstractKotlinFindUsagesWithStdlibTest : AbstractFindUsagesTest() { override fun getProjectDescriptor() = KotlinJdkAndMultiplatformStdlibDescriptor.JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES