-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add option to set detail of coverage information + method level instr…
…uction coverage
- Loading branch information
Showing
16 changed files
with
272 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Spoon files | ||
spooned/ | ||
|
||
# Config files | ||
.idea/ | ||
test-runner.iml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/eu/stamp_project/testrunner/listener/impl/CoverageCollectorMethodDetailed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package eu.stamp_project.testrunner.listener.impl; | ||
|
||
import eu.stamp_project.testrunner.listener.Coverage; | ||
import eu.stamp_project.testrunner.listener.CoverageTransformer; | ||
import org.jacoco.core.analysis.*; | ||
import org.jacoco.core.data.ExecutionDataStore; | ||
|
||
import java.io.*; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
public class CoverageCollectorMethodDetailed implements CoverageTransformer { | ||
@Override | ||
public Coverage transformJacocoObject(ExecutionDataStore executionData, String classesDirectory) { | ||
final CoverageBuilder coverageBuilder = new CoverageBuilder(); | ||
final Analyzer analyzer = new Analyzer(executionData, coverageBuilder); | ||
try { | ||
analyzer.analyzeAll(new File(classesDirectory)); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
final int[] counter = new int[2]; | ||
final StringBuilder builderExecutionPath = new StringBuilder(); | ||
coverageBuilder.getClasses().forEach(coverage -> { | ||
final List<Integer> listOfCountForCounterFunction = | ||
CoverageImpl.getListOfCountForCounterFunction(coverage, ICounter::getCoveredCount); | ||
builderExecutionPath.append(coverage.getName()) | ||
.append(":") | ||
.append(getCoverageInformationPerMethod(coverage, ICounter::getCoveredCount)) | ||
.append("-"); | ||
counter[0] += listOfCountForCounterFunction.stream() | ||
.mapToInt(Integer::intValue) | ||
.sum(); | ||
counter[1] += CoverageImpl.getListOfCountForCounterFunction(coverage, ICounter::getTotalCount) | ||
.stream() | ||
.mapToInt(Integer::intValue) | ||
.sum(); | ||
}); | ||
|
||
Coverage coverage = new CoverageImpl( counter[0], counter[1],builderExecutionPath.toString()); | ||
return coverage; | ||
} | ||
|
||
public static String getCoverageInformationPerMethod(IClassCoverage coverage, | ||
Function<ICounter, Integer> counterGetter) { | ||
StringBuilder builder = new StringBuilder(); | ||
coverage.getMethods() | ||
.stream() | ||
.filter(iMethodCoverage -> !"<clinit>".equals(iMethodCoverage.getName())) | ||
.forEach(iMethodCoverage -> { | ||
builder.append(iMethodCoverage.getName()).append("+"); | ||
builder.append(iMethodCoverage.getDesc()).append("+"); | ||
builder.append(IntStream.range(iMethodCoverage.getFirstLine(), iMethodCoverage.getLastLine() + 1) | ||
.mapToObj(iMethodCoverage::getLine) | ||
.map(ILine::getInstructionCounter) | ||
.map(counterGetter) | ||
.map(Object::toString) | ||
.collect(Collectors.joining(","))); | ||
builder.append("|"); | ||
}); | ||
if (builder.length() > 0) { | ||
builder.replace(builder.length()-1, builder.length(),""); | ||
} | ||
return builder.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,5 +77,4 @@ public Coverage transformJacocoObject(ExecutionDataStore executionData, String c | |
return coverage; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.