Skip to content

Commit 61d1094

Browse files
authored
merge PR #10 Make compatible with gcovr
2 parents c5d12d4 + 7cd8fe4 commit 61d1094

File tree

4 files changed

+1100
-12
lines changed

4 files changed

+1100
-12
lines changed

src/CodeCoverageSummary/CodeSummary.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class CodeCoverage
1010

1111
public double BranchRate { get; set; }
1212

13-
public int Complexity { get; set; }
13+
public double Complexity { get; set; }
1414
}
1515

1616
public class CodeSummary
@@ -27,7 +27,7 @@ public class CodeSummary
2727

2828
public int BranchesValid { get; set; }
2929

30-
public int Complexity { get; set; }
30+
public double Complexity { get; set; }
3131

3232
public List<CodeCoverage> Packages { get; set; }
3333

src/CodeCoverageSummary/Program.cs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,19 @@ private static CodeSummary ParseTestResults(string filename)
134134
var packages = from item in coverage.Descendants("package")
135135
select item;
136136

137+
int i = 1;
137138
foreach (var item in packages)
138139
{
139140
CodeCoverage packageCoverage = new()
140141
{
141-
Name = item.Attribute("name").Value,
142-
LineRate = double.Parse(item.Attribute("line-rate").Value),
143-
BranchRate = double.Parse(item.Attribute("branch-rate").Value),
144-
Complexity = int.Parse(item.Attribute("complexity")?.Value ?? "0")
142+
Name = string.IsNullOrWhiteSpace(item.Attribute("name").Value) ? $"Package {i}" : item.Attribute("name").Value,
143+
LineRate = double.Parse(item.Attribute("line-rate")?.Value ?? "0"),
144+
BranchRate = double.Parse(item.Attribute("branch-rate")?.Value ?? "0"),
145+
Complexity = double.Parse(item.Attribute("complexity")?.Value ?? "0")
145146
};
146147
summary.Packages.Add(packageCoverage);
147148
summary.Complexity += packageCoverage.Complexity;
149+
i++;
148150
}
149151

150152
return summary;
@@ -184,12 +186,27 @@ private static string GenerateTextOutput(CodeSummary summary, string badgeUrl)
184186
}
185187

186188
textOutput.AppendLine($"Line Rate = {summary.LineRate * 100:N0}%, Lines Covered = {summary.LinesCovered} / {summary.LinesValid}")
187-
.AppendLine($"Branch Rate = {summary.BranchRate * 100:N0}%, Branches Covered = {summary.BranchesCovered} / {summary.BranchesValid}")
188-
.AppendLine($"Complexity = {summary.Complexity}");
189+
.AppendLine($"Branch Rate = {summary.BranchRate * 100:N0}%, Branches Covered = {summary.BranchesCovered} / {summary.BranchesValid}");
190+
191+
if (summary.Complexity % 1 == 0)
192+
{
193+
textOutput.AppendLine($"Complexity = {summary.Complexity}");
194+
}
195+
else
196+
{
197+
textOutput.AppendLine($"Complexity = {summary.Complexity:N4}");
198+
}
189199

190200
foreach (CodeCoverage package in summary.Packages)
191201
{
192-
textOutput.AppendLine($"{package.Name}: Line Rate = {package.LineRate * 100:N0}%, Branch Rate = {package.BranchRate * 100:N0}%, Complexity = {package.Complexity}");
202+
if (package.Complexity % 1 == 0)
203+
{
204+
textOutput.AppendLine($"{package.Name}: Line Rate = {package.LineRate * 100:N0}%, Branch Rate = {package.BranchRate * 100:N0}%, Complexity = {package.Complexity}");
205+
}
206+
else
207+
{
208+
textOutput.AppendLine($"{package.Name}: Line Rate = {package.LineRate * 100:N0}%, Branch Rate = {package.BranchRate * 100:N0}%, Complexity = {package.Complexity:N4}");
209+
}
193210
}
194211

195212
return textOutput.ToString();
@@ -210,11 +227,27 @@ private static string GenerateMarkdownOutput(CodeSummary summary, string badgeUr
210227

211228
foreach (CodeCoverage package in summary.Packages)
212229
{
213-
markdownOutput.AppendLine($"{package.Name} | {package.LineRate * 100:N0}% | {package.BranchRate * 100:N0}% | {package.Complexity}");
230+
if (package.Complexity % 1 == 0)
231+
{
232+
markdownOutput.AppendLine($"{package.Name} | {package.LineRate * 100:N0}% | {package.BranchRate * 100:N0}% | {package.Complexity}");
233+
}
234+
else
235+
{
236+
markdownOutput.AppendLine($"{package.Name} | {package.LineRate * 100:N0}% | {package.BranchRate * 100:N0}% | {package.Complexity:N4}");
237+
}
214238
}
215239

216240
markdownOutput.Append($"**Summary** | **{summary.LineRate * 100:N0}%** ({summary.LinesCovered} / {summary.LinesValid}) | ")
217-
.AppendLine($"**{summary.BranchRate * 100:N0}%** ({summary.BranchesCovered} / {summary.BranchesValid}) | {summary.Complexity}");
241+
.Append($"**{summary.BranchRate * 100:N0}%** ({summary.BranchesCovered} / {summary.BranchesValid}) | ");
242+
243+
if (summary.Complexity % 1 == 0)
244+
{
245+
markdownOutput.AppendLine(summary.Complexity.ToString());
246+
}
247+
else
248+
{
249+
markdownOutput.AppendLine(summary.Complexity.ToString("N4"));
250+
}
218251

219252
return markdownOutput.ToString();
220253
}

src/CodeCoverageSummary/Properties/launchSettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"profiles": {
33
"CodeCoverageSummary": {
4-
"commandName": "Project"
4+
"commandName": "Project",
5+
"commandLineArgs": "../../../../coverage.gcovr.xml --format=md --badge=true"
56
},
67
"Docker": {
78
"commandName": "Docker",

0 commit comments

Comments
 (0)