less "caused by" in test exceptions by default (IDEA-CR-16699)

This commit is contained in:
peter
2016-12-09 11:53:35 +01:00
parent 8e128b7f32
commit acc1a1d987
3 changed files with 11 additions and 19 deletions
@@ -28,22 +28,6 @@ class EdtTestUtil {
@TestOnly @JvmStatic fun runInEdtAndWait(runnable: ThrowableRunnable<Throwable>) {
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<Throwable>) {
var exception: Throwable? = null
runInEdtAndWait {
try {
runnable.run()
} catch (e: Throwable) {
exception = e
}
}
ExceptionUtil.rethrowAllAsUnchecked(exception)
}
}
}
@@ -51,7 +35,15 @@ class EdtTestUtil {
fun runInEdtAndWait(runnable: () -> Unit) {
val application = ApplicationManager.getApplication()
if (application is ApplicationImpl) {
application.invokeAndWait(runnable)
var exception: Throwable? = null
application.invokeAndWait {
try {
runnable()
} catch (e: Throwable) {
exception = e
}
}
ExceptionUtil.rethrowAllAsUnchecked(exception)
return
}
@@ -496,7 +496,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
}
TestRunnerUtil.replaceIdeEventQueueSafely();
EdtTestUtil.runInEdtAndWaitRethrowing(() -> {
EdtTestUtil.runInEdtAndWait(() -> {
try {
ourTestThread = Thread.currentThread();
startRunAndTear();
@@ -414,7 +414,7 @@ public abstract class UsefulTestCase extends TestCase {
if (runInDispatchThread()) {
TestRunnerUtil.replaceIdeEventQueueSafely();
EdtTestUtil.runInEdtAndWaitRethrowing(this::defaultRunBare);
EdtTestUtil.runInEdtAndWait(this::defaultRunBare);
}
else {
defaultRunBare();