mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
enable write-safe context checks in tests
This commit is contained in:
@@ -51,7 +51,6 @@ public class TransactionGuardImpl extends TransactionGuard {
|
||||
private TransactionIdImpl myCurrentTransaction;
|
||||
private boolean myWritingAllowed;
|
||||
private boolean myErrorReported;
|
||||
private static boolean ourTestingTransactions;
|
||||
|
||||
public TransactionGuardImpl() {
|
||||
myWriteSafeModalities.put(ModalityState.NON_MODAL, true);
|
||||
@@ -255,9 +254,6 @@ public class TransactionGuardImpl extends TransactionGuard {
|
||||
|
||||
private static boolean areAssertionsEnabled() {
|
||||
Application app = ApplicationManager.getApplication();
|
||||
if (app.isUnitTestMode() && !ourTestingTransactions) {
|
||||
return false;
|
||||
}
|
||||
if (app instanceof ApplicationEx && !((ApplicationEx)app).isLoaded()) {
|
||||
return false;
|
||||
}
|
||||
@@ -340,10 +336,6 @@ public class TransactionGuardImpl extends TransactionGuard {
|
||||
.toString();
|
||||
}
|
||||
|
||||
public static void setTestingTransactions(boolean testingTransactions) {
|
||||
ourTestingTransactions = testingTransactions;
|
||||
}
|
||||
|
||||
private static class Transaction {
|
||||
@NotNull final Runnable runnable;
|
||||
@Nullable final TransactionIdImpl expectedContext;
|
||||
|
||||
@@ -59,13 +59,11 @@ class TransactionTest extends LightPlatformTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp()
|
||||
assert LaterInvocator.currentModalityState == ModalityState.NON_MODAL
|
||||
TransactionGuardImpl.testingTransactions = true
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
UIUtil.dispatchAllInvocationEvents()
|
||||
TransactionGuardImpl.testingTransactions = false
|
||||
log.clear()
|
||||
LaterInvocator.leaveAllModals()
|
||||
super.tearDown()
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.openapi.application.TransactionGuard;
|
||||
import com.intellij.openapi.application.impl.ApplicationImpl;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.ShutDownTracker;
|
||||
import com.intellij.testFramework.EdtTestUtil;
|
||||
import com.intellij.testFramework.LeakHunter;
|
||||
import com.intellij.testFramework.LightPlatformTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
@@ -56,7 +57,7 @@ public class _LastInSuiteTest extends TestCase {
|
||||
return buildConf == null ? name : name + "[" + buildConf + "]";
|
||||
}
|
||||
|
||||
public void testProjectLeak() throws Exception {
|
||||
public void testProjectLeak() {
|
||||
if (Boolean.getBoolean("idea.test.guimode")) {
|
||||
Application application = ApplicationManager.getApplication();
|
||||
TransactionGuard.getInstance().submitTransactionAndWait(() -> {
|
||||
@@ -67,7 +68,7 @@ public class _LastInSuiteTest extends TestCase {
|
||||
return;
|
||||
}
|
||||
|
||||
UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
|
||||
EdtTestUtil.runInEdtAndWait(() -> {
|
||||
try {
|
||||
LightPlatformTestCase.initApplication(); // in case nobody cared to init. LightPlatformTestCase.disposeApplication() would not work otherwise.
|
||||
}
|
||||
@@ -109,7 +110,7 @@ public class _LastInSuiteTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testStatistics() throws Exception {
|
||||
public void testStatistics() {
|
||||
long started = _FirstInSuiteTest.getSuiteStartTime();
|
||||
if (started != 0) {
|
||||
long testSuiteDuration = System.nanoTime() - started;
|
||||
|
||||
@@ -615,7 +615,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
EdtTestUtil.runInEdtAndWait(() -> {
|
||||
cleanupApplicationCaches(getProject());
|
||||
resetAllFields();
|
||||
});
|
||||
|
||||
+18
-26
@@ -783,7 +783,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@Override
|
||||
public void type(final char c) {
|
||||
assertInitialized();
|
||||
UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
|
||||
ApplicationManager.getApplication().invokeAndWait((Runnable)() -> {
|
||||
final EditorActionManager actionManager = EditorActionManager.getInstance();
|
||||
if (c == '\b') {
|
||||
performEditorAction(IdeActions.ACTION_EDITOR_BACKSPACE);
|
||||
@@ -1044,29 +1044,21 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
public LookupElement[] complete(@NotNull final CompletionType type, final int invocationCount) {
|
||||
assertInitialized();
|
||||
myEmptyLookup = false;
|
||||
return UIUtil.invokeAndWaitIfNeeded(new Computable<LookupElement[]>() {
|
||||
@Override
|
||||
public LookupElement[] compute() {
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final CodeCompletionHandlerBase handler = new CodeCompletionHandlerBase(type) {
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void completionFinished(CompletionProgressIndicator indicator, boolean hasModifiers) {
|
||||
myEmptyLookup = indicator.getLookup().getItems().isEmpty();
|
||||
super.completionFinished(indicator, hasModifiers);
|
||||
}
|
||||
};
|
||||
Editor editor = getCompletionEditor();
|
||||
assertNotNull(editor);
|
||||
handler.invokeCompletion(getProject(), editor, invocationCount);
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); // to compare with file text
|
||||
}
|
||||
}, null, null, getEditor().getDocument());
|
||||
return getLookupElements();
|
||||
}
|
||||
});
|
||||
ApplicationManager.getApplication().invokeAndWait(() -> CommandProcessor.getInstance().executeCommand(getProject(), () -> {
|
||||
final CodeCompletionHandlerBase handler = new CodeCompletionHandlerBase(type) {
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void completionFinished(CompletionProgressIndicator indicator, boolean hasModifiers) {
|
||||
myEmptyLookup = indicator.getLookup().getItems().isEmpty();
|
||||
super.completionFinished(indicator, hasModifiers);
|
||||
}
|
||||
};
|
||||
Editor editor = getCompletionEditor();
|
||||
assertNotNull(editor);
|
||||
handler.invokeCompletion(getProject(), editor, invocationCount);
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); // to compare with file text
|
||||
}, null, null, getEditor().getDocument()));
|
||||
return getLookupElements();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -1170,13 +1162,13 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@Override
|
||||
public void checkResultByFile(@NotNull String expectedFile, boolean ignoreTrailingWhitespaces) {
|
||||
assertInitialized();
|
||||
UIUtil.invokeAndWaitIfNeeded((Runnable)() -> checkResultByFile(expectedFile, getHostFile(), ignoreTrailingWhitespaces));
|
||||
ApplicationManager.getApplication().invokeAndWait(() -> checkResultByFile(expectedFile, getHostFile(), ignoreTrailingWhitespaces));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkResultByFile(@NotNull String filePath, @NotNull String expectedFile, boolean ignoreTrailingWhitespaces) {
|
||||
assertInitialized();
|
||||
UIUtil.invokeAndWaitIfNeeded((Runnable)() -> checkResultByFile(expectedFile, getFileToCheck(filePath), ignoreTrailingWhitespaces));
|
||||
ApplicationManager.getApplication().invokeAndWait(() -> checkResultByFile(expectedFile, getFileToCheck(filePath), ignoreTrailingWhitespaces));
|
||||
}
|
||||
|
||||
private PsiFile getFileToCheck(String filePath) {
|
||||
|
||||
@@ -17,9 +17,9 @@ package com.intellij.testFramework.vcs;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.testFramework.EdtTestUtil;
|
||||
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
|
||||
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
@@ -40,13 +40,6 @@ public abstract class FileBasedTest {
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
myProject = null;
|
||||
UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
|
||||
try {
|
||||
myProjectFixture.tearDown();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
EdtTestUtil.runInEdtAndWait(() -> myProjectFixture.tearDown());
|
||||
}
|
||||
}
|
||||
|
||||
+26
-36
@@ -24,11 +24,11 @@ import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.EdtTestUtil;
|
||||
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
|
||||
import com.intellij.testFramework.fixtures.TempDirTestFixture;
|
||||
import com.intellij.testFramework.vcs.AbstractJunitVcsTestCase;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
@@ -53,50 +53,40 @@ public class ExternalChangesDetectionVcsTest extends AbstractJunitVcsTestCase {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
|
||||
try {
|
||||
final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory();
|
||||
myTempDirTestFixture = fixtureFactory.createTempDirTestFixture();
|
||||
myTempDirTestFixture.setUp();
|
||||
EdtTestUtil.runInEdtAndWait(() -> {
|
||||
final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory();
|
||||
myTempDirTestFixture = fixtureFactory.createTempDirTestFixture();
|
||||
myTempDirTestFixture.setUp();
|
||||
|
||||
myClientRoot = new File(myTempDirTestFixture.getTempDirPath(), "clientroot");
|
||||
myClientRoot.mkdir();
|
||||
myClientRoot = new File(myTempDirTestFixture.getTempDirPath(), "clientroot");
|
||||
myClientRoot.mkdir();
|
||||
|
||||
initProject(myClientRoot, ExternalChangesDetectionVcsTest.this.getTestName());
|
||||
initProject(myClientRoot, ExternalChangesDetectionVcsTest.this.getTestName());
|
||||
|
||||
myVcs = new MockAbstractVcs(myProject);
|
||||
myVcs.setChangeProvider(new MyMockChangeProvider());
|
||||
myVcsManager = (ProjectLevelVcsManagerImpl)ProjectLevelVcsManager.getInstance(myProject);
|
||||
myVcsManager.registerVcs(myVcs);
|
||||
myVcsManager.setDirectoryMapping("", myVcs.getName());
|
||||
myVcs = new MockAbstractVcs(myProject);
|
||||
myVcs.setChangeProvider(new MyMockChangeProvider());
|
||||
myVcsManager = (ProjectLevelVcsManagerImpl)ProjectLevelVcsManager.getInstance(myProject);
|
||||
myVcsManager.registerVcs(myVcs);
|
||||
myVcsManager.setDirectoryMapping("", myVcs.getName());
|
||||
|
||||
myLFS = LocalFileSystem.getInstance();
|
||||
myChangeListManager = ChangeListManager.getInstance(myProject);
|
||||
myVcsDirtyScopeManager = VcsDirtyScopeManager.getInstance(myProject);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
myLFS = LocalFileSystem.getInstance();
|
||||
myChangeListManager = ChangeListManager.getInstance(myProject);
|
||||
myVcsDirtyScopeManager = VcsDirtyScopeManager.getInstance(myProject);
|
||||
});
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
|
||||
try {
|
||||
myVcsManager.unregisterVcs(myVcs);
|
||||
myVcs = null;
|
||||
myVcsManager = null;
|
||||
myChangeListManager = null;
|
||||
myVcsDirtyScopeManager = null;
|
||||
tearDownProject();
|
||||
myTempDirTestFixture.tearDown();
|
||||
myTempDirTestFixture = null;
|
||||
FileUtil.delete(myClientRoot);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
EdtTestUtil.runInEdtAndWait(() -> {
|
||||
myVcsManager.unregisterVcs(myVcs);
|
||||
myVcs = null;
|
||||
myVcsManager = null;
|
||||
myChangeListManager = null;
|
||||
myVcsDirtyScopeManager = null;
|
||||
tearDownProject();
|
||||
myTempDirTestFixture.tearDown();
|
||||
myTempDirTestFixture = null;
|
||||
FileUtil.delete(myClientRoot);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package hg4idea.test.validator;
|
||||
|
||||
import com.intellij.testFramework.EdtTestUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import hg4idea.test.HgPlatformTest;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.After;
|
||||
@@ -63,14 +63,7 @@ public class HgReferenceValidatorTest extends HgPlatformTest {
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() {
|
||||
UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
|
||||
try {
|
||||
HgReferenceValidatorTest.super.tearDown();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
EdtTestUtil.runInEdtAndWait(() -> super.tearDown());
|
||||
}
|
||||
|
||||
@SuppressWarnings({"JUnitTestCaseWithNonTrivialConstructors", "UnusedParameters"})
|
||||
|
||||
Reference in New Issue
Block a user