Skip to content

Commit 05b101a

Browse files
committed
handle NaN in branch + complexity values #46
1 parent 405344b commit 05b101a

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/CodeCoverageSummary/Program.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,19 @@ private static CodeSummary ParseTestResults(string filename, CodeSummary summary
188188

189189
if (branchR.Any())
190190
{
191-
summary.BranchRate += double.Parse(branchR.First().Value);
191+
summary.BranchRate += double.TryParse(branchR.First().Value, out double bRate) ? bRate : 0;
192192

193193
var branchesCovered = from item in coverage.Attributes()
194194
where item.Name == "branches-covered"
195195
select item;
196196

197-
if (branchesCovered.Any())
198-
summary.BranchesCovered += int.Parse(branchesCovered.First().Value);
197+
summary.BranchesCovered += int.TryParse(branchesCovered?.First().Value ?? "0", out int bCovered) ? bCovered : 0;
199198

200199
var branchesValid = from item in coverage.Attributes()
201200
where item.Name == "branches-valid"
202201
select item;
203202

204-
if (branchesValid.Any())
205-
summary.BranchesValid += int.Parse(branchesValid.First().Value);
203+
summary.BranchesValid += int.TryParse(branchesValid?.First().Value ?? "0", out int bValid) ? bValid : 0;
206204
}
207205

208206
// test coverage for individual packages
@@ -219,8 +217,8 @@ private static CodeSummary ParseTestResults(string filename, CodeSummary summary
219217
{
220218
Name = string.IsNullOrWhiteSpace(item.Attribute("name")?.Value) ? $"{Path.GetFileNameWithoutExtension(filename)} Package {i}" : item.Attribute("name").Value,
221219
LineRate = double.Parse(item.Attribute("line-rate")?.Value ?? "0"),
222-
BranchRate = double.Parse(item.Attribute("branch-rate")?.Value ?? "0"),
223-
Complexity = double.Parse(item.Attribute("complexity")?.Value ?? "0")
220+
BranchRate = double.TryParse(item.Attribute("branch-rate")?.Value ?? "0", out double bRate) ? bRate : 0,
221+
Complexity = double.TryParse(item.Attribute("complexity")?.Value ?? "0", out double complex) ? complex : 0
224222
};
225223
summary.Packages.Add(packageCoverage);
226224
summary.Complexity += packageCoverage.Complexity;

0 commit comments

Comments
 (0)