FIR IDE: introduce common function to mute tests
This commit is contained in:
+2
-2
@@ -6,7 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.idea.perf
|
package org.jetbrains.kotlin.idea.perf
|
||||||
|
|
||||||
import com.intellij.codeInsight.completion.CompletionType
|
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
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
|
|
||||||
abstract class AbstractHighLevelPerformanceCompletionHandlerTests(
|
abstract class AbstractHighLevelPerformanceCompletionHandlerTests(
|
||||||
@@ -17,7 +17,7 @@ abstract class AbstractHighLevelPerformanceCompletionHandlerTests(
|
|||||||
override val statsPrefix: String = "fir-completion"
|
override val statsPrefix: String = "fir-completion"
|
||||||
|
|
||||||
override fun doPerfTest(unused: String) {
|
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)
|
super.doPerfTest(unused)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ dependencies {
|
|||||||
testCompile(projectTests(":idea:idea-frontend-fir"))
|
testCompile(projectTests(":idea:idea-frontend-fir"))
|
||||||
testCompile(project(":kotlin-test:kotlin-test-junit"))
|
testCompile(project(":kotlin-test:kotlin-test-junit"))
|
||||||
testCompile(commonDep("junit:junit"))
|
testCompile(commonDep("junit:junit"))
|
||||||
|
testCompile(projectTests(":idea:idea-frontend-independent"))
|
||||||
|
|
||||||
testCompileOnly(intellijDep())
|
testCompileOnly(intellijDep())
|
||||||
testRuntime(intellijDep())
|
testRuntime(intellijDep())
|
||||||
|
|||||||
+1
-4
@@ -5,13 +5,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.asJava.classes
|
package org.jetbrains.kotlin.asJava.classes
|
||||||
|
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
|
||||||
import org.jetbrains.kotlin.asJava.KotlinAsJavaSupport
|
import org.jetbrains.kotlin.asJava.KotlinAsJavaSupport
|
||||||
import org.jetbrains.kotlin.doTestWithFIRFlagsByPath
|
|
||||||
import org.jetbrains.kotlin.executeOnPooledThreadInReadAction
|
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
|
||||||
import org.jetbrains.kotlin.idea.perf.UltraLightChecker.checkByJavaFile
|
|
||||||
import org.jetbrains.kotlin.idea.perf.UltraLightChecker.getJavaFileForTest
|
import org.jetbrains.kotlin.idea.perf.UltraLightChecker.getJavaFileForTest
|
||||||
import org.jetbrains.kotlin.idea.perf.UltraLightChecker.renderLightClasses
|
import org.jetbrains.kotlin.idea.perf.UltraLightChecker.renderLightClasses
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
|||||||
+1
-1
@@ -6,8 +6,8 @@
|
|||||||
package org.jetbrains.kotlin.asJava.classes
|
package org.jetbrains.kotlin.asJava.classes
|
||||||
|
|
||||||
import org.jetbrains.kotlin.asJava.LightClassTestCommon
|
import org.jetbrains.kotlin.asJava.LightClassTestCommon
|
||||||
import org.jetbrains.kotlin.doTestWithFIRFlagsByPath
|
|
||||||
import org.jetbrains.kotlin.executeOnPooledThreadInReadAction
|
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.PsiElementChecker
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.findClass
|
import org.jetbrains.kotlin.idea.caches.resolve.findClass
|
||||||
import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager
|
import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager
|
||||||
|
|||||||
+1
-1
@@ -7,8 +7,8 @@ package org.jetbrains.kotlin.asJava.classes
|
|||||||
|
|
||||||
import com.intellij.psi.search.GlobalSearchScope
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
import org.jetbrains.kotlin.asJava.KotlinAsJavaSupport
|
import org.jetbrains.kotlin.asJava.KotlinAsJavaSupport
|
||||||
import org.jetbrains.kotlin.doTestWithFIRFlagsByPath
|
|
||||||
import org.jetbrains.kotlin.executeOnPooledThreadInReadAction
|
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
|
||||||
import org.jetbrains.kotlin.idea.perf.UltraLightChecker.checkByJavaFile
|
import org.jetbrains.kotlin.idea.perf.UltraLightChecker.checkByJavaFile
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
|||||||
@@ -6,11 +6,9 @@
|
|||||||
package org.jetbrains.kotlin.checkers
|
package org.jetbrains.kotlin.checkers
|
||||||
|
|
||||||
import com.intellij.rt.execution.junit.FileComparisonFailure
|
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.test.withCustomCompilerOptions
|
||||||
import org.jetbrains.kotlin.idea.withPossiblyDisabledDuplicatedFirSourceElementsException
|
import org.jetbrains.kotlin.idea.withPossiblyDisabledDuplicatedFirSourceElementsException
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.uitls.IgnoreTests
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
abstract class AbstractFirPsiCheckerTest : AbstractPsiCheckerTest() {
|
abstract class AbstractFirPsiCheckerTest : AbstractPsiCheckerTest() {
|
||||||
@@ -19,7 +17,7 @@ abstract class AbstractFirPsiCheckerTest : AbstractPsiCheckerTest() {
|
|||||||
override fun isFirPlugin(): Boolean = true
|
override fun isFirPlugin(): Boolean = true
|
||||||
|
|
||||||
override fun doTest(filePath: String) {
|
override fun doTest(filePath: String) {
|
||||||
runTestWithCustomEnableDirective(FIR_COMPARISON, testDataFile()) {
|
IgnoreTests.runTestIfEnabledByFileDirective(testDataFilePath(), IgnoreTests.DIRECTIVES.FIR_COMPARISON) {
|
||||||
myFixture.configureByFile(fileName())
|
myFixture.configureByFile(fileName())
|
||||||
checkHighlighting(checkWarnings = false, checkInfos = false, checkWeakWarnings = false)
|
checkHighlighting(checkWarnings = false, checkInfos = false, checkWeakWarnings = false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 <T : PsiElement> doTest(path: String) = doTestWithFIRFlagsByPath(path) {
|
||||||
|
super.doTest<T>(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
@@ -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 <T : PsiElement> doTest(path: String) = doTestWithFIRFlagsByPath(path) {
|
||||||
|
super.doTest<T>(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+18
@@ -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 <T : PsiElement> doTest(path: String) = doTestWithFIRFlagsByPath(path) {
|
||||||
|
super.doTest<T>(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
@@ -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 <T : PsiElement> doTest(path: String) = doTestWithFIRFlagsByPath(path) {
|
||||||
|
super.doTest<T>(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,12 +5,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.findUsages
|
package org.jetbrains.kotlin.findUsages
|
||||||
|
|
||||||
import org.jetbrains.kotlin.doTestWithFIRFlags
|
import java.nio.file.Paths
|
||||||
|
|
||||||
class FindUsagesMultiModuleFirTest : FindUsagesMultiModuleTest() {
|
class FindUsagesMultiModuleFirTest : FindUsagesMultiModuleTest() {
|
||||||
override val isFirPlugin: Boolean = true
|
override val isFirPlugin: Boolean = true
|
||||||
|
|
||||||
override fun doFindUsagesTest() = doTestWithFIRFlags(mainFile.text) {
|
override fun doFindUsagesTest() = doTestWithFIRFlags(Paths.get(mainFile.virtualFilePath)) {
|
||||||
super.doFindUsagesTest()
|
super.doFindUsagesTest()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-2
@@ -6,12 +6,14 @@
|
|||||||
package org.jetbrains.kotlin.idea.completion
|
package org.jetbrains.kotlin.idea.completion
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.completion.test.AbstractJvmBasicCompletionTest
|
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() {
|
abstract class AbstractHighLevelJvmBasicCompletionTest : AbstractJvmBasicCompletionTest() {
|
||||||
override val captureExceptions: Boolean = false
|
override val captureExceptions: Boolean = false
|
||||||
|
|
||||||
override fun executeTest(test: () -> Unit) {
|
override fun executeTest(test: () -> Unit) {
|
||||||
runTestWithCustomEnableDirective(FIR_COMPARISON, testDataFile()) { super.executeTest(test) }
|
IgnoreTests.runTestIfEnabledByFileDirective(testDataFile().toPath(), IgnoreTests.DIRECTIVES.FIR_COMPARISON, ".after") {
|
||||||
|
super.executeTest(test)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-44
@@ -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")
|
|
||||||
}
|
|
||||||
+4
-3
@@ -5,13 +5,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.completion.test.handlers
|
package org.jetbrains.kotlin.idea.completion.test.handlers
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.completion.FIR_COMPARISON
|
import org.jetbrains.kotlin.test.uitls.IgnoreTests
|
||||||
import org.jetbrains.kotlin.idea.completion.runTestWithCustomEnableDirective
|
|
||||||
|
|
||||||
abstract class AbstractHighLevelBasicCompletionHandlerTest : AbstractBasicCompletionHandlerTest() {
|
abstract class AbstractHighLevelBasicCompletionHandlerTest : AbstractBasicCompletionHandlerTest() {
|
||||||
override val captureExceptions: Boolean = false
|
override val captureExceptions: Boolean = false
|
||||||
|
|
||||||
override fun doTest(testPath: String) {
|
override fun doTest(testPath: String) {
|
||||||
runTestWithCustomEnableDirective(FIR_COMPARISON, testDataFile()) { super.doTest(testPath) }
|
IgnoreTests.runTestIfEnabledByFileDirective(testDataFilePath(), IgnoreTests.DIRECTIVES.FIR_COMPARISON, ".after") {
|
||||||
|
super.doTest(testPath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-9
@@ -6,10 +6,10 @@
|
|||||||
package org.jetbrains.kotlin.idea.highlighter
|
package org.jetbrains.kotlin.idea.highlighter
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.addExternalTestFiles
|
import org.jetbrains.kotlin.idea.addExternalTestFiles
|
||||||
import org.jetbrains.kotlin.idea.shouldBeRethrown
|
|
||||||
import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources
|
import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources
|
||||||
import org.jetbrains.kotlin.idea.withPossiblyDisabledDuplicatedFirSourceElementsException
|
import org.jetbrains.kotlin.idea.withPossiblyDisabledDuplicatedFirSourceElementsException
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
|
import org.jetbrains.kotlin.test.uitls.IgnoreTests
|
||||||
|
|
||||||
abstract class AbstractFirHighlightingTest : AbstractHighlightingTest() {
|
abstract class AbstractFirHighlightingTest : AbstractHighlightingTest() {
|
||||||
override val captureExceptions: Boolean = false
|
override val captureExceptions: Boolean = false
|
||||||
@@ -24,20 +24,13 @@ abstract class AbstractFirHighlightingTest : AbstractHighlightingTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun checkHighlighting(fileText: String) {
|
override fun checkHighlighting(fileText: String) {
|
||||||
val doComparison = !InTextDirectivesUtils.isDirectiveDefined(myFixture.file.text, "IGNORE_FIR")
|
|
||||||
val checkInfos = !InTextDirectivesUtils.isDirectiveDefined(fileText, NO_CHECK_INFOS_PREFIX);
|
val checkInfos = !InTextDirectivesUtils.isDirectiveDefined(fileText, NO_CHECK_INFOS_PREFIX);
|
||||||
|
|
||||||
try {
|
IgnoreTests.runTestIfNotDisabledByFileDirective(testDataFile().toPath(), IgnoreTests.DIRECTIVES.IGNORE_FIR) {
|
||||||
// warnings are not supported yet
|
// warnings are not supported yet
|
||||||
withPossiblyDisabledDuplicatedFirSourceElementsException(fileText) {
|
withPossiblyDisabledDuplicatedFirSourceElementsException(fileText) {
|
||||||
myFixture.checkHighlighting(/* checkWarnings= */ false, checkInfos, /* checkWeakWarnings= */ false)
|
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")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
-9
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.idea.shouldBeRethrown
|
|||||||
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
|
import org.jetbrains.kotlin.test.uitls.IgnoreTests
|
||||||
|
|
||||||
abstract class AbstractFirReferenceResolveTest : AbstractReferenceResolveTest() {
|
abstract class AbstractFirReferenceResolveTest : AbstractReferenceResolveTest() {
|
||||||
override fun isFirPlugin(): Boolean = true
|
override fun isFirPlugin(): Boolean = true
|
||||||
@@ -20,15 +21,9 @@ abstract class AbstractFirReferenceResolveTest : AbstractReferenceResolveTest()
|
|||||||
override fun doTest(path: String) {
|
override fun doTest(path: String) {
|
||||||
assert(path.endsWith(".kt")) { path }
|
assert(path.endsWith(".kt")) { path }
|
||||||
myFixture.configureWithExtraFile(path, ".Data")
|
myFixture.configureWithExtraFile(path, ".Data")
|
||||||
if (InTextDirectivesUtils.isDirectiveDefined(myFixture.file.text, "IGNORE_FIR")) {
|
|
||||||
try {
|
IgnoreTests.runTestIfNotDisabledByFileDirective(testDataFile().toPath(), IgnoreTests.DIRECTIVES.IGNORE_FIR) {
|
||||||
performChecks()
|
performChecks()
|
||||||
} catch (t: Throwable) {
|
|
||||||
if (t.shouldBeRethrown()) throw t
|
|
||||||
return
|
|
||||||
}
|
|
||||||
throw AssertionError("Looks like test is passing, please remove IGNORE_FIR")
|
|
||||||
}
|
}
|
||||||
performChecks()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,8 @@ dependencies {
|
|||||||
compileOnly(intellijDep())
|
compileOnly(intellijDep())
|
||||||
compileOnly(project(":compiler:light-classes"))
|
compileOnly(project(":compiler:light-classes"))
|
||||||
compileOnly(intellijPluginDep("java")) { includeJars("java-api", "java-impl") }
|
compileOnly(intellijPluginDep("java")) { includeJars("java-api", "java-impl") }
|
||||||
|
|
||||||
|
testCompile(projectTests(":compiler:tests-common"))
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
@@ -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<String>,
|
||||||
|
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<String>,
|
||||||
|
) {
|
||||||
|
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<String>,
|
||||||
|
) {
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -57,6 +57,7 @@ import java.io.File
|
|||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.reflect.full.findAnnotation
|
import kotlin.reflect.full.findAnnotation
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFixtureTestCaseBase() {
|
abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFixtureTestCaseBase() {
|
||||||
|
|
||||||
@@ -68,6 +69,8 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix
|
|||||||
|
|
||||||
protected fun testDataFile(): File = testDataFile(fileName())
|
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(fileName: String = fileName()): String = testDataFile(fileName).toString()
|
||||||
|
|
||||||
protected fun testPath(): String = testPath(fileName())
|
protected fun testPath(): String = testPath(fileName())
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ package org.jetbrains.kotlin
|
|||||||
|
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.application.runReadAction
|
import com.intellij.openapi.application.runReadAction
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
fun <R> executeOnPooledThreadInReadAction(action: () -> R): R? {
|
fun <R> executeOnPooledThreadInReadAction(action: () -> R): R? {
|
||||||
var exception: Exception? = null
|
var exception: Exception? = null
|
||||||
@@ -26,23 +23,4 @@ fun <R> executeOnPooledThreadInReadAction(action: () -> R): R? {
|
|||||||
throw this
|
throw this
|
||||||
}
|
}
|
||||||
return result
|
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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,6 @@ import com.intellij.usages.impl.rules.UsageTypeProvider
|
|||||||
import com.intellij.usages.rules.UsageFilteringRule
|
import com.intellij.usages.rules.UsageFilteringRule
|
||||||
import com.intellij.usages.rules.UsageGroupingRule
|
import com.intellij.usages.rules.UsageGroupingRule
|
||||||
import com.intellij.util.CommonProcessors
|
import com.intellij.util.CommonProcessors
|
||||||
import org.jetbrains.kotlin.doTestWithFIRFlagsByPath
|
|
||||||
import org.jetbrains.kotlin.executeOnPooledThreadInReadAction
|
import org.jetbrains.kotlin.executeOnPooledThreadInReadAction
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
|
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
|
||||||
import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager
|
import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager
|
||||||
@@ -59,21 +58,6 @@ import java.io.File
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.LinkedHashSet
|
import kotlin.collections.LinkedHashSet
|
||||||
|
|
||||||
abstract class AbstractFindUsagesWithDisableComponentSearchFirTest : AbstractFindUsagesWithDisableComponentSearchTest() {
|
|
||||||
override fun isFirPlugin(): Boolean = true
|
|
||||||
|
|
||||||
override fun <T : PsiElement> doTest(path: String) = doTestWithFIRFlagsByPath(path) {
|
|
||||||
super.doTest<T>(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class AbstractFindUsagesFirTest : AbstractFindUsagesTest() {
|
|
||||||
override fun isFirPlugin(): Boolean = true
|
|
||||||
|
|
||||||
override fun <T : PsiElement> doTest(path: String) = doTestWithFIRFlagsByPath(path) {
|
|
||||||
super.doTest<T>(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class AbstractFindUsagesWithDisableComponentSearchTest : AbstractFindUsagesTest() {
|
abstract class AbstractFindUsagesWithDisableComponentSearchTest : AbstractFindUsagesTest() {
|
||||||
|
|
||||||
|
|||||||
+1
-11
@@ -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.
|
* 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
|
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.PluginTestCaseBase
|
||||||
import org.jetbrains.kotlin.idea.test.SdkAndMockLibraryProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.SdkAndMockLibraryProjectDescriptor
|
||||||
|
|
||||||
abstract class AbstractKotlinFindUsagesWithLibraryFirTest : AbstractKotlinFindUsagesWithLibraryTest() {
|
|
||||||
override fun isFirPlugin(): Boolean = true
|
|
||||||
|
|
||||||
override fun <T : PsiElement> doTest(path: String) = doTestWithFIRFlagsByPath(path) {
|
|
||||||
super.doTest<T>(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class AbstractKotlinFindUsagesWithLibraryTest : AbstractFindUsagesTest() {
|
abstract class AbstractKotlinFindUsagesWithLibraryTest : AbstractFindUsagesTest() {
|
||||||
override fun getProjectDescriptor() =
|
override fun getProjectDescriptor() =
|
||||||
SdkAndMockLibraryProjectDescriptor(
|
SdkAndMockLibraryProjectDescriptor(
|
||||||
|
|||||||
+1
-11
@@ -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.
|
* 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
|
package org.jetbrains.kotlin.findUsages
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import org.jetbrains.kotlin.doTestWithFIRFlagsByPath
|
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinJdkAndMultiplatformStdlibDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinJdkAndMultiplatformStdlibDescriptor
|
||||||
|
|
||||||
abstract class AbstractKotlinFindUsagesWithStdlibFirTest : AbstractKotlinFindUsagesWithStdlibTest() {
|
|
||||||
override fun isFirPlugin(): Boolean = true
|
|
||||||
|
|
||||||
override fun <T : PsiElement> doTest(path: String) = doTestWithFIRFlagsByPath(path) {
|
|
||||||
super.doTest<T>(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class AbstractKotlinFindUsagesWithStdlibTest : AbstractFindUsagesTest() {
|
abstract class AbstractKotlinFindUsagesWithStdlibTest : AbstractFindUsagesTest() {
|
||||||
override fun getProjectDescriptor() =
|
override fun getProjectDescriptor() =
|
||||||
KotlinJdkAndMultiplatformStdlibDescriptor.JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES
|
KotlinJdkAndMultiplatformStdlibDescriptor.JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES
|
||||||
|
|||||||
Reference in New Issue
Block a user