diff options
author | Alena Laskavaia | 2014-12-03 03:42:49 +0000 |
---|---|---|
committer | Elena Laskavaia | 2014-12-04 18:57:27 +0000 |
commit | 863def95be233a4f6650874b1c3950cad4aabb8d (patch) | |
tree | 2f768e76d7a1632654811aaca55907946819779d | |
parent | c6865cfb7dfaad4317abc572c3fe73ed5ff8be3a (diff) | |
download | org.eclipse.cdt-863def95be233a4f6650874b1c3950cad4aabb8d.tar.gz org.eclipse.cdt-863def95be233a4f6650874b1c3950cad4aabb8d.tar.xz org.eclipse.cdt-863def95be233a4f6650874b1c3950cad4aabb8d.zip |
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
3 files changed, 23 insertions, 21 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CodanTestCase.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CodanTestCase.java index 41af0bf470d..dceab470a8e 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CodanTestCase.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CodanTestCase.java @@ -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 diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java index 70a583c6c10..968e827a267 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java @@ -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$ } diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanRunner.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanRunner.java index 8b23934fe07..4b41a4d921e 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanRunner.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanRunner.java @@ -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(); |