Fixing non-running tests, that used MockApplication environment
This commit is contained in:
committed by
Nikolay Krasko
parent
c1cf03d89c
commit
a278e4ccef
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.test.testFramework
|
||||
|
||||
import com.intellij.mock.MockApplication
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
@@ -41,6 +42,7 @@ fun runInEdtAndWait(runnable: () -> Unit) {
|
||||
else {
|
||||
try {
|
||||
val application = ApplicationManager.getApplication()
|
||||
.takeIf { it !is MockApplication } // because MockApplication do nothing instead of `invokeAndWait`
|
||||
if (application != null)
|
||||
application.invokeAndWait(runnable)
|
||||
else
|
||||
|
||||
+6
@@ -52,6 +52,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||
public abstract class KtUsefulTestCase extends TestCase {
|
||||
@@ -217,9 +218,11 @@ public abstract class KtUsefulTestCase extends TestCase {
|
||||
protected void runTest() throws Throwable {
|
||||
Throwable[] throwables = new Throwable[1];
|
||||
|
||||
AtomicBoolean completed = new AtomicBoolean(false);
|
||||
Runnable runnable = () -> {
|
||||
try {
|
||||
super.runTest();
|
||||
completed.set(true);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.fillInStackTrace();
|
||||
@@ -239,6 +242,9 @@ public abstract class KtUsefulTestCase extends TestCase {
|
||||
if (throwables[0] != null) {
|
||||
throw throwables[0];
|
||||
}
|
||||
if (!completed.get()) {
|
||||
throw new IllegalStateException("test didn't start");
|
||||
}
|
||||
}
|
||||
|
||||
private static void invokeTestRunnable(@NotNull Runnable runnable) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user