Tests: Disable inspections after test as Platform test framework requires

This commit is contained in:
Yan Zhulanow
2018-03-23 23:11:26 +03:00
parent 8f02d338a6
commit 5d9bdbec10
@@ -26,10 +26,7 @@ import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.CharsetToolkit import com.intellij.openapi.vfs.CharsetToolkit
import com.intellij.rt.execution.junit.FileComparisonFailure import com.intellij.rt.execution.junit.FileComparisonFailure
import com.intellij.testFramework.InspectionTestUtil import com.intellij.testFramework.*
import com.intellij.testFramework.LightPlatformTestCase
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.UsefulTestCase
import com.intellij.util.ui.UIUtil import com.intellij.util.ui.UIUtil
import junit.framework.TestCase import junit.framework.TestCase
import org.jetbrains.kotlin.idea.quickfix.utils.findInspectionFile import org.jetbrains.kotlin.idea.quickfix.utils.findInspectionFile
@@ -46,10 +43,16 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase() {
val beforeFileText = FileUtil.loadFile(File(beforeFileName)) val beforeFileText = FileUtil.loadFile(File(beforeFileName))
configureLanguageVersion(beforeFileText, project, module) configureLanguageVersion(beforeFileText, project, module)
enableInspections(beforeFileName, beforeFileText) val inspections = parceInspectionsToEnable(beforeFileName, beforeFileText).toTypedArray()
doKotlinQuickFixTest(beforeFileName) try {
checkForUnexpectedErrors() myFixture.enableInspections(*inspections)
doKotlinQuickFixTest(beforeFileName)
checkForUnexpectedErrors()
} finally {
myFixture.disableInspections(*inspections)
}
} }
override fun getProjectDescriptor(): LightProjectDescriptor { override fun getProjectDescriptor(): LightProjectDescriptor {
@@ -160,7 +163,7 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase() {
} }
} }
private fun enableInspections(beforeFileName: String, beforeFileText: String) { private fun parceInspectionsToEnable(beforeFileName: String, beforeFileText: String): List<InspectionProfileEntry> {
val toolsStrings = InTextDirectivesUtils.findListWithPrefixes(beforeFileText, "TOOL:") val toolsStrings = InTextDirectivesUtils.findListWithPrefixes(beforeFileText, "TOOL:")
if (toolsStrings.isNotEmpty()) { if (toolsStrings.isNotEmpty()) {
val inspections = toolsStrings.map { toolFqName -> val inspections = toolsStrings.map { toolFqName ->
@@ -172,18 +175,17 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase() {
throw IllegalArgumentException("Failed to create inspection for key '$toolFqName'", e) throw IllegalArgumentException("Failed to create inspection for key '$toolFqName'", e)
} }
} }
myFixture.enableInspections(*inspections.toTypedArray()) return inspections
return
} }
val inspectionFile = findInspectionFile(File(beforeFileName).parentFile) val inspectionFile = findInspectionFile(File(beforeFileName).parentFile)
if (inspectionFile != null) { if (inspectionFile != null) {
val className = FileUtil.loadFile(inspectionFile).trim { it <= ' ' } val className = FileUtil.loadFile(inspectionFile).trim { it <= ' ' }
val inspectionClass = Class.forName(className) as Class<InspectionProfileEntry> val inspectionClass = Class.forName(className) as Class<InspectionProfileEntry>
val tools = InspectionTestUtil.instantiateTools( return InspectionTestUtil.instantiateTools(listOf<Class<out InspectionProfileEntry>>(inspectionClass))
listOf<Class<out InspectionProfileEntry>>(inspectionClass))
myFixture.enableInspections(*tools.toTypedArray())
} }
return emptyList()
} }
@Throws(ClassNotFoundException::class) @Throws(ClassNotFoundException::class)