From a278e4ccef964b4156c8f1fc642d718bbb11a18c Mon Sep 17 00:00:00 2001 From: Nicolay Mitropolsky Date: Tue, 12 Dec 2017 18:57:06 +0300 Subject: [PATCH] Fixing non-running tests, that used `MockApplication` environment --- .../org/jetbrains/kotlin/test/testFramework/EdtTestUtil.kt | 2 ++ .../kotlin/test/testFramework/KtUsefulTestCase.java | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/EdtTestUtil.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/EdtTestUtil.kt index e42071d1ed6..945e443afa2 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/EdtTestUtil.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/EdtTestUtil.kt @@ -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 diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java index e46292cc55f..67fff80e75e 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java @@ -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 {