Skip to content

Commit fd886a4

Browse files
committed
Improved lcov support (take FNDA elements into account to determine whether a code element has been covered)
1 parent 957c146 commit fd886a4

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

src/Readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ CHANGELOG
7171

7272
* New: #741 Charts does not render "Full method coverage" elements if coverage information is not available
7373
* New: Added new setting "applyMaximumGroupingLevel". This allows to apply the maximum grouping level instead of the default 'By assembly' grouping in HTML reports.
74+
* New: Improved lcov support (take FNDA elements into account to determine whether a code element has been covered)
7475

7576
5.4.7.0
7677

src/ReportGenerator.Core/Parser/Analysis/CodeFile.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,7 @@ public int CoveredCodeElements
251251
get
252252
{
253253
return this.CodeElements.Count(
254-
x => this.lineCoverage.Skip(x.FirstLine)
255-
.Take(x.LastLine - x.FirstLine + 1)
256-
.Any(y => y > 0));
254+
x => x.CoverageQuota.GetValueOrDefault() > 0);
257255
}
258256
}
259257

src/ReportGenerator.Core/Parser/CodeElementBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public CodeElementBase(string name, int firstLine)
2626
/// </summary>
2727
public int FirstLine { get; }
2828

29+
/// <summary>
30+
/// Gets or sets a value indicating whether the method has not been executed.
31+
/// </summary>
32+
public bool NotExecuted { get; set; }
33+
2934
/// <summary>
3035
/// Returns a <see cref="string"/> that represents this instance.
3136
/// </summary>

src/ReportGenerator.Core/Parser/LCovParser.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ private void ProcessClass(Class @class, string fileName, string[] lines, ref int
125125

126126
var branchesByLineNumber = new Dictionary<int, ICollection<Branch>>();
127127

128+
int fndaCounter = -1;
129+
128130
while (true)
129131
{
130132
string line = lines[currentLine];
@@ -175,6 +177,19 @@ private void ProcessClass(Class @class, string fileName, string[] lines, ref int
175177
branchesByLineNumber.Add(lineNumber, branches);
176178
}
177179
}
180+
else if (line.StartsWith("FNDA:"))
181+
{
182+
fndaCounter++;
183+
184+
line = line.Substring(5);
185+
string[] tokens = line.Split(',');
186+
int executionCount = int.Parse(tokens[0], CultureInfo.InvariantCulture);
187+
188+
if (executionCount == 0)
189+
{
190+
codeElements[fndaCounter].NotExecuted = true;
191+
}
192+
}
178193
else if (line.StartsWith("DA:"))
179194
{
180195
line = line.Substring(3);
@@ -234,12 +249,16 @@ private void ProcessClass(Class @class, string fileName, string[] lines, ref int
234249
lastLine = codeElements[i + 1].FirstLine - 1;
235250
}
236251

252+
decimal? coverageOfCodeElement = codeElement.NotExecuted
253+
? 0
254+
: codeFile.CoverageQuotaInRange(codeElement.FirstLine, lastLine);
255+
237256
codeFile.AddCodeElement(new CodeElement(
238257
codeElement.Name,
239258
CodeElementType.Method,
240259
codeElement.FirstLine,
241260
lastLine,
242-
codeFile.CoverageQuotaInRange(codeElement.FirstLine, lastLine)));
261+
coverageOfCodeElement));
243262
}
244263

245264
@class.AddFile(codeFile);

0 commit comments

Comments
 (0)