From bc95c5fc7e788ba8e35fb9ee4c4770ffa0922379 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Tue, 25 Mar 2014 10:52:49 +0400 Subject: [PATCH] checkForSettingsDamage(): throw after tearDown() --- .../com/intellij/testFramework/CompositeException.java | 4 ++++ .../intellij/testFramework/LightPlatformTestCase.java | 4 +++- .../com/intellij/testFramework/PlatformTestCase.java | 3 ++- .../src/com/intellij/testFramework/UsefulTestCase.java | 10 +++++----- .../fixtures/impl/LightIdeaTestFixtureImpl.java | 9 ++++----- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/CompositeException.java b/platform/testFramework/src/com/intellij/testFramework/CompositeException.java index b7af563fce27..59e73bf718d4 100644 --- a/platform/testFramework/src/com/intellij/testFramework/CompositeException.java +++ b/platform/testFramework/src/com/intellij/testFramework/CompositeException.java @@ -141,4 +141,8 @@ public class CompositeException extends Exception { return sb.toString(); } + + public void throwIfNotEmpty() throws CompositeException { + if (!isEmpty()) throw this; + } } diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 4eb294025dd7..163e5e8fea04 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -505,7 +505,8 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da protected void tearDown() throws Exception { Project project = getProject(); CodeStyleSettingsManager.getInstance(project).dropTemporarySettings(); - checkForSettingsDamage(); + @SuppressWarnings("ThrowableResultOfMethodCallIgnored") + CompositeException damage = checkForSettingsDamage(); VirtualFilePointerManagerImpl filePointerManager = (VirtualFilePointerManagerImpl)VirtualFilePointerManager.getInstance(); doTearDown(project, ourApplication, true); @@ -517,6 +518,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da InjectedLanguageManagerImpl.checkInjectorsAreDisposed(project); filePointerManager.assertPointersAreDisposed(); } + damage.throwIfNotEmpty(); } public static void doTearDown(@NotNull final Project project, IdeaTestApplication application, boolean checkForEditors) throws Exception { diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index 59b8d4b95056..6e4ec4928a89 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java @@ -402,7 +402,8 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro } try { - checkForSettingsDamage(); + CompositeException damage = checkForSettingsDamage(); + result.add(damage); } catch (Throwable e) { result.add(e); diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java index 104c55e0c77b..960964fac7af 100644 --- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java @@ -213,19 +213,19 @@ public abstract class UsefulTestCase extends TestCase { } } - protected void checkForSettingsDamage() throws Exception { + protected CompositeException checkForSettingsDamage() throws Exception { Application app = ApplicationManager.getApplication(); if (isPerformanceTest() || app == null || app instanceof MockApplication) { - return; + return new CompositeException(); } CodeStyleSettings oldCodeStyleSettings = myOldCodeStyleSettings; myOldCodeStyleSettings = null; - doCheckForSettingsDamage(oldCodeStyleSettings, getCurrentCodeStyleSettings()); + return doCheckForSettingsDamage(oldCodeStyleSettings, getCurrentCodeStyleSettings()); } - public static void doCheckForSettingsDamage(@NotNull CodeStyleSettings oldCodeStyleSettings, + public static CompositeException doCheckForSettingsDamage(@NotNull CodeStyleSettings oldCodeStyleSettings, @NotNull CodeStyleSettings currentCodeStyleSettings) throws Exception { CompositeException result = new CompositeException(); final CodeInsightSettings settings = CodeInsightSettings.getInstance(); @@ -266,7 +266,7 @@ public abstract class UsefulTestCase extends TestCase { result.add(e); } - if (!result.isEmpty()) throw result; + return result; } protected void storeSettings() { diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java index 5259fa0680fd..97bd36698640 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java @@ -29,10 +29,7 @@ import com.intellij.psi.codeStyle.CodeStyleSchemes; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl; -import com.intellij.testFramework.LightPlatformTestCase; -import com.intellij.testFramework.LightProjectDescriptor; -import com.intellij.testFramework.TestDataProvider; -import com.intellij.testFramework.UsefulTestCase; +import com.intellij.testFramework.*; import com.intellij.testFramework.fixtures.LightIdeaTestFixture; import gnu.trove.THashMap; @@ -68,13 +65,15 @@ public class LightIdeaTestFixtureImpl extends BaseFixture implements LightIdeaTe CodeStyleSettingsManager.getInstance(project).dropTemporarySettings(); CodeStyleSettings oldCodeStyleSettings = myOldCodeStyleSettings; myOldCodeStyleSettings = null; - UsefulTestCase.doCheckForSettingsDamage(oldCodeStyleSettings, getCurrentCodeStyleSettings()); + @SuppressWarnings("ThrowableResultOfMethodCallIgnored") + CompositeException damage = UsefulTestCase.doCheckForSettingsDamage(oldCodeStyleSettings, getCurrentCodeStyleSettings()); LightPlatformTestCase.doTearDown(project, LightPlatformTestCase.getApplication(), true); super.tearDown(); InjectedLanguageManagerImpl.checkInjectorsAreDisposed(project); PersistentFS.getInstance().clearIdCache(); ((DirectoryIndexImpl)DirectoryIndex.getInstance(project)).assertAncestorConsistent(); + damage.throwIfNotEmpty(); } @Override