Skip to content

Commit

Permalink
Added test with reporting psi element invalidation
Browse files Browse the repository at this point in the history
(cherry picked from commit 0feaf71)
  • Loading branch information
hurricup committed Sep 5, 2019
1 parent 22e387c commit 23cdc9b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions plugin/test/unit/perl/PerlExceptionReporterTest.java
Expand Up @@ -17,12 +17,20 @@
package unit.perl;

import base.PerlLightTestCase;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.diagnostic.Attachment;
import com.intellij.openapi.diagnostic.IdeaLoggingEvent;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiInvalidElementAccessException;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.concurrency.Semaphore;
import com.perl5.errorHandler.YoutrackErrorHandler;
import org.junit.Ignore;
import org.junit.Test;

import javax.swing.*;
import java.util.Arrays;

public class PerlExceptionReporterTest extends PerlLightTestCase {
Expand All @@ -41,4 +49,29 @@ public void testReporting() {
));
assertTrue(StringUtil.isNotEmpty(result));
}

@Ignore
@Test
public void testReportingInvalidPsiElement() {
initWithTextSmart("say 'hi'");
PsiFile file = getFile();
assertTrue(file.isValid());
PsiElement statement = file.getFirstChild();
WriteCommandAction.runWriteCommandAction(getProject(), statement::delete);
assertFalse(statement.isValid());
try {
PsiUtilCore.ensureValid(statement);
}
catch (PsiInvalidElementAccessException e) {
Semaphore semaphore = new Semaphore();
semaphore.down();
new YoutrackErrorHandler().submit(
new IdeaLoggingEvent[]{new IdeaLoggingEvent("Test message", e)},
"No info",
new JPanel(),
info -> semaphore.up()
);
semaphore.waitFor();
}
}
}

0 comments on commit 23cdc9b

Please sign in to comment.