1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 453275 - Codan tests cannot test for checkers throwing an exception

Added system flag that is used to propagate exception
instead of swallowing. Set by default in codan junit tests.

Change-Id: Iccda9a7b2e419192bb9f4eec4b89d525e152fc81
Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com>
Reviewed-on: https://git.eclipse.org/r/37482
This commit is contained in:
Alena Laskavaia 2014-12-02 22:42:49 -05:00 committed by Elena Laskavaia
parent c6865cfb7d
commit 863def95be
3 changed files with 23 additions and 21 deletions

View file

@ -78,6 +78,8 @@ public class CodanTestCase extends BaseTestCase {
removeLeftOverProjects();
cproject = createProject(isCpp());
tmpDir = cproject.getProject().getLocation().makeAbsolute().toFile();
// this make CodanRunner to propagate all exceptions it normally just logs
System.setProperty("codan.rethrow", "true"); // test can override setUp and unset this
}
@Override

View file

@ -95,6 +95,8 @@ public class CodanCorePlugin extends Plugin {
* @noreference This method is not intended to be referenced by clients.
*/
public static void log(Throwable e) {
if (Boolean.valueOf(System.getProperty("codan.rethrow"))) //$NON-NLS-1$
throw new RuntimeException(e);
log("Internal Error", e); //$NON-NLS-1$
}

View file

@ -76,31 +76,29 @@ public class CodanRunner {
ICheckerInvocationContext context = new CheckerInvocationContext(resource);
try {
for (IChecker checker : chegistry) {
try {
if (monitor.isCanceled())
return;
if (chegistry.isCheckerEnabled(checker, resource, checkerLaunchMode)) {
synchronized (checker) {
try {
checker.before(resource);
CheckersTimeStats.getInstance().checkerStart(checker.getClass().getName());
if (checkerLaunchMode == CheckerLaunchMode.RUN_AS_YOU_TYPE) {
((IRunnableInEditorChecker) checker).processModel(model, context);
} else {
checker.processResource(resource, context);
}
} finally {
CheckersTimeStats.getInstance().checkerStop(checker.getClass().getName());
checker.after(resource);
if (monitor.isCanceled())
return;
if (chegistry.isCheckerEnabled(checker, resource, checkerLaunchMode)) {
synchronized (checker) {
try {
checker.before(resource);
CheckersTimeStats.getInstance().checkerStart(checker.getClass().getName());
if (checkerLaunchMode == CheckerLaunchMode.RUN_AS_YOU_TYPE) {
((IRunnableInEditorChecker) checker).processModel(model, context);
} else {
checker.processResource(resource, context);
}
} catch (OperationCanceledException e) {
return;
} catch (Throwable e) {
CodanCorePlugin.log(e);
} finally {
CheckersTimeStats.getInstance().checkerStop(checker.getClass().getName());
checker.after(resource);
}
}
monitor.worked(1);
} catch (OperationCanceledException e) {
return;
} catch (Throwable e) {
CodanCorePlugin.log(e);
}
monitor.worked(1);
}
} finally {
context.dispose();