Skip to content

Commit

Permalink
Merge pull request #75 from cqse/fix_minus_one_coverage
Browse files Browse the repository at this point in the history
Fixed #74
  • Loading branch information
albertsteckermeier authored Jun 13, 2019
2 parents d46f684 + 82155bd commit dc67b19
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
We use [semantic versioning][semver]

# Next version
- [fix] Prevent `-1` to show up as covered line in Testwise Coverage report

# 13.0.0
- [feature] added `dump-on-exit` option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
import java.util.Set;

/**
* Stateful builder for the {@link Instruction}s of a method. All instructions
* of a method must be added in their original sequence along with additional
* information like line numbers. Afterwards the instructions can be obtained
* Stateful builder for the {@link Instruction}s of a method. All instructions of a method must be added in their
* original sequence along with additional information like line numbers. Afterwards the instructions can be obtained
* with the <code>getInstructions()</code> method.
* <p>
* It's core is a copy of {@link org.jacoco.core.internal.analysis.InstructionsBuilder} that has been
* extended with caching functionality to speed up report generation.
* It's core is a copy of {@link org.jacoco.core.internal.analysis.InstructionsBuilder} that has been extended with
* caching functionality to speed up report generation.
* <p>
* This class contains callbacks for stepping through a method at bytecode level which has been
* decorated with probes by JaCoCo in a depth-first-search like way.
* This class contains callbacks for stepping through a method at bytecode level which has been decorated with probes by
* JaCoCo in a depth-first-search like way.
* <p>
* Changes that have been applied to the original class are marked with ADDED and REMOVED comments to make it as easy
* as possible to adjust the implementation to new versions of JaCoCo.
* Changes that have been applied to the original class are marked with ADDED and REMOVED comments to make it as easy as
* possible to adjust the implementation to new versions of JaCoCo.
* <p>
* When updating JaCoCo make a diff of the previous {@link org.jacoco.core.internal.analysis.InstructionsBuilder}
* implementation and the new implementation and update this class accordingly.
Expand All @@ -48,8 +47,7 @@ public class CachingInstructionsBuilder extends InstructionsBuilder {
private Instruction currentInsn;

/**
* All instructions of a method mapped from the ASM node to the
* corresponding {@link Instruction} instance.
* All instructions of a method mapped from the ASM node to the corresponding {@link Instruction} instance.
*/
private final Map<AbstractInsnNode, Instruction> instructions;

Expand All @@ -61,18 +59,16 @@ public class CachingInstructionsBuilder extends InstructionsBuilder {
private final List<Label> currentLabel;

/**
* List of all jumps within the control flow. We need to store jumps
* temporarily as the target {@link Instruction} may not been known yet.
* List of all jumps within the control flow. We need to store jumps temporarily as the target {@link Instruction}
* may not been known yet.
*/
private final List<Jump> jumps;


/**
* Creates a new builder instance which can be used to analyze a single
* method.
* Creates a new builder instance which can be used to analyze a single method.
* <p>
* ADDED ClassCoverageLookup classCoverageLookup parameter
* REMOVED final boolean[] probes
* ADDED ClassCoverageLookup classCoverageLookup parameter REMOVED final boolean[] probes
*
* @param classCoverageLookup cache of the class' probes
*/
Expand All @@ -87,18 +83,17 @@ public CachingInstructionsBuilder(ClassCoverageLookup classCoverageLookup) {
}

/**
* Sets the current source line. All subsequently added instructions will be
* assigned to this line. If no line is set (e.g. for classes compiled
* without debug information) {@link ISourceNode#UNKNOWN_LINE} is assigned
* to the instructions.
* Sets the current source line. All subsequently added instructions will be assigned to this line. If no line is
* set (e.g. for classes compiled without debug information) {@link ISourceNode#UNKNOWN_LINE} is assigned to the
* instructions.
*/
void setCurrentLine(final int line) {
currentLine = line;
}

/**
* Adds a label which applies to the subsequently added instruction. Due to
* ASM internals multiple {@link Label}s can be added to an instruction.
* Adds a label which applies to the subsequently added instruction. Due to ASM internals multiple {@link Label}s
* can be added to an instruction.
*/
void addLabel(final Label label) {
currentLabel.add(label);
Expand All @@ -108,8 +103,8 @@ void addLabel(final Label label) {
}

/**
* Adds a new instruction. Instructions are by default linked with the
* previous instruction unless specified otherwise.
* Adds a new instruction. Instructions are by default linked with the previous instruction unless specified
* otherwise.
*/
void addInstruction(final AbstractInsnNode node) {
final Instruction insn = new Instruction(currentLine);
Expand All @@ -128,9 +123,8 @@ void addInstruction(final AbstractInsnNode node) {
}

/**
* Declares that the next instruction will not be a successor of the current
* instruction. This is the case with an unconditional jump or technically
* when a probe was inserted before.
* Declares that the next instruction will not be a successor of the current instruction. This is the case with an
* unconditional jump or technically when a probe was inserted before.
*/
void noSuccessor() {
currentInsn = null;
Expand Down Expand Up @@ -163,8 +157,8 @@ void addProbe(final int probeId, final int branch) {
}

/**
* Returns the status for all instructions of this method. This method must
* be called exactly once after the instructions have been added.
* Returns the status for all instructions of this method. This method must be called exactly once after the
* instructions have been added.
*/
public void fillCache() {
// Wire jumps:
Expand All @@ -180,17 +174,20 @@ public void fillCache() {
Instruction instruction = coveredProbe.instruction;
Set<Integer> coveredLines = new HashSet<>();
while (instruction != null) {
coveredLines.add(instruction.getLine());
if (instruction.getLine() != -1) {
// Only add the line number if one is associated with the instruction.
// This is not the case for e.g. Lombok generated code.
coveredLines.add(instruction.getLine());
}
instruction = getPredecessor(instruction);
}
classCoverageLookup.addProbe(coveredProbe.probeId, coveredLines);
}
}

/**
* ADDED
* Helper to get the private field predecessor from an instruction. The predecessor of an instruction
* is the preceding node according to the control flow graph of the method.
* ADDED Helper to get the private field predecessor from an instruction. The predecessor of an instruction is the
* preceding node according to the control flow graph of the method.
*/
private Instruction getPredecessor(Instruction instruction) {
try {
Expand Down

0 comments on commit dc67b19

Please sign in to comment.