diff --git a/platform/testFramework/src/com/intellij/testFramework/EdtTestUtil.kt b/platform/testFramework/src/com/intellij/testFramework/EdtTestUtil.kt index 2b07c7536631..fb6643dcd844 100644 --- a/platform/testFramework/src/com/intellij/testFramework/EdtTestUtil.kt +++ b/platform/testFramework/src/com/intellij/testFramework/EdtTestUtil.kt @@ -17,6 +17,7 @@ package com.intellij.testFramework import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.impl.ApplicationImpl +import com.intellij.util.ExceptionUtil import com.intellij.util.ThrowableRunnable import org.jetbrains.annotations.TestOnly import java.lang.reflect.InvocationTargetException @@ -24,9 +25,25 @@ import javax.swing.SwingUtilities class EdtTestUtil { companion object { - @JvmStatic fun runInEdtAndWait(runnable: ThrowableRunnable) { + @TestOnly @JvmStatic fun runInEdtAndWait(runnable: ThrowableRunnable) { runInEdtAndWait { runnable.run() } } + + /** + * Same as {@link #runInEdtAndWait}, but when an unchecked exception happens inside runnable, its just rethrown without being wrapped. + * Can be useful to decrease "Caused by" chain for cases when the stack trace of the calling thread is not important or obvious. + */ + @TestOnly @JvmStatic fun runInEdtAndWaitRethrowing(runnable: ThrowableRunnable) { + var exception: Throwable? = null + runInEdtAndWait { + try { + runnable.run() + } catch (e: Throwable) { + exception = e + } + } + ExceptionUtil.rethrowAllAsUnchecked(exception) + } } } diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 302b06286973..e523fd64e0c3 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -496,7 +496,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da } TestRunnerUtil.replaceIdeEventQueueSafely(); - EdtTestUtil.runInEdtAndWait(() -> { + EdtTestUtil.runInEdtAndWaitRethrowing(() -> { try { ourTestThread = Thread.currentThread(); startRunAndTear(); diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java index a83b4a56d885..d58ca60e2c8a 100644 --- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java @@ -414,7 +414,7 @@ public abstract class UsefulTestCase extends TestCase { if (runInDispatchThread()) { TestRunnerUtil.replaceIdeEventQueueSafely(); - EdtTestUtil.runInEdtAndWait(this::defaultRunBare); + EdtTestUtil.runInEdtAndWaitRethrowing(this::defaultRunBare); } else { defaultRunBare();