Skip to content

Commit

Permalink
Merge pull request #180 from kolipka/overall
Browse files Browse the repository at this point in the history
Add total line coverage for badge generators
  • Loading branch information
tonerdo committed Sep 15, 2018
2 parents fece36a + 64b3003 commit 47206b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/coverlet.console/Program.cs
Expand Up @@ -86,6 +86,9 @@ static int Main(string[] args)
var exceptionBuilder = new StringBuilder();
var coverageTable = new ConsoleTable("Module", "Line", "Branch", "Method");
var thresholdFailed = false;
var overallLineCoverage = summary.CalculateLineCoverage(result.Modules).Percent * 100;
var overallBranchCoverage = summary.CalculateBranchCoverage(result.Modules).Percent * 100;
var overallMethodCoverage = summary.CalculateMethodCoverage(result.Modules).Percent * 100;
foreach (var _module in result.Modules)
{
Expand Down Expand Up @@ -119,6 +122,10 @@ static int Main(string[] args)
logger.LogInformation(string.Empty);
logger.LogInformation(coverageTable.ToStringAlternative());
logger.LogInformation(string.Empty);
logger.LogInformation($"Total Line {overallLineCoverage}%");
logger.LogInformation($"Total Branch {overallBranchCoverage}%");
logger.LogInformation($"Total Method {overallMethodCoverage}%");
if (thresholdFailed)
throw new Exception(exceptionBuilder.ToString().TrimEnd(Environment.NewLine.ToCharArray()));
Expand Down
7 changes: 7 additions & 0 deletions src/coverlet.msbuild.tasks/CoverageResultTask.cs
Expand Up @@ -79,6 +79,9 @@ public override bool Execute()
var summary = new CoverageSummary();
var exceptionBuilder = new StringBuilder();
var coverageTable = new ConsoleTable("Module", "Line", "Branch", "Method");
var overallLineCoverage = summary.CalculateLineCoverage(result.Modules).Percent * 100;
var overallBranchCoverage = summary.CalculateBranchCoverage(result.Modules).Percent * 100;
var overallMethodCoverage = summary.CalculateMethodCoverage(result.Modules).Percent * 100;

foreach (var module in result.Modules)
{
Expand Down Expand Up @@ -112,6 +115,10 @@ public override bool Execute()

Console.WriteLine();
Console.WriteLine(coverageTable.ToStringAlternative());
Console.WriteLine();
Console.WriteLine($"Total Line {overallLineCoverage}%");
Console.WriteLine($"Total Branch {overallBranchCoverage}%");
Console.WriteLine($"Total Method {overallMethodCoverage}%");

if (thresholdFailed)
throw new Exception(exceptionBuilder.ToString().TrimEnd(Environment.NewLine.ToCharArray()));
Expand Down

0 comments on commit 47206b0

Please sign in to comment.