test for the exception inside stub index

This commit is contained in:
Alexey Kudravtsev
2011-11-29 18:10:16 +04:00
parent cd2858071f
commit 625ae37de7
2 changed files with 27 additions and 6 deletions
@@ -244,4 +244,20 @@ public abstract class PsiTestCase extends ModuleTestCase {
PsiDocumentManager.getInstance(getProject()).commitDocument(document);
}
protected static VirtualFile createChildData(final VirtualFile dir, @NonNls final String name) {
return new WriteAction<VirtualFile>() {
@Override
protected void run(Result<VirtualFile> result) throws Throwable {
result.setResult(dir.createChildData(null, name));
}
}.execute().throwException().getResultObject();
}
protected static VirtualFile createChildDirectory(final VirtualFile dir, @NonNls final String name) {
return new WriteAction<VirtualFile>() {
@Override
protected void run(Result<VirtualFile> result) throws Throwable {
result.setResult(dir.createChildDirectory(null, name));
}
}.execute().throwException().getResultObject();
}
}
@@ -35,14 +35,20 @@ public class RunResult<T> extends Result<T> {
public RunResult<T> run() {
try {
myActionRunnable.run(this);
} catch (ProcessCanceledException e) {
}
catch (ProcessCanceledException e) {
throw e; // this exception may occur from time to time and it shouldn't be catched
} catch (Throwable throwable) {
}
catch (Throwable throwable) {
myThrowable = throwable;
if (!myActionRunnable.isSilentExecution()) {
if (throwable instanceof RuntimeException) throw (RuntimeException)throwable;
if (throwable instanceof Error) throw (Error)throwable;
else throw new RuntimeException(myThrowable);
if (throwable instanceof Error) {
throw (Error)throwable;
}
else {
throw new RuntimeException(myThrowable);
}
}
}
finally {
@@ -64,7 +70,7 @@ public class RunResult<T> extends Result<T> {
return this;
}
public RunResult<T> throwException() {
public RunResult<T> throwException() throws RuntimeException, Error {
if (hasException()) {
if (myThrowable instanceof RuntimeException) {
throw (RuntimeException)myThrowable;
@@ -89,5 +95,4 @@ public class RunResult<T> extends Result<T> {
public void setThrowable(Exception throwable) {
myThrowable = throwable;
}
}