mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Kotlin property tests for intention actions (including preview); KTIJ-20104
GitOrigin-RevId: 2df895af87021104623bf2f27db179753d06a3de
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ba80e056fa
commit
2bd4aebd1f
@@ -209,6 +209,7 @@ com.intellij.lang.properties.propertyBased.PropertiesCodeInsightSanityTest
|
||||
org.jetbrains.plugins.groovy.GroovySanityTest
|
||||
com.intellij.workspaceModel.storage.propertyBased.*
|
||||
com.intellij.compiler.artifacts.propertybased.*
|
||||
org.jetbrains.kotlin.idea.propertyBased.*
|
||||
|
||||
[GROOVY_TESTS]
|
||||
org.jetbrains.plugins.groovy.*
|
||||
@@ -246,6 +247,7 @@ com.intellij.testDiscovery.*
|
||||
org.jetbrains.kotlin.*
|
||||
org.jetbrains.uast.test.kotlin.*
|
||||
com.intellij.codeInspection.tests.kotlin.*
|
||||
-org.jetbrains.kotlin.idea.propertyBased.*
|
||||
|
||||
[KOTLIN_FIR_TESTS]
|
||||
org.jetbrains.kotlin.idea.fir.*
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.kotlin.idea.propertyBased
|
||||
|
||||
import com.intellij.openapi.application.PathManager
|
||||
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl
|
||||
import com.intellij.openapi.util.RecursionManager
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.SkipSlowTestLocally
|
||||
import com.intellij.testFramework.propertyBased.*
|
||||
import org.jetbrains.jetCheck.Generator
|
||||
import org.jetbrains.jetCheck.PropertyChecker
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources
|
||||
import java.io.File
|
||||
import java.util.function.Function
|
||||
import java.util.function.Supplier
|
||||
|
||||
@SkipSlowTestLocally
|
||||
class KotlinCodeInsightSanityTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
RecursionManager.disableMissedCacheAssertions(testRootDisposable)
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
// remove jdk if it was created during highlighting to avoid leaks
|
||||
try {
|
||||
JavaAwareProjectJdkTableImpl.removeInternalJdkInTests()
|
||||
} catch (e: Throwable) {
|
||||
addSuppressedException(e)
|
||||
} finally {
|
||||
super.tearDown()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor = ProjectDescriptorWithStdlibSources.INSTANCE
|
||||
|
||||
fun testRandomActivity() {
|
||||
enableInspections()
|
||||
val actionSupplier = actionOnKotlinFiles { file: PsiFile ->
|
||||
Generator.sampledFrom(
|
||||
InvokeIntention(file, KotlinIntentionPolicy()),
|
||||
//TODO: support completion mutators
|
||||
//InvokeCompletion(file, KotlinCompletionPolicy()),
|
||||
StripTestDataMarkup(file),
|
||||
DeleteRange(file)
|
||||
)
|
||||
}
|
||||
PropertyChecker
|
||||
.checkScenarios(actionSupplier)
|
||||
}
|
||||
|
||||
private fun enableInspections() {
|
||||
MadTestingUtil.enableAllInspections(project)
|
||||
}
|
||||
|
||||
private fun actionOnKotlinFiles(fileActions: Function<PsiFile, Generator<out MadTestingAction>>): Supplier<MadTestingAction?> {
|
||||
return MadTestingUtil.actionsOnFileContents(myFixture, PathManager.getHomePath(),
|
||||
{ f: File -> f.name.endsWith(".kt") }, fileActions)
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.kotlin.idea.propertyBased
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import com.intellij.codeInsight.intention.IntentionActionDelegate
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.testFramework.propertyBased.IntentionPolicy
|
||||
import org.jetbrains.kotlin.idea.intentions.ConvertToScopeIntention
|
||||
|
||||
internal class KotlinIntentionPolicy : IntentionPolicy() {
|
||||
override fun shouldSkipIntention(actionText: String): Boolean =
|
||||
// These intentions don't modify code (probably should not start in write-action?)
|
||||
actionText == "Enable a trailing comma by default in the formatter" ||
|
||||
actionText == "Disable a trailing comma by default in the formatter"
|
||||
|
||||
override fun mayBreakCode(action: IntentionAction, editor: Editor, file: PsiFile): Boolean = false
|
||||
|
||||
override fun shouldTolerateIntroducedError(info: HighlightInfo): Boolean = false
|
||||
|
||||
override fun shouldCheckPreview(action: IntentionAction): Boolean {
|
||||
val unwrapped = IntentionActionDelegate.unwrap(action)
|
||||
val skipPreview =
|
||||
action.familyName == "Create from usage" || // Starts template but may also perform modifications before that; thus not so easy to support
|
||||
unwrapped is ConvertToScopeIntention // Performs reference search which must be run under progress. Probably we can generate diff excluding references?..
|
||||
return !skipPreview
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user