aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core.test
diff options
context:
space:
mode:
authorEvgeny Mandrikov <Godin@users.noreply.github.com>2017-01-17 02:03:39 +0100
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2017-01-17 02:03:39 +0100
commitd80b6b55af2c6ad10c04067ef7853161deac7e83 (patch)
tree3b660e9e11d32064c7dd707f42143a7e2cd404bb /org.jacoco.core.test
parentb20e49549418a205ea42b1922a16d5f7bce057c7 (diff)
downloadjacoco-d80b6b55af2c6ad10c04067ef7853161deac7e83.tar.gz
MethodAnalyzerTest should not violate contracts of ASM API (#480)
In particular visitLineNumber methods must be called after the labels passed as arguments have been visited. This is important because otherwise test does not simulate behavior of reading from bytecode.
Diffstat (limited to 'org.jacoco.core.test')
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/internal/analysis/MethodAnalyzerTest.java53
1 files changed, 40 insertions, 13 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/MethodAnalyzerTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/MethodAnalyzerTest.java
index bdc5e6b2..6bcbd630 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/MethodAnalyzerTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/MethodAnalyzerTest.java
@@ -26,6 +26,7 @@ import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TryCatchBlockNode;
+import org.objectweb.asm.util.CheckMethodAdapter;
/**
* Unit tests for {@link MethodAnalyzer}.
@@ -55,9 +56,13 @@ public class MethodAnalyzerTest implements IProbeIdGenerator {
// === Scenario: linear Sequence without branches ===
private void createLinearSequence() {
- method.visitLineNumber(1001, new Label());
+ final Label l0 = new Label();
+ method.visitLabel(l0);
+ method.visitLineNumber(1001, l0);
method.visitInsn(Opcodes.NOP);
- method.visitLineNumber(1002, new Label());
+ final Label l1 = new Label();
+ method.visitLabel(l1);
+ method.visitLineNumber(1002, l1);
method.visitInsn(Opcodes.RETURN);
}
@@ -95,11 +100,15 @@ public class MethodAnalyzerTest implements IProbeIdGenerator {
// === Scenario: simple if branch ===
private void createIfBranch() {
- method.visitLineNumber(1001, new Label());
+ final Label l0 = new Label();
+ method.visitLabel(l0);
+ method.visitLineNumber(1001, l0);
method.visitVarInsn(Opcodes.ILOAD, 1);
Label l1 = new Label();
method.visitJumpInsn(Opcodes.IFEQ, l1);
- method.visitLineNumber(1002, new Label());
+ final Label l2 = new Label();
+ method.visitLabel(l2);
+ method.visitLineNumber(1002, l2);
method.visitLdcInsn("a");
method.visitInsn(Opcodes.ARETURN);
method.visitLabel(l1);
@@ -156,11 +165,15 @@ public class MethodAnalyzerTest implements IProbeIdGenerator {
// === Scenario: branch which merges back ===
private void createIfBranchMerge() {
- method.visitLineNumber(1001, new Label());
+ final Label l0 = new Label();
+ method.visitLabel(l0);
+ method.visitLineNumber(1001, l0);
method.visitVarInsn(Opcodes.ILOAD, 1);
Label l1 = new Label();
method.visitJumpInsn(Opcodes.IFEQ, l1);
- method.visitLineNumber(1002, new Label());
+ final Label l2 = new Label();
+ method.visitLabel(l2);
+ method.visitLineNumber(1002, l2);
method.visitInsn(Opcodes.NOP);
method.visitLabel(l1);
method.visitLineNumber(1003, l1);
@@ -216,7 +229,9 @@ public class MethodAnalyzerTest implements IProbeIdGenerator {
// === Scenario: branch which jump backwards ===
private void createJumpBackwards() {
- method.visitLineNumber(1001, new Label());
+ final Label l0 = new Label();
+ method.visitLabel(l0);
+ method.visitLineNumber(1001, l0);
final Label l1 = new Label();
method.visitJumpInsn(Opcodes.GOTO, l1);
final Label l2 = new Label();
@@ -302,7 +317,9 @@ public class MethodAnalyzerTest implements IProbeIdGenerator {
// === Scenario: table switch ===
private void createTableSwitch() {
- method.visitLineNumber(1001, new Label());
+ final Label l0 = new Label();
+ method.visitLabel(l0);
+ method.visitLineNumber(1001, l0);
method.visitVarInsn(Opcodes.ILOAD, 1);
Label l1 = new Label();
Label l2 = new Label();
@@ -312,14 +329,18 @@ public class MethodAnalyzerTest implements IProbeIdGenerator {
method.visitLineNumber(1002, l1);
method.visitIntInsn(Opcodes.BIPUSH, 11);
method.visitVarInsn(Opcodes.ISTORE, 2);
- method.visitLineNumber(1003, new Label());
+ final Label l4 = new Label();
+ method.visitLabel(l4);
+ method.visitLineNumber(1003, l4);
Label l5 = new Label();
method.visitJumpInsn(Opcodes.GOTO, l5);
method.visitLabel(l2);
method.visitLineNumber(1004, l2);
method.visitIntInsn(Opcodes.BIPUSH, 22);
method.visitVarInsn(Opcodes.ISTORE, 2);
- method.visitLineNumber(1005, new Label());
+ final Label l6 = new Label();
+ method.visitLabel(l6);
+ method.visitLineNumber(1005, l6);
method.visitJumpInsn(Opcodes.GOTO, l5);
method.visitLabel(l3);
method.visitLineNumber(1006, l3);
@@ -402,10 +423,14 @@ public class MethodAnalyzerTest implements IProbeIdGenerator {
// === Scenario: table switch with merge ===
private void createTableSwitchMerge() {
- method.visitLineNumber(1001, new Label());
+ final Label l0 = new Label();
+ method.visitLabel(l0);
+ method.visitLineNumber(1001, l0);
method.visitInsn(Opcodes.ICONST_0);
method.visitVarInsn(Opcodes.ISTORE, 2);
- method.visitLineNumber(1002, new Label());
+ final Label l1 = new Label();
+ method.visitLabel(l1);
+ method.visitLineNumber(1002, l1);
method.visitVarInsn(Opcodes.ILOAD, 1);
Label l2 = new Label();
Label l3 = new Label();
@@ -559,7 +584,9 @@ public class MethodAnalyzerTest implements IProbeIdGenerator {
probes);
final MethodProbesAdapter probesAdapter = new MethodProbesAdapter(
analyzer, this);
- method.accept(probesAdapter);
+ // note that CheckMethodAdapter verifies that this test does not violate
+ // contracts of ASM API
+ method.accept(new CheckMethodAdapter(probesAdapter));
result = analyzer.getCoverage();
}