Skip to content

Commit 97735f5

Browse files
committed
#582: Removed method coverage usage for line coverage if no coverage is available
1 parent 8197991 commit 97735f5

File tree

10 files changed

+12
-139
lines changed

10 files changed

+12
-139
lines changed

src/AngularComponents/src/app/components/coverageinfo/class-row.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import { ClassViewModel } from "./viewmodels/class-viewmodel.class";
5353
{{clazz.totalLines}}
5454
</ng-container>
5555
</td>
56-
<td class="right" [title]="clazz.coverageType + ': ' + clazz.coverageRatioText" *ngIf="lineCoverageAvailable">
56+
<td class="right" [title]="clazz.coverageRatioText" *ngIf="lineCoverageAvailable">
5757
<div coverage-history-chart [historicCoverages]="clazz.lineCoverageHistory"
5858
*ngIf="clazz.lineCoverageHistory.length > 1"
5959
[ngClass]="{'historiccoverageoffset': clazz.currentHistoricCoverage !== null}"

src/AngularComponents/src/app/components/coverageinfo/data/class.class.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ export class Class {
3131
*/
3232
tl: number = 0;
3333

34-
/*
35-
* The coverageType.
36-
*/
37-
ct: string = "";
38-
39-
/*
40-
* The line coverage determined by method coverage.
41-
*/
42-
cbm: string = "";
43-
4434
/*
4535
* The coveredBranches.
4636
*/

src/AngularComponents/src/app/components/coverageinfo/viewmodels/class-viewmodel.class.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { Helper } from "./helper.class";
55

66
export class ClassViewModel extends ElementBase {
77
reportPath: string = "";
8-
_coverageType: string = "";
9-
coverageByMethod: string = "";
108
lineCoverageHistory: number[] = [];
119
branchCoverageHistory: number[] = [];
1210
methodCoverageHistory: number[] = [];
@@ -27,9 +25,6 @@ export class ClassViewModel extends ElementBase {
2725
this.coverableLines = clazz.cal;
2826
this.totalLines = clazz.tl;
2927

30-
this._coverageType = clazz.ct;
31-
this.coverageByMethod = clazz.cbm;
32-
3328
this.coveredBranches = clazz.cb;
3429
this.totalBranches = clazz.tb;
3530

@@ -49,28 +44,12 @@ export class ClassViewModel extends ElementBase {
4944

5045
override get coverage(): number {
5146
if (this.coverableLines === 0) {
52-
if (this.coverageByMethod !== "-") {
53-
return parseFloat(this.coverageByMethod);
54-
}
55-
5647
return NaN;
5748
}
5849

5950
return Helper.roundNumber(100 * this.coveredLines / this.coverableLines, 1);
6051
}
6152

62-
get coverageType(): string {
63-
if (this.coverableLines === 0) {
64-
if (this.coverageByMethod !== "-") {
65-
return this._coverageType;
66-
}
67-
68-
return "";
69-
}
70-
71-
return this._coverageType;
72-
}
73-
7453
visible(filter: string, historicCoverageFilter: string): boolean {
7554
if (filter !== "" && this.name.toLowerCase().indexOf(filter.toLowerCase()) === -1) {
7655
return false;

src/Readme.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ For further details take a look at LICENSE.txt.
6666

6767
CHANGELOG
6868

69+
5.1.17.0
70+
71+
* Fix: #582: Removed method coverage usage for line coverage if no coverage is available
72+
6973
5.1.16.0
7074

7175
* Fix: #536: Improved support for C code in Visual Studio coverage input format (*.coveragexml)

src/ReportGenerator.Core.Test/Parser/Analysis/ClassTest.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,6 @@ public void AddFile_AddSingleFile_FileIsStored()
4444
Assert.Single(sut.Files);
4545
}
4646

47-
/// <summary>
48-
/// A test for Merge
49-
/// </summary>
50-
[Fact]
51-
public void Merge_MergeClassWithCoverageQuota_CoverageQuotaApplied()
52-
{
53-
var assembly = new Assembly("C:\\test\\TestAssembly.dll");
54-
var sut = new Class("Test", assembly);
55-
var classToMerge = new Class("Test", assembly)
56-
{
57-
CoverageQuota = 15
58-
};
59-
60-
sut.Merge(classToMerge);
61-
62-
Assert.Equal(15, sut.CoverageQuota);
63-
64-
classToMerge = new Class("Test", assembly)
65-
{
66-
CoverageQuota = 20
67-
};
68-
69-
sut.Merge(classToMerge);
70-
71-
Assert.Equal(20, sut.CoverageQuota);
72-
}
73-
7447
/// <summary>
7548
/// A test for Equals
7649
/// </summary>

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

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ public class Class
3131
/// </summary>
3232
private readonly List<HistoricCoverage> historicCoverages = new List<HistoricCoverage>();
3333

34-
/// <summary>
35-
/// The coverage quota.
36-
/// </summary>
37-
private decimal? coverageQuota;
38-
3934
/// <summary>
4035
/// Initializes a new instance of the <see cref="Class"/> class.
4136
/// </summary>
@@ -118,12 +113,6 @@ internal Class(string name, Assembly assembly)
118113
/// <value>The historic coverage information.</value>
119114
public IEnumerable<HistoricCoverage> HistoricCoverages => this.historicCoverages;
120115

121-
/// <summary>
122-
/// Gets the coverage type.
123-
/// </summary>
124-
/// <value>The coverage type.</value>
125-
public CoverageType CoverageType => this.files.Count == 0 ? CoverageType.MethodCoverage : CoverageType.LineCoverage;
126-
127116
/// <summary>
128117
/// Gets the number of covered lines.
129118
/// </summary>
@@ -143,26 +132,14 @@ internal Class(string name, Assembly assembly)
143132
public int? TotalLines => this.files.SafeSum(f => f.TotalLines);
144133

145134
/// <summary>
146-
/// Gets or sets the coverage quota of the class.
135+
/// Gets the coverage quota of the class.
147136
/// </summary>
148137
/// <value>The coverage quota.</value>
149138
public decimal? CoverageQuota
150139
{
151140
get
152141
{
153-
if (this.files.Count == 0)
154-
{
155-
return this.coverageQuota;
156-
}
157-
else
158-
{
159-
return (this.CoverableLines == 0) ? (decimal?)null : (decimal)Math.Truncate(1000 * (double)this.CoveredLines / (double)this.CoverableLines) / 10;
160-
}
161-
}
162-
163-
set
164-
{
165-
this.coverageQuota = value;
142+
return (this.CoverableLines == 0) ? (decimal?)null : (decimal)Math.Truncate(1000 * (double)this.CoveredLines / (double)this.CoverableLines) / 10;
166143
}
167144
}
168145

@@ -281,15 +258,6 @@ internal void Merge(Class @class)
281258
throw new ArgumentNullException(nameof(@class));
282259
}
283260

284-
if (this.coverageQuota.HasValue && @class.coverageQuota.HasValue)
285-
{
286-
this.CoverageQuota = Math.Max(this.coverageQuota.Value, @class.coverageQuota.Value);
287-
}
288-
else if (@class.coverageQuota.HasValue)
289-
{
290-
this.CoverageQuota = @class.coverageQuota.Value;
291-
}
292-
293261
foreach (var file in @class.files)
294262
{
295263
var existingFile = this.files.FirstOrDefault(f => f.Equals(file));

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

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/ReportGenerator.Core/Parser/OpenCoverParser.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,6 @@ private void ProcessClass(IDictionary<string, XElement[]> assemblyModules, XElem
217217
@class.AddFile(ProcessFile(trackedMethods, fileIdsByFilename[file], file, methods));
218218
}
219219

220-
@class.CoverageQuota = GetCoverageQuotaOfClass(methods);
221-
222220
assembly.AddClass(@class);
223221
}
224222
}
@@ -573,24 +571,6 @@ private static string ExtractMethodName(string methodName)
573571
return fullName;
574572
}
575573

576-
/// <summary>
577-
/// Gets the coverage quota of a class.
578-
/// This method is used to get coverage quota if line coverage is not available.
579-
/// </summary>
580-
/// <param name="methods">The methods.</param>
581-
/// <returns>The coverage quota.</returns>
582-
private static decimal? GetCoverageQuotaOfClass(XElement[] methods)
583-
{
584-
var methodGroups = methods
585-
.Where(m => m.Attribute("skippedDueTo") == null && m.Element("FileRef") == null && !m.Element("Name").Value.EndsWith(".ctor()", StringComparison.OrdinalIgnoreCase))
586-
.GroupBy(m => m.Element("Name").Value)
587-
.ToArray();
588-
589-
int visitedMethods = methodGroups.Count(g => g.Any(m => m.Attribute("visited").Value == "true"));
590-
591-
return (methodGroups.Length == 0) ? (decimal?)null : (decimal)Math.Truncate(1000 * (double)visitedMethods / (double)methodGroups.Length) / 10;
592-
}
593-
594574
private class FileElement
595575
{
596576
/// <summary>

src/ReportGenerator.Core/Reporting/Builders/Rendering/HtmlRenderer.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,7 @@ public void CustomSummary(IEnumerable<Assembly> assemblies, IEnumerable<RiskHots
609609
this.javaScriptContent.AppendFormat(" \"ucl\": {0},", (@class.CoverableLines - @class.CoveredLines).ToString(CultureInfo.InvariantCulture));
610610
this.javaScriptContent.AppendFormat(" \"cal\": {0},", @class.CoverableLines.ToString(CultureInfo.InvariantCulture));
611611
this.javaScriptContent.AppendFormat(" \"tl\": {0},", @class.TotalLines.GetValueOrDefault().ToString(CultureInfo.InvariantCulture));
612-
this.javaScriptContent.AppendFormat(" \"ct\": \"{0}\",", @class.CoverageType);
613-
this.javaScriptContent.AppendFormat(
614-
" \"cbm\": {0},",
615-
@class.CoverageType == CoverageType.MethodCoverage && @class.CoverageQuota.HasValue ? @class.CoverageQuota.Value.ToString(CultureInfo.InvariantCulture) : "\"-\"");
612+
616613
this.javaScriptContent.AppendFormat(" \"cb\": {0},", @class.CoveredBranches.GetValueOrDefault().ToString(CultureInfo.InvariantCulture));
617614
this.javaScriptContent.AppendFormat(" \"tb\": {0},", @class.TotalBranches.GetValueOrDefault().ToString(CultureInfo.InvariantCulture));
618615
this.javaScriptContent.AppendFormat(" \"cm\": {0},", methodCoverageAvailable ? @class.CoveredCodeElements.ToString(CultureInfo.InvariantCulture) : "0");
@@ -1237,7 +1234,7 @@ public void SummaryAssembly(Assembly assembly, bool branchCoverageAvailable, boo
12371234
this.reportTextWriter.Write("<th class=\"right\">{0}</th>", assembly.TotalLines.GetValueOrDefault());
12381235
this.reportTextWriter.Write(
12391236
"<th title=\"{0}\" class=\"right\">{1}</th>",
1240-
assembly.CoverageQuota.HasValue ? $"{CoverageType.LineCoverage}: {assembly.CoveredLines}/{assembly.CoverableLines}" : string.Empty,
1237+
assembly.CoverageQuota.HasValue ? $"{assembly.CoveredLines}/{assembly.CoverableLines}" : string.Empty,
12411238
assembly.CoverageQuota.HasValue ? assembly.CoverageQuota.Value.ToString(CultureInfo.InvariantCulture) + "%" : string.Empty);
12421239
this.reportTextWriter.Write("<th>{0}</th>", CreateCoverageTable(assembly.CoverageQuota));
12431240

@@ -1293,7 +1290,7 @@ public void SummaryClass(Class @class, bool branchCoverageAvailable, bool method
12931290
this.reportTextWriter.Write("<td class=\"right\">{0}</td>", @class.TotalLines.GetValueOrDefault());
12941291
this.reportTextWriter.Write(
12951292
"<td title=\"{0}\" class=\"right\">{1}</td>",
1296-
@class.CoverageQuota.HasValue ? $"{@class.CoverageType}: {@class.CoveredLines}/{@class.CoverableLines}" : @class.CoverageType.ToString(),
1293+
@class.CoverageQuota.HasValue ? $"{@class.CoveredLines}/{@class.CoverableLines}" : string.Empty,
12971294
@class.CoverageQuota.HasValue ? @class.CoverageQuota.Value.ToString(CultureInfo.InvariantCulture) + "%" : string.Empty);
12981295
this.reportTextWriter.Write("<td>{0}</td>", CreateCoverageTable(@class.CoverageQuota));
12991296

@@ -1685,7 +1682,7 @@ private Stream GetCombinedJavascript()
16851682
sb.AppendLine(",");
16861683
sb.AppendFormat("'method': '{0}'", WebUtility.HtmlEncode(ReportResources.Method));
16871684
sb.AppendLine(",");
1688-
sb.AppendFormat("'lineCoverage': '{0}'", CoverageType.LineCoverage.ToString());
1685+
sb.AppendFormat("'lineCoverage': '{0}'", WebUtility.HtmlEncode(ReportResources.Coverage));
16891686
sb.AppendLine(",");
16901687
sb.AppendFormat("'noGrouping': '{0}'", WebUtility.HtmlEncode(ReportResources.NoGrouping));
16911688
sb.AppendLine(",");

src/ReportGenerator.Core/Reporting/Builders/Rendering/resources/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)