FIR IDE: Assert that the action to invoke in

AbstractHighLevelQuickFixTest is of type QuickFixActionBase.
This commit is contained in:
Mark Punzalan
2021-06-10 07:11:46 +00:00
committed by TeamCityServer
parent 783e5972d0
commit cd6dbd2515
6 changed files with 25 additions and 7 deletions
@@ -45,6 +45,10 @@ abstract class AbstractHighLevelQuickFixTest : AbstractQuickFixTest() {
}
}
override val shouldCheckIntentionActionType: Boolean
// All quickfixes from the FIR plugin are guaranteed to be of type QuickFixActionBase (see HLDiagnosticFixFactory)
get() = true
// TODO: Enable these as more actions/inspections are enabled, and/or add more FIR-specific directives
override fun checkForUnexpectedErrors() {}
override fun checkAvailableActionsAreExpected(actions: List<IntentionAction>) {}
@@ -4,4 +4,5 @@ class Test {
get() {
return 1
}
}
}
/* IGNORE_FIR */
@@ -5,4 +5,5 @@ class Test {
return 1
}
set(value) {<caret>}
}
}
/* IGNORE_FIR */
@@ -3,4 +3,5 @@
class Test {
var x: Int<caret>
set(value) {}
}
}
/* IGNORE_FIR */
@@ -6,4 +6,5 @@ class Test {
<caret>TODO()
}
set(value) {}
}
}
/* IGNORE_FIR */
@@ -20,7 +20,6 @@ import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.UsefulTestCase
import com.intellij.util.ui.UIUtil
import junit.framework.TestCase
import org.jetbrains.annotations.NotNull
import org.jetbrains.kotlin.idea.caches.resolve.ResolveInDispatchThreadException
import org.jetbrains.kotlin.idea.caches.resolve.forceCheckForResolveInDispatchThreadInTests
import org.jetbrains.kotlin.idea.facet.KotlinFacet
@@ -163,9 +162,12 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase(), Q
return
}
val writeActionResolveHandler: () -> Unit = {
val unwrappedIntention = unwrapIntention(intention)
val unwrappedIntention = unwrapIntention(intention)
if (shouldCheckIntentionActionType) {
assertInstanceOf(unwrappedIntention, QuickFixActionBase::class.java)
}
val writeActionResolveHandler: () -> Unit = {
val intentionClassName = unwrappedIntention.javaClass.name
if (!quickFixesAllowedToResolveInWriteAction.isWriteActionAllowed(intentionClassName)) {
throw ResolveInDispatchThreadException("Resolve is not allowed under the write action for `$intentionClassName`!")
@@ -205,6 +207,14 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase(), Q
return File(beforeFileName).name + ".after"
}
/**
* If true, the type of the [IntentionAction] to invoke is [QuickFixActionBase]. This ensures that the action is coming from a
* quickfix (i.e., diagnostic-based), and not a regular IDE intention.
*/
protected open val shouldCheckIntentionActionType: Boolean
// For FE 1.0, many quickfixes are implemented as IntentionActions, which may or may not be used as regular IDE intentions as well
get() = false
@Throws(ClassNotFoundException::class)
private fun checkForUnexpectedActions() {
val text = myFixture.editor.document.text