From 600fe7dedfd697443d0de9944d974a904649dbdc Mon Sep 17 00:00:00 2001 From: qxo <49526356@qq.com> Date: Sat, 19 Sep 2020 08:26:48 +0800 Subject: [PATCH] feat: add Line Coverage on the console --- .../tooling/MutationCoverage.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java b/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java index 9c136c3db..6baa50edc 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java @@ -35,6 +35,7 @@ import org.pitest.classpath.CodeSource; import org.pitest.coverage.CoverageDatabase; import org.pitest.coverage.CoverageGenerator; +import org.pitest.coverage.CoverageSummary; import org.pitest.coverage.TestInfo; import org.pitest.functional.FCollection; import org.pitest.help.Help; @@ -60,6 +61,7 @@ import org.pitest.mutationtest.incremental.DefaultCodeHistory; import org.pitest.mutationtest.incremental.HistoryListener; import org.pitest.mutationtest.incremental.IncrementalAnalyser; +import org.pitest.mutationtest.statistics.MutationStatistics; import org.pitest.mutationtest.statistics.MutationStatisticsListener; import org.pitest.mutationtest.statistics.Score; import org.pitest.util.Log; @@ -154,10 +156,10 @@ public CombinedStatistics runReport() throws IOException { LOG.info("Completed in " + timeSpan(t0)); - printStats(stats); - - return new CombinedStatistics(stats.getStatistics(), + final CombinedStatistics combinedStatistics = new CombinedStatistics(stats.getStatistics(), coverageData.createSummary()); + printStats(combinedStatistics); + return combinedStatistics; } @@ -223,13 +225,14 @@ private void verifyBuildSuitableForMutationTesting() { this.strategies.buildVerifier().verify(this.code); } - private void printStats(final MutationStatisticsListener stats) { + private void printStats(final CombinedStatistics stats) { final PrintStream ps = System.out; ps.println(StringUtil.separatorLine('=')); ps.println("- Mutators"); ps.println(StringUtil.separatorLine('=')); - for (final Score each : stats.getStatistics().getScores()) { + final MutationStatistics mutationStat = stats.getMutationStatistics(); + for (final Score each : mutationStat.getScores()) { each.report(ps); ps.println(StringUtil.separatorLine()); } @@ -242,7 +245,12 @@ private void printStats(final MutationStatisticsListener stats) { ps.println(StringUtil.separatorLine('=')); ps.println("- Statistics"); ps.println(StringUtil.separatorLine('=')); - stats.getStatistics().report(ps); + final CoverageSummary coverage = stats.getCoverageSummary(); + if (coverage != null) { + ps.println(String.format(">> Line Coverage: %d/%d (%d%%)", coverage.getNumberOfCoveredLines(), + coverage.getNumberOfLines(), coverage.getCoverage())); + } + mutationStat.report(ps); } private List buildMutationTests(