diff options
author | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2015-02-16 09:09:25 +0100 |
---|---|---|
committer | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2015-05-22 11:16:59 +0200 |
commit | 873114568ee148ea2e15cd036d57bf7b43ba154d (patch) | |
tree | 96244e1b3a49b2458ea4bb03194d8441b71b09e2 /org.jacoco.core.test | |
parent | 93c1f077e9856dae19c0a7b9bce963181bfd3fc3 (diff) | |
download | jacoco-873114568ee148ea2e15cd036d57bf7b43ba154d.tar.gz |
Improve coverage data for code with implicit exception.
Add additional probe before every line with at least one method
invocation.
Diffstat (limited to 'org.jacoco.core.test')
4 files changed, 61 insertions, 11 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java b/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java index f63762e9..6a9275e8 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java @@ -93,7 +93,7 @@ public class AnalyzerTest { final byte[] bytes = TargetLoader .getClassDataAsBytes(AnalyzerTest.class); executionData.get(Long.valueOf(CRC64.checksum(bytes)), - "org/jacoco/core/analysis/AnalyzerTest", 100); + "org/jacoco/core/analysis/AnalyzerTest", 200); analyzer.analyzeClass(bytes, "Test"); assertFalse(classes.get("org/jacoco/core/analysis/AnalyzerTest") .isNoMatch()); @@ -102,7 +102,7 @@ public class AnalyzerTest { @Test public void testAnalyzeClassNoIdMatch() throws IOException { executionData.get(Long.valueOf(0), - "org/jacoco/core/analysis/AnalyzerTest", 100); + "org/jacoco/core/analysis/AnalyzerTest", 200); analyzer.analyzeClass( TargetLoader.getClassDataAsBytes(AnalyzerTest.class), "Test"); assertTrue(classes.get("org/jacoco/core/analysis/AnalyzerTest") 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 440b4f38..8081c675 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 @@ -12,6 +12,8 @@ package org.jacoco.core.internal.flow; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.objectweb.asm.Opcodes.*; @@ -36,6 +38,13 @@ public class LabelFlowAnalyzerTest { } @Test + public void testInit() { + assertFalse(analyzer.successor); + assertTrue(analyzer.first); + assertNull(analyzer.lineStart); + } + + @Test public void testFlowScenario01() { assertFalse(LabelInfo.isMultiTarget(label)); assertFalse(LabelInfo.isSuccessor(label)); @@ -134,12 +143,6 @@ public class LabelFlowAnalyzerTest { } @Test - public void testInit() { - assertFalse(analyzer.successor); - assertTrue(analyzer.first); - } - - @Test public void testInsn() { testInsn(NOP, true); testInsn(ACONST_NULL, true); @@ -294,17 +297,27 @@ public class LabelFlowAnalyzerTest { } @Test + public void testLineNumber() { + analyzer.visitLineNumber(42, label); + assertSame(label, analyzer.lineStart); + } + + @Test public void testMethodInsn() { + analyzer.visitLineNumber(42, label); analyzer.visitMethodInsn(INVOKEVIRTUAL, "Foo", "doit", "()V", false); assertTrue(analyzer.successor); assertFalse(analyzer.first); + assertTrue(LabelInfo.isMethodInvocationLine(label)); } @Test public void testInvokeDynamicInsn() { + analyzer.visitLineNumber(42, label); analyzer.visitInvokeDynamicInsn("foo", "()V", null); assertTrue(analyzer.successor); assertFalse(analyzer.first); + assertTrue(LabelInfo.isMethodInvocationLine(label)); } @Test diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/flow/LabelInfoTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/flow/LabelInfoTest.java index c5d74a6c..d83bee6e 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/flow/LabelInfoTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/flow/LabelInfoTest.java @@ -37,6 +37,7 @@ public class LabelInfoTest { public void testDefaults() { assertFalse(LabelInfo.isMultiTarget(label)); assertFalse(LabelInfo.isSuccessor(label)); + assertFalse(LabelInfo.isMethodInvocationLine(label)); assertFalse(LabelInfo.isDone(label)); assertEquals(LabelInfo.NO_PROBE, LabelInfo.getProbeId(label)); assertNull(LabelInfo.getIntermediateLabel(label)); @@ -90,6 +91,42 @@ public class LabelInfoTest { } @Test + public void testMethodInvocationLine() { + LabelInfo.setMethodInvocationLine(label); + assertTrue(LabelInfo.isMethodInvocationLine(label)); + } + + @Test + public void testNeedsProbe() { + testNeedsProbe(false, false, false, false); + testNeedsProbe(true, false, false, false); + testNeedsProbe(false, true, false, false); + testNeedsProbe(true, true, false, false); + testNeedsProbe(false, false, true, false); + testNeedsProbe(true, false, true, true); + testNeedsProbe(false, true, true, true); + testNeedsProbe(true, true, true, true); + } + + private void testNeedsProbe(boolean multitarget, + boolean methodinvocationline, boolean successor, boolean expected) { + if (multitarget) { + LabelInfo.setTarget(label); + LabelInfo.setTarget(label); + } + if (methodinvocationline) { + LabelInfo.setMethodInvocationLine(label); + } + if (successor) { + LabelInfo.setSuccessor(label); + } + assertTrue(expected == LabelInfo.needsProbe(label)); + + // Reset: + label = new Label(); + } + + @Test public void testSetResetDone1() { LabelInfo.setDone(label); assertTrue(LabelInfo.isDone(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 03517826..40080914 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 @@ -36,7 +36,7 @@ public class ExceptionsTest extends ValidationTestBase { // 1. Implicit Exception // Currently no coverage at all, as we don't see when a block aborts // somewhere in the middle. - assertLine("implicitException.before", ICounter.NOT_COVERED); + assertLine("implicitException.before", ICounter.FULLY_COVERED); assertLine("implicitException.exception", ICounter.NOT_COVERED); assertLine("implicitException.after", ICounter.NOT_COVERED); @@ -55,7 +55,7 @@ public class ExceptionsTest extends ValidationTestBase { // somewhere in the middle. assertLine("implicitExceptionTryCatch.beforeBlock", ICounter.FULLY_COVERED); - assertLine("implicitExceptionTryCatch.before", ICounter.NOT_COVERED); + assertLine("implicitExceptionTryCatch.before", ICounter.FULLY_COVERED); assertLine("implicitExceptionTryCatch.exception", ICounter.NOT_COVERED); assertLine("implicitExceptionTryCatch.after", ICounter.NOT_COVERED); assertLine("implicitExceptionTryCatch.catchBlock", @@ -89,7 +89,7 @@ public class ExceptionsTest extends ValidationTestBase { // Finally block is yellow as the non-exception path is missing. assertLine("implicitExceptionFinally.beforeBlock", ICounter.FULLY_COVERED); - assertLine("implicitExceptionFinally.before", ICounter.NOT_COVERED); + assertLine("implicitExceptionFinally.before", ICounter.FULLY_COVERED); assertLine("implicitExceptionFinally.exception", ICounter.NOT_COVERED); assertLine("implicitExceptionFinally.after", ICounter.NOT_COVERED); assertLine("implicitExceptionFinally.finallyBlock", |