diff options
author | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2015-02-24 22:21:23 +0100 |
---|---|---|
committer | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2015-02-24 22:21:23 +0100 |
commit | be29a42498f4ef1b50bc49d4e453ca543bc91489 (patch) | |
tree | dc5704ecf73816bf6aa9dd0c73721f98312a88d0 /org.jacoco.core.test/src/org | |
parent | f686e5e9b3cae1221b61aefd80ae605b39e4d764 (diff) | |
download | jacoco-be29a42498f4ef1b50bc49d4e453ca543bc91489.tar.gz |
GitHub #286: Fix missing probes
Fix missing probes at the beginning of try/catch blocks when the block
starts as a jump target. This should restore exec file compatibility
with 0.7.2. Basically a revert of commit e4a474c
Diffstat (limited to 'org.jacoco.core.test/src/org')
4 files changed, 39 insertions, 5 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/flow/LabelFlowAnalyzerTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/flow/LabelFlowAnalyzerTest.java index 6d278743..440b4f38 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/flow/LabelFlowAnalyzerTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/flow/LabelFlowAnalyzerTest.java @@ -107,6 +107,15 @@ public class LabelFlowAnalyzerTest { @Test public void testFlowScenario10() { + analyzer.visitTryCatchBlock(new Label(), new Label(), label, + "java/lang/Exception"); + analyzer.visitJumpInsn(GOTO, label); + assertTrue(LabelInfo.isMultiTarget(label)); + assertFalse(LabelInfo.isSuccessor(label)); + } + + @Test + public void testFlowScenario11() { // Even if the same label is referenced multiple times but from the same // source instruction this is only counted as one target. analyzer.visitLookupSwitchInsn(label, new int[] { 0, 1 }, new Label[] { @@ -116,7 +125,7 @@ public class LabelFlowAnalyzerTest { } @Test - public void testFlowScenario11() { + public void testFlowScenario12() { // Even if the same label is referenced multiple times but from the same // source instruction this is only counted as one target. analyzer.visitTableSwitchInsn(0, 1, label, new Label[] { label, label }); diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/flow/MethodProbesAdapterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/flow/MethodProbesAdapterTest.java index af5e98bd..25da70cd 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/flow/MethodProbesAdapterTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/flow/MethodProbesAdapterTest.java @@ -330,6 +330,7 @@ public class MethodProbesAdapterTest implements IProbeIdGenerator { public void testVisitTryCatchBlockWithProbe() { Label target = new Label(); LabelInfo.setSuccessor(target); + LabelInfo.setTarget(target); Label end = new Label(); Label handler = new Label(); Label start = new Label(); @@ -348,6 +349,7 @@ public class MethodProbesAdapterTest implements IProbeIdGenerator { public void testVisitMultipleTryCatchBlocksWithProbe() { Label target = new Label(); LabelInfo.setSuccessor(target); + LabelInfo.setTarget(target); Label end = new Label(); Label handler1 = new Label(); Label handler2 = new Label(); diff --git a/org.jacoco.core.test/src/org/jacoco/core/test/validation/ExceptionsTest.java b/org.jacoco.core.test/src/org/jacoco/core/test/validation/ExceptionsTest.java index a3bfa81d..03517826 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/test/validation/ExceptionsTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/test/validation/ExceptionsTest.java @@ -61,7 +61,17 @@ public class ExceptionsTest extends ValidationTestBase { assertLine("implicitExceptionTryCatch.catchBlock", ICounter.FULLY_COVERED); - // 5. Try/Catch Block With Exception Thrown Explicitly + // 5. Try/Catch Block With Exception Thrown Implicitly After Condition + // As the try/catch block is entered at one branch of the condition + // should be marked as executed + assertLine("implicitExceptionTryCatchAfterCondition.condition", + ICounter.FULLY_COVERED, 1, 1); + assertLine("implicitExceptionTryCatchAfterCondition.exception", + ICounter.NOT_COVERED); + assertLine("implicitExceptionTryCatchAfterCondition.catchBlock", + ICounter.FULLY_COVERED); + + // 6. Try/Catch Block With Exception Thrown Explicitly assertLine("explicitExceptionTryCatch.beforeBlock", ICounter.FULLY_COVERED); assertLine("explicitExceptionTryCatch.before", ICounter.FULLY_COVERED); @@ -69,13 +79,13 @@ public class ExceptionsTest extends ValidationTestBase { assertLine("explicitExceptionTryCatch.catchBlock", ICounter.FULLY_COVERED); - // 6. Finally Block Without Exception Thrown + // 7. Finally Block Without Exception Thrown // Finally block is yellow as the exception path is missing. assertLine("noExceptionFinally.beforeBlock", ICounter.FULLY_COVERED); assertLine("noExceptionFinally.tryBlock", ICounter.FULLY_COVERED); assertLine("noExceptionFinally.finallyBlock", ICounter.PARTLY_COVERED); - // 7. Finally Block With Implicit Exception + // 8. Finally Block With Implicit Exception // Finally block is yellow as the non-exception path is missing. assertLine("implicitExceptionFinally.beforeBlock", ICounter.FULLY_COVERED); @@ -85,7 +95,7 @@ public class ExceptionsTest extends ValidationTestBase { assertLine("implicitExceptionFinally.finallyBlock", ICounter.PARTLY_COVERED); - // 8. Finally Block With Exception Thrown Explicitly + // 9. Finally Block With Exception Thrown Explicitly assertLine("explicitExceptionFinally.beforeBlock", ICounter.FULLY_COVERED); assertLine("explicitExceptionFinally.before", ICounter.FULLY_COVERED); diff --git a/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/Target03.java b/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/Target03.java index 0ea2d69e..41dfbe0b 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/Target03.java +++ b/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/Target03.java @@ -12,6 +12,7 @@ package org.jacoco.core.test.validation.targets; import static org.jacoco.core.test.validation.targets.Stubs.ex; +import static org.jacoco.core.test.validation.targets.Stubs.f; import static org.jacoco.core.test.validation.targets.Stubs.nop; import org.jacoco.core.test.validation.targets.Stubs.StubException; @@ -32,6 +33,7 @@ public class Target03 implements Runnable { } noExceptionTryCatch(); implicitExceptionTryCatch(); + implicitExceptionTryCatchAfterCondition(); explicitExceptionTryCatch(); noExceptionFinally(); try { @@ -75,6 +77,17 @@ public class Target03 implements Runnable { } } + private void implicitExceptionTryCatchAfterCondition() { + if (f()) { // $line-implicitExceptionTryCatchAfterCondition.condition$ + return; + } + try { + ex(); // $line-implicitExceptionTryCatchAfterCondition.exception$ + } catch (StubException e) { + nop(); // $line-implicitExceptionTryCatchAfterCondition.catchBlock$ + } + } + private void explicitExceptionTryCatch() { nop(); // $line-explicitExceptionTryCatch.beforeBlock$ try { |