Skip to content

Commit

Permalink
ignore the assert statement's conditional branch. (jacoco#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
morganga committed Oct 21, 2022
1 parent 8a367e3 commit c2aff3e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Expand Up @@ -23,7 +23,7 @@ private AssertTarget() {
}

public static void main(String[] args) {
assert t() : "msg"; // assertPartlyCovered(1, 1)
assert t() : "msg"; // assertFullyCovered()
}

}
Expand Up @@ -17,6 +17,7 @@
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.MethodNode;

/**
Expand Down Expand Up @@ -124,8 +125,7 @@ public void should_filter_assert() {
"Z");
final Label label = new Label();
m.visitJumpInsn(Opcodes.IFNE, label);
final Range range = new Range(m.instructions.getLast(),
m.instructions.getLast());
final AbstractInsnNode fromInclusive = m.instructions.getLast();
m.visitVarInsn(Opcodes.ILOAD, 1);
m.visitJumpInsn(Opcodes.IFNE, label);
m.visitTypeInsn(Opcodes.NEW, "java/lang/AssertionError");
Expand All @@ -135,10 +135,12 @@ public void should_filter_assert() {
"<init>", "(Ljava/lang/Object;)V", false);
m.visitInsn(Opcodes.ATHROW);
m.visitLabel(label);
final AbstractInsnNode toInclusive = m.instructions.getLast();
m.visitInsn(Opcodes.NOP);

filter.filter(m, context, output);

final Range range = new Range(fromInclusive, toInclusive);
assertIgnored(range);
}

Expand Down
Expand Up @@ -14,6 +14,7 @@

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.MethodNode;

/**
Expand Down Expand Up @@ -58,7 +59,7 @@ public void matchGet(final String className,
"Z");
nextIs(Opcodes.IFNE);
if (cursor != null) {
output.ignore(cursor, cursor);
output.ignore(cursor, ((JumpInsnNode) cursor).label);
}
}
}
Expand Down

0 comments on commit c2aff3e

Please sign in to comment.