From 03e140a2da00a83362f6740a153d7204e708ccd5 Mon Sep 17 00:00:00 2001 From: Sergei Vorobyov Date: Fri, 29 Mar 2024 13:14:39 +0100 Subject: [PATCH] IJ-CR-129986 [Gradle|TestFramework] fix: restore application and project initial state after each Gradle project test GitOrigin-RevId: d47227bdc999f0c0c74b684ebaecb35b1e3f9bfd --- .../junit5/src/impl/TestApplicationExtension.kt | 2 +- .../testFramework/GradleExecutionBaseTestCase.kt | 10 ++++++++++ .../testFramework/GradleProjectBaseTestCase.kt | 2 +- .../application/GradleProjectTestApplication.kt | 16 ++-------------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/platform/testFramework/junit5/src/impl/TestApplicationExtension.kt b/platform/testFramework/junit5/src/impl/TestApplicationExtension.kt index dff9aa057f52..332c5df09515 100644 --- a/platform/testFramework/junit5/src/impl/TestApplicationExtension.kt +++ b/platform/testFramework/junit5/src/impl/TestApplicationExtension.kt @@ -17,7 +17,7 @@ import java.time.Duration import java.util.concurrent.TimeUnit @TestOnly -internal class TestApplicationExtension : BeforeAllCallback, AfterEachCallback { +class TestApplicationExtension : BeforeAllCallback, AfterEachCallback { override fun beforeAll(context: ExtensionContext) { context.testApplication().getOrThrow() } diff --git a/plugins/gradle/java/testSources/testFramework/GradleExecutionBaseTestCase.kt b/plugins/gradle/java/testSources/testFramework/GradleExecutionBaseTestCase.kt index 57cfa40fcb83..e367bfa17812 100644 --- a/plugins/gradle/java/testSources/testFramework/GradleExecutionBaseTestCase.kt +++ b/plugins/gradle/java/testSources/testFramework/GradleExecutionBaseTestCase.kt @@ -11,6 +11,7 @@ import org.gradle.util.GradleVersion import org.jetbrains.plugins.gradle.execution.test.runner.GradleTestsExecutionConsole import org.jetbrains.plugins.gradle.testFramework.fixture.* import org.jetbrains.plugins.gradle.testFramework.util.ExternalSystemExecutionTracer +import org.junit.jupiter.api.AfterEach abstract class GradleExecutionBaseTestCase : GradleProjectTestCase() { @@ -41,6 +42,15 @@ abstract class GradleExecutionBaseTestCase : GradleProjectTestCase() { ) } + /** + * Forces a project closing after each Gradle execution test. + * The BuildViewTestFixture cannot release all editors in console view after the test. + */ + @AfterEach + fun destroyAllGradleFixturesAfterEachTest() { + destroyAllGradleFixtures() + } + // '--rerun-tasks' corrupts gradle build caches fo gradle versions before 4.0 (included) private fun cleanupProjectBuildDirectory() { runWriteActionAndWait { diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleProjectBaseTestCase.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleProjectBaseTestCase.kt index 93b9eb930033..0a2caa500f1d 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleProjectBaseTestCase.kt +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleProjectBaseTestCase.kt @@ -63,7 +63,7 @@ abstract class GradleProjectBaseTestCase { return fixtures[fixtureId]!! } - private fun destroyAllGradleFixtures() { + fun destroyAllGradleFixtures() { runAll(fixtures.values.reversed(), ::destroyGradleFixture) } diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleProjectTestApplication.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleProjectTestApplication.kt index 7b42eae34fea..e100d6d857d7 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleProjectTestApplication.kt +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/application/GradleProjectTestApplication.kt @@ -1,14 +1,12 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.plugins.gradle.testFramework.fixtures.application -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.invokeAndWaitIfNeeded import com.intellij.openapi.roots.impl.libraries.LibraryTableTracker import com.intellij.openapi.vfs.impl.VirtualFilePointerTracker import com.intellij.testFramework.SdkLeakTracker -import com.intellij.testFramework.common.cleanApplicationState import com.intellij.testFramework.common.runAll -import com.intellij.testFramework.junit5.impl.testApplication +import com.intellij.testFramework.junit5.impl.TestApplicationExtension import org.jetbrains.plugins.gradle.testFramework.fixtures.tracker.ExternalSystemListenerLeakTracker import org.junit.jupiter.api.extension.AfterAllCallback import org.junit.jupiter.api.extension.BeforeAllCallback @@ -27,21 +25,11 @@ import org.junit.jupiter.api.extension.ExtensionContext */ @Target(AnnotationTarget.CLASS) @ExtendWith( - GradleProjectTestApplicationExtension::class, + TestApplicationExtension::class, GradleProjectTestApplicationLeakTrackerExtension::class, ) annotation class GradleProjectTestApplication -private class GradleProjectTestApplicationExtension : BeforeAllCallback, AfterAllCallback { - override fun beforeAll(context: ExtensionContext) { - context.testApplication().getOrThrow() - } - - override fun afterAll(context: ExtensionContext) { - ApplicationManager.getApplication().cleanApplicationState() - } -} - /** * @see com.intellij.testFramework.junit5.impl.TestApplicationLeakTrackerExtension */