Fix project leak through child test case disposable

This commit is contained in:
Mikhail Bogdanov
2020-03-24 17:28:18 +01:00
parent cdf5a2a5a1
commit e975eedbfb
3 changed files with 29 additions and 8 deletions
@@ -11,6 +11,7 @@ import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl
import com.intellij.codeInsight.daemon.impl.HighlightInfo import com.intellij.codeInsight.daemon.impl.HighlightInfo
import com.intellij.lang.annotation.HighlightSeverity import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.impl.EditorImpl import com.intellij.openapi.editor.impl.EditorImpl
@@ -55,7 +56,12 @@ class GradleMultiplatformHighlightingTest : GradleImportingTestCase() {
checkFiles( checkFiles(
files.filter { it.extension == "kt" }, files.filter { it.extension == "kt" },
project, project,
object : GradleDaemonAnalyzerTestCase(testLineMarkers = true, checkWarnings = true, checkInfos = false) {} object : GradleDaemonAnalyzerTestCase(
testLineMarkers = true,
checkWarnings = true,
checkInfos = false,
rootDisposable = testRootDisposable
) {}
) )
} }
@@ -67,16 +73,21 @@ class GradleMultiplatformHighlightingTest : GradleImportingTestCase() {
abstract class GradleDaemonAnalyzerTestCase( abstract class GradleDaemonAnalyzerTestCase(
val testLineMarkers: Boolean, val testLineMarkers: Boolean,
val checkWarnings: Boolean, val checkWarnings: Boolean,
val checkInfos: Boolean val checkInfos: Boolean,
private val rootDisposable: Disposable
) : DaemonAnalyzerTestCase() { ) : DaemonAnalyzerTestCase() {
override fun doTestLineMarkers() = testLineMarkers override fun doTestLineMarkers() = testLineMarkers
fun checkHighlighting(project: Project, editor: Editor) { fun checkHighlighting(project: Project, editor: Editor) {
myProject = project myProject = project
runInEdtAndWait { try {
// This will prepare ExpectedHighlightingData, clear current editor from testing tags, and then runInEdtAndWait {
// call doCheckResult, which we override // This will prepare ExpectedHighlightingData, clear current editor from testing tags, and then
checkHighlighting(editor, checkWarnings, checkInfos) // call doCheckResult, which we override
checkHighlighting(editor, checkWarnings, checkInfos)
}
} finally {
myProject = null
} }
} }
@@ -117,6 +128,10 @@ abstract class GradleDaemonAnalyzerTestCase(
protected open fun performAdditionalChecksAfterHighlighting(editor: Editor) { } protected open fun performAdditionalChecksAfterHighlighting(editor: Editor) { }
protected open fun renderAdditionalAttributeForTag(tag: TagInfo<*>): String? = null protected open fun renderAdditionalAttributeForTag(tag: TagInfo<*>): String? = null
override fun getTestRootDisposable(): Disposable {
return rootDisposable;
}
} }
internal fun checkFiles( internal fun checkFiles(
@@ -34,7 +34,8 @@ class ImportAndCheckHighlighting : MultiplePluginVersionGradleImportingTestCase(
object : GradleDaemonAnalyzerTestCase( object : GradleDaemonAnalyzerTestCase(
testLineMarkers = testLineMarkers, testLineMarkers = testLineMarkers,
checkWarnings = checkWarnings, checkWarnings = checkWarnings,
checkInfos = false checkInfos = false,
rootDisposable = testRootDisposable
) {} ) {}
) )
} }
@@ -49,7 +49,12 @@ class GradleTestRunConfigurationAndHighlightingTest : GradleImportingTestCase()
checkFiles( checkFiles(
files.filter { it.extension == "kt" }, files.filter { it.extension == "kt" },
project, project,
object : GradleDaemonAnalyzerTestCase(testLineMarkers = true, checkWarnings = true, checkInfos = false) { object : GradleDaemonAnalyzerTestCase(
testLineMarkers = true,
checkWarnings = true,
checkInfos = false,
rootDisposable = testRootDisposable
) {
override fun renderAdditionalAttributeForTag(tag: TagsTestDataUtil.TagInfo<*>): String? { override fun renderAdditionalAttributeForTag(tag: TagsTestDataUtil.TagInfo<*>): String? {
val lineMarkerInfo = tag.data as? LineMarkerInfo<*> ?: return null val lineMarkerInfo = tag.data as? LineMarkerInfo<*> ?: return null