diff --git a/src/CodeCoverageSummary/CodeSummary.cs b/src/CodeCoverageSummary/CodeSummary.cs index 8183544..b73296c 100644 --- a/src/CodeCoverageSummary/CodeSummary.cs +++ b/src/CodeCoverageSummary/CodeSummary.cs @@ -10,7 +10,7 @@ namespace CodeCoverageSummary public double BranchRate { get; set; } - public int Complexity { get; set; } + public double Complexity { get; set; } } public class CodeSummary @@ -27,7 +27,7 @@ namespace CodeCoverageSummary public int BranchesValid { get; set; } - public int Complexity { get; set; } + public double Complexity { get; set; } public List Packages { get; set; } diff --git a/src/CodeCoverageSummary/Program.cs b/src/CodeCoverageSummary/Program.cs index 4d85b32..27b4c2b 100644 --- a/src/CodeCoverageSummary/Program.cs +++ b/src/CodeCoverageSummary/Program.cs @@ -134,17 +134,19 @@ namespace CodeCoverageSummary var packages = from item in coverage.Descendants("package") select item; + int i = 1; foreach (var item in packages) { CodeCoverage packageCoverage = new() { - Name = item.Attribute("name").Value, - LineRate = double.Parse(item.Attribute("line-rate").Value), - BranchRate = double.Parse(item.Attribute("branch-rate").Value), - Complexity = int.Parse(item.Attribute("complexity")?.Value ?? "0") + Name = string.IsNullOrWhiteSpace(item.Attribute("name").Value) ? $"Package {i}" : item.Attribute("name").Value, + LineRate = double.Parse(item.Attribute("line-rate")?.Value ?? "0"), + BranchRate = double.Parse(item.Attribute("branch-rate")?.Value ?? "0"), + Complexity = double.Parse(item.Attribute("complexity")?.Value ?? "0") }; summary.Packages.Add(packageCoverage); summary.Complexity += packageCoverage.Complexity; + i++; } return summary; @@ -184,12 +186,27 @@ namespace CodeCoverageSummary } textOutput.AppendLine($"Line Rate = {summary.LineRate * 100:N0}%, Lines Covered = {summary.LinesCovered} / {summary.LinesValid}") - .AppendLine($"Branch Rate = {summary.BranchRate * 100:N0}%, Branches Covered = {summary.BranchesCovered} / {summary.BranchesValid}") - .AppendLine($"Complexity = {summary.Complexity}"); + .AppendLine($"Branch Rate = {summary.BranchRate * 100:N0}%, Branches Covered = {summary.BranchesCovered} / {summary.BranchesValid}"); + + if (summary.Complexity % 1 == 0) + { + textOutput.AppendLine($"Complexity = {summary.Complexity}"); + } + else + { + textOutput.AppendLine($"Complexity = {summary.Complexity:N4}"); + } foreach (CodeCoverage package in summary.Packages) { - textOutput.AppendLine($"{package.Name}: Line Rate = {package.LineRate * 100:N0}%, Branch Rate = {package.BranchRate * 100:N0}%, Complexity = {package.Complexity}"); + if (package.Complexity % 1 == 0) + { + textOutput.AppendLine($"{package.Name}: Line Rate = {package.LineRate * 100:N0}%, Branch Rate = {package.BranchRate * 100:N0}%, Complexity = {package.Complexity}"); + } + else + { + textOutput.AppendLine($"{package.Name}: Line Rate = {package.LineRate * 100:N0}%, Branch Rate = {package.BranchRate * 100:N0}%, Complexity = {package.Complexity:N4}"); + } } return textOutput.ToString(); @@ -210,11 +227,27 @@ namespace CodeCoverageSummary foreach (CodeCoverage package in summary.Packages) { - markdownOutput.AppendLine($"{package.Name} | {package.LineRate * 100:N0}% | {package.BranchRate * 100:N0}% | {package.Complexity}"); + if (package.Complexity % 1 == 0) + { + markdownOutput.AppendLine($"{package.Name} | {package.LineRate * 100:N0}% | {package.BranchRate * 100:N0}% | {package.Complexity}"); + } + else + { + markdownOutput.AppendLine($"{package.Name} | {package.LineRate * 100:N0}% | {package.BranchRate * 100:N0}% | {package.Complexity:N4}"); + } } markdownOutput.Append($"**Summary** | **{summary.LineRate * 100:N0}%** ({summary.LinesCovered} / {summary.LinesValid}) | ") - .AppendLine($"**{summary.BranchRate * 100:N0}%** ({summary.BranchesCovered} / {summary.BranchesValid}) | {summary.Complexity}"); + .Append($"**{summary.BranchRate * 100:N0}%** ({summary.BranchesCovered} / {summary.BranchesValid}) | "); + + if (summary.Complexity % 1 == 0) + { + markdownOutput.AppendLine(summary.Complexity.ToString()); + } + else + { + markdownOutput.AppendLine(summary.Complexity.ToString("N4")); + } return markdownOutput.ToString(); } diff --git a/src/CodeCoverageSummary/Properties/launchSettings.json b/src/CodeCoverageSummary/Properties/launchSettings.json index 2fd0dee..77ec29b 100644 --- a/src/CodeCoverageSummary/Properties/launchSettings.json +++ b/src/CodeCoverageSummary/Properties/launchSettings.json @@ -1,7 +1,8 @@ { "profiles": { "CodeCoverageSummary": { - "commandName": "Project" + "commandName": "Project", + "commandLineArgs": "../../../../coverage.gcovr.xml --format=md --badge=true" }, "Docker": { "commandName": "Docker", diff --git a/src/coverage.gcovr.xml b/src/coverage.gcovr.xml new file mode 100644 index 0000000..ef7fc73 --- /dev/null +++ b/src/coverage.gcovr.xml @@ -0,0 +1,1054 @@ + + + + + src/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +