From 988c89602d18769168b1f034e60a2e2d65e1082d Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Thu, 7 May 2020 17:00:28 +0700 Subject: [PATCH] tests: wrap `tearDown` with `RunAll` --- .../test/KotlinLightCodeInsightFixtureTestCase.kt | 15 ++++++++++++--- ...tlinLightPlatformCodeInsightFixtureTestCase.kt | 11 +++++------ .../KotlinLightPlatformCodeInsightTestCase.kt | 8 ++++---- .../KotlinLightPlatformCodeInsightTestCase.kt.191 | 8 ++++---- .../kotlin/idea/stubs/AbstractMultiModuleTest.kt | 10 +++++----- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt index e1e68214440..4e1176f29c1 100644 --- a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt @@ -32,6 +32,8 @@ import com.intellij.psi.search.FileTypeIndex import com.intellij.psi.search.ProjectScope import com.intellij.testFramework.LightProjectDescriptor import com.intellij.testFramework.LoggedErrorProcessor +import com.intellij.testFramework.RunAll +import com.intellij.util.ThrowableRunnable import org.apache.log4j.Logger import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.config.* @@ -103,9 +105,11 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix } override fun tearDown() { - LoggedErrorProcessor.restoreDefaultProcessor() - disableKotlinOfficialCodeStyle(project) - super.tearDown() + runAll( + { LoggedErrorProcessor.restoreDefaultProcessor() }, + { disableKotlinOfficialCodeStyle(project) }, + { super.tearDown() }, + ) if (exceptions.isNotEmpty()) { exceptions.forEach { it.printStackTrace() } @@ -323,6 +327,11 @@ fun disableKotlinOfficialCodeStyle(project: Project) { CodeStyle.getSettings(project) } +fun runAll( + vararg actions: ThrowableRunnable, + suppressedExceptions: List = emptyList() +) = RunAll(*actions).run(suppressedExceptions) + private fun rollbackCompilerOptions(project: Project, module: Module, removeFacet: Boolean) { KotlinCompilerSettings.getInstance(project).update { this.additionalArguments = DEFAULT_ADDITIONAL_ARGUMENTS } KotlinCommonCompilerArgumentsHolder.getInstance(project).update { this.languageVersion = LanguageVersion.LATEST_STABLE.versionString } diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightFixtureTestCase.kt b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightFixtureTestCase.kt index d6ec63e14ed..6fa57d006f1 100644 --- a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightFixtureTestCase.kt +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightFixtureTestCase.kt @@ -23,12 +23,11 @@ abstract class KotlinLightPlatformCodeInsightFixtureTestCase : LightPlatformCode invalidateLibraryCache(project) } - override fun tearDown() { - disableKotlinOfficialCodeStyle(project) - VfsRootAccess.disallowRootAccess(KotlinTestUtils.getHomeDirectory()) - - super.tearDown() - } + override fun tearDown() = runAll( + { disableKotlinOfficialCodeStyle(project) }, + { VfsRootAccess.disallowRootAccess(KotlinTestUtils.getHomeDirectory()) }, + { super.tearDown() }, + ) protected fun testDataFile(fileName: String): File = File(testDataPath, fileName) diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightTestCase.kt b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightTestCase.kt index e547ff54d2a..2c8acc78d38 100644 --- a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightTestCase.kt +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightTestCase.kt @@ -19,8 +19,8 @@ abstract class KotlinLightPlatformCodeInsightTestCase : LightPlatformCodeInsight enableKotlinOfficialCodeStyle(project_) } - override fun tearDown() { - disableKotlinOfficialCodeStyle(project_) - super.tearDown() - } + override fun tearDown() = runAll( + { disableKotlinOfficialCodeStyle(project_) }, + { super.tearDown() }, + ) } \ No newline at end of file diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightTestCase.kt.191 b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightTestCase.kt.191 index 1afa16c10dd..d8cdad46776 100644 --- a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightTestCase.kt.191 +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightTestCase.kt.191 @@ -20,8 +20,8 @@ abstract class KotlinLightPlatformCodeInsightTestCase : LightPlatformCodeInsight enableKotlinOfficialCodeStyle(project_) } - override fun tearDown() { - disableKotlinOfficialCodeStyle(project_) - super.tearDown() - } + override fun tearDown() = runAll( + { disableKotlinOfficialCodeStyle(project_) }, + { super.tearDown() }, + ) } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractMultiModuleTest.kt b/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractMultiModuleTest.kt index 8559870464d..25c531f042e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractMultiModuleTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractMultiModuleTest.kt @@ -62,11 +62,11 @@ abstract class AbstractMultiModuleTest : DaemonAnalyzerTestCase() { return moduleWithSrcRootSet } - override fun tearDown() { - VfsRootAccess.disallowRootAccess(KotlinTestUtils.getHomeDirectory()) - disableKotlinOfficialCodeStyle(project) - super.tearDown() - } + override fun tearDown() = runAll( + { VfsRootAccess.disallowRootAccess(KotlinTestUtils.getHomeDirectory()) }, + { disableKotlinOfficialCodeStyle(project) }, + { super.tearDown() }, + ) public override fun createModule(path: String, moduleType: ModuleType<*>): Module { return super.createModule(path, moduleType)