From 9196cf3448638e7e58a14eefb2e011bde81db9a3 Mon Sep 17 00:00:00 2001 From: irongut Date: Sat, 19 Feb 2022 02:37:17 +0000 Subject: [PATCH] dont fail if branch metrics missing #33 --- src/CodeCoverageSummary/Program.cs | 31 +- src/coverage.simplecov.xml | 441 +++++++++++++++++++++++++++++ 2 files changed, 461 insertions(+), 11 deletions(-) create mode 100644 src/coverage.simplecov.xml diff --git a/src/CodeCoverageSummary/Program.cs b/src/CodeCoverageSummary/Program.cs index e1e2ca3..433e962 100644 --- a/src/CodeCoverageSummary/Program.cs +++ b/src/CodeCoverageSummary/Program.cs @@ -59,6 +59,11 @@ namespace CodeCoverageSummary } else { + // hide branch rate if metrics missing + bool hideBranchRate = o.HideBranchRate; + if (summary.BranchRate == 0 && summary.BranchesCovered == 0 && summary.BranchesValid == 0) + hideBranchRate = true; + // set health badge thresholds if (!string.IsNullOrWhiteSpace(o.Thresholds)) SetThresholds(o.Thresholds); @@ -72,14 +77,14 @@ namespace CodeCoverageSummary if (o.Format.Equals("text", StringComparison.OrdinalIgnoreCase)) { fileExt = "txt"; - output = GenerateTextOutput(summary, badgeUrl, o.Indicators, o.HideBranchRate, o.HideComplexity); + output = GenerateTextOutput(summary, badgeUrl, o.Indicators, hideBranchRate, o.HideComplexity); if (o.FailBelowThreshold) output += $"Minimum allowed line rate is {lowerThreshold * 100:N0}%{Environment.NewLine}"; } else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase)) { fileExt = "md"; - output = GenerateMarkdownOutput(summary, badgeUrl, o.Indicators, o.HideBranchRate, o.HideComplexity); + output = GenerateMarkdownOutput(summary, badgeUrl, o.Indicators, hideBranchRate, o.HideComplexity); if (o.FailBelowThreshold) output += $"{Environment.NewLine}_Minimum allowed line rate is `{lowerThreshold * 100:N0}%`_{Environment.NewLine}"; } @@ -156,17 +161,21 @@ namespace CodeCoverageSummary var branchR = from item in coverage.Attributes() where item.Name == "branch-rate" select item; - summary.BranchRate += double.Parse(branchR.First().Value); - var branchesCovered = from item in coverage.Attributes() - where item.Name == "branches-covered" - select item; - summary.BranchesCovered += int.Parse(branchesCovered.First().Value); + if (branchR.Any()) + { + summary.BranchRate += double.Parse(branchR.First().Value); - var branchesValid = from item in coverage.Attributes() - where item.Name == "branches-valid" - select item; - summary.BranchesValid += int.Parse(branchesValid.First().Value); + var branchesCovered = from item in coverage.Attributes() + where item.Name == "branches-covered" + select item; + summary.BranchesCovered += int.Parse(branchesCovered.First().Value); + + var branchesValid = from item in coverage.Attributes() + where item.Name == "branches-valid" + select item; + summary.BranchesValid += int.Parse(branchesValid.First().Value); + } // test coverage for individual packages var packages = from item in coverage.Descendants("package") diff --git a/src/coverage.simplecov.xml b/src/coverage.simplecov.xml new file mode 100644 index 0000000..b29e3fd --- /dev/null +++ b/src/coverage.simplecov.xml @@ -0,0 +1,441 @@ + + + + + + /Users/pboling/src/my/oauth2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file