Skip to content

Add total line coverage for badge generators #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/coverlet.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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 @@ -118,6 +121,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
Original file line number Diff line number Diff line change
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