Skip to content

Commit

Permalink
#408: Fixed coverage of generic classes
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed Mar 4, 2021
1 parent 3b4fc59 commit 0bc6d22
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 47 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ variables:
- name: disable.coverage.autogenerate
value: 'true'
- name: version
value: '4.8.6'
value: '4.8.7'

stages:
- stage: Build
Expand Down
2 changes: 1 addition & 1 deletion src/AzureDevopsTask/ReportGenerator/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 4,
"Minor": 8,
"Patch": 6
"Patch": 7
},
"instanceNameFormat": "ReportGenerator",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion src/AzureDevopsTask/vss-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifestVersion": 1,
"id": "reportgenerator",
"name": "ReportGenerator",
"version": "4.8.6",
"version": "4.8.7",
"publisher": "Palmmedia",
"public": true,
"targets": [
Expand Down
4 changes: 4 additions & 0 deletions src/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ For further details take a look at LICENSE.txt.

CHANGELOG

4.8.7.0

* Fix: #408: Fixed coverage of generic classes

4.8.6.0

* New: #405: Added support for deterministic source paths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<AssemblyName>ReportGenerator</AssemblyName>
<RootNamespace>Palmmedia.ReportGenerator</RootNamespace>
<StartupObject>Palmmedia.ReportGenerator.Console.NetCore.Program</StartupObject>
<AssemblyVersion>4.8.6.0</AssemblyVersion>
<FileVersion>4.8.6.0</FileVersion>
<AssemblyVersion>4.8.7.0</AssemblyVersion>
<FileVersion>4.8.7.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/ReportGenerator.Console/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.8.6.0")]
[assembly: AssemblyFileVersion("4.8.6.0")]
[assembly: AssemblyVersion("4.8.7.0")]
[assembly: AssemblyFileVersion("4.8.7.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.8.0" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.9.0" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
10 changes: 5 additions & 5 deletions src/ReportGenerator.Core.Test/ReportGenerator.Core.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
<RootNamespace>Palmmedia.ReportGenerator.Core.Test</RootNamespace>
<AssemblyVersion>4.8.6.0</AssemblyVersion>
<FileVersion>4.8.6.0</FileVersion>
<AssemblyVersion>4.8.7.0</AssemblyVersion>
<FileVersion>4.8.7.0</FileVersion>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="3.0.2">
<PackageReference Include="coverlet.msbuild" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.0-preview-20201020-06" />
<PackageReference Include="Moq" Version="4.16.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
Expand Down
19 changes: 13 additions & 6 deletions src/ReportGenerator.Core/Parser/Analysis/Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ internal Class(string name, Assembly assembly)
this.Name = name ?? throw new ArgumentNullException(nameof(name));
this.Assembly = assembly ?? throw new ArgumentNullException(nameof(assembly));

this.DisplayName = name;

/*
* Convert class name of generic classes:
* See: https://github.com/coverlet-coverage/coverlet/issues/1077
Expand All @@ -59,29 +61,29 @@ internal Class(string name, Assembly assembly)

if (match.Success)
{
this.Name = match.Groups["Name"].Value;
this.DisplayName = match.Groups["Name"].Value;

int number = int.Parse(match.Groups["Number"].Value);

if (number == 1)
{
this.Name += "<T>";
this.DisplayName += "<T>";
}
else if (number > 1)
{
this.Name += "<";
this.DisplayName += "<";

for (int i = 1; i <= number; i++)
{
if (i > 1)
{
this.Name += ", ";
this.DisplayName += ", ";
}

this.Name += "T" + i;
this.DisplayName += "T" + i;
}

this.Name += ">";
this.DisplayName += ">";
}
}
}
Expand All @@ -92,6 +94,11 @@ internal Class(string name, Assembly assembly)
/// </summary>
public string Name { get; }

/// <summary>
/// Gets the display name of the class.
/// </summary>
public string DisplayName { get; }

/// <summary>
/// Gets the assembly.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/ReportGenerator.Core/ReportGenerator.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AssemblyName>ReportGenerator.Core</AssemblyName>
<AssemblyVersion>4.8.6.0</AssemblyVersion>
<FileVersion>4.8.6.0</FileVersion>
<AssemblyVersion>4.8.7.0</AssemblyVersion>
<FileVersion>4.8.7.0</FileVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ public void BeginSummaryReport(string targetDirectory, string fileName, string t
/// <param name="targetDirectory">The target directory.</param>
/// <param name="assemblyName">Name of the assembly.</param>
/// <param name="className">Name of the class.</param>
/// <param name="classDisplayName">Display name of the class.</param>
/// <param name="additionalTitle">Additional title.</param>
public void BeginClassReport(string targetDirectory, string assemblyName, string className, string additionalTitle)
public void BeginClassReport(string targetDirectory, string assemblyName, string className, string classDisplayName, string additionalTitle)
{
this.classReport = true;

Expand All @@ -171,7 +172,7 @@ public void BeginClassReport(string targetDirectory, string assemblyName, string
"<style type=\"text/css\">" + new StreamReader(cssStream).ReadToEnd() + "</style>"
: CssLink;

this.reportTextWriter.WriteLine(HtmlStart, WebUtility.HtmlEncode(className), WebUtility.HtmlEncode(additionalTitle + ReportResources.CoverageReport), style);
this.reportTextWriter.WriteLine(HtmlStart, WebUtility.HtmlEncode(classDisplayName), WebUtility.HtmlEncode(additionalTitle + ReportResources.CoverageReport), style);
}
}

Expand Down Expand Up @@ -480,7 +481,7 @@ public void CustomSummary(IEnumerable<Assembly> assemblies, IEnumerable<RiskHots
historicCoveragesSb.Append("]");

this.javaScriptContent.Append(" { ");
this.javaScriptContent.AppendFormat("\"name\": \"{0}\",", @class.Name.Replace(@"\", @"\\"));
this.javaScriptContent.AppendFormat("\"name\": \"{0}\",", @class.DisplayName.Replace(@"\", @"\\"));
this.javaScriptContent.AppendFormat(
" \"rp\": \"{0}\",",
this.onlySummary ? string.Empty : this.GetClassReportFilename(@class.Assembly.ShortName, @class.Name));
Expand Down Expand Up @@ -554,7 +555,7 @@ public void CustomSummary(IEnumerable<Assembly> assemblies, IEnumerable<RiskHots
{
this.javaScriptContent.AppendLine(" {");
this.javaScriptContent.AppendFormat(" \"assembly\": \"{0}\",", riskHotspot.Assembly.ShortName);
this.javaScriptContent.AppendFormat(" \"class\": \"{0}\",", riskHotspot.Class.Name);
this.javaScriptContent.AppendFormat(" \"class\": \"{0}\",", riskHotspot.Class.DisplayName);
this.javaScriptContent.AppendFormat(" \"reportPath\": \"{0}\",", this.onlySummary ? string.Empty : this.GetClassReportFilename(riskHotspot.Assembly.ShortName, riskHotspot.Class.Name));
this.javaScriptContent.AppendFormat(" \"methodName\": \"{0}\",", riskHotspot.MethodMetric.FullName);
this.javaScriptContent.AppendFormat(" \"methodShortName\": \"{0}\",", riskHotspot.MethodMetric.ShortName);
Expand Down Expand Up @@ -1005,7 +1006,7 @@ public void RiskHotspots(IEnumerable<RiskHotspot> riskHotspots)
CultureInfo.InvariantCulture,
"<a href=\"{0}\">{1}</a>",
WebUtility.HtmlEncode(this.GetClassReportFilename(riskHotspot.Assembly.ShortName, riskHotspot.Class.Name)),
WebUtility.HtmlEncode(riskHotspot.Class.Name));
WebUtility.HtmlEncode(riskHotspot.Class.DisplayName));
}

this.reportTextWriter.WriteLine("<tr>");
Expand Down Expand Up @@ -1100,7 +1101,7 @@ public void SummaryClass(Class @class, bool branchCoverageAvailable)
CultureInfo.InvariantCulture,
"<a href=\"{0}\">{1}</a>",
WebUtility.HtmlEncode(this.GetClassReportFilename(@class.Assembly.ShortName, @class.Name)),
WebUtility.HtmlEncode(@class.Name));
WebUtility.HtmlEncode(@class.DisplayName));
}

this.reportTextWriter.Write("<tr>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public interface IReportRenderer
/// <param name="targetDirectory">The target directory.</param>
/// <param name="assemblyName">Name of the assembly.</param>
/// <param name="className">Name of the class.</param>
/// <param name="classDisplayName">Display name of the class.</param>
/// <param name="additionalTitle">Additional title.</param>
void BeginClassReport(string targetDirectory, string assemblyName, string className, string additionalTitle);
void BeginClassReport(string targetDirectory, string assemblyName, string className, string classDisplayName, string additionalTitle);

/// <summary>
/// Saves a summary report.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ public void BeginSummaryReport(string targetDirectory, string fileName, string t
/// <param name="targetDirectory">The target directory.</param>
/// <param name="assemblyName">Name of the assembly.</param>
/// <param name="className">Name of the class.</param>
/// <param name="classDisplayName">Display name of the class.</param>
/// <param name="additionalTitle">Additional title.</param>
public void BeginClassReport(string targetDirectory, string assemblyName, string className, string additionalTitle)
public void BeginClassReport(string targetDirectory, string assemblyName, string className, string classDisplayName, string additionalTitle)
{
if (this.classReportTextWriter == null)
{
Expand All @@ -136,8 +137,8 @@ public void BeginClassReport(string targetDirectory, string assemblyName, string
this.reportTextWriter = this.classReportTextWriter;
this.reportTextWriter.WriteLine(@"\newpage");

className = string.Format(CultureInfo.InvariantCulture, @"\section{{{0}}}", EscapeLatexChars(className));
this.reportTextWriter.WriteLine(className);
classDisplayName = string.Format(CultureInfo.InvariantCulture, @"\section{{{0}}}", EscapeLatexChars(classDisplayName));
this.reportTextWriter.WriteLine(classDisplayName);
}

/// <summary>
Expand Down Expand Up @@ -537,7 +538,7 @@ public void RiskHotspots(IEnumerable<RiskHotspot> riskHotspots)
this.reportTextWriter.Write(
"{0} & {1} & {2}",
EscapeLatexChars(riskHotspot.Assembly.ShortName),
EscapeLatexChars(riskHotspot.Class.Name),
EscapeLatexChars(riskHotspot.Class.DisplayName),
EscapeLatexChars(riskHotspot.MethodMetric.ShortName));

foreach (var statusMetric in riskHotspot.StatusMetrics)
Expand Down Expand Up @@ -612,7 +613,7 @@ public void SummaryClass(Class @class, bool branchCoverageAvailable)
string row = string.Format(
CultureInfo.InvariantCulture,
@"{0} & {1} & {2} & {3} & {4} & {5}",
EscapeLatexChars(@class.Name),
EscapeLatexChars(@class.DisplayName),
@class.CoveredLines,
@class.CoverableLines - @class.CoveredLines,
@class.CoverableLines,
Expand Down Expand Up @@ -765,6 +766,8 @@ private static string ShortenString(string text, int maxLength)
.Replace(@"\", @"\textbackslash ")
.Replace("%", @"\%")
.Replace("#", @"\#")
.Replace("_", @"\_");
.Replace("_", @"\_")
.Replace("<", "$<$")
.Replace(">", "$>$");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public virtual void CreateClassReport(IReportRenderer reportRenderer, Class @cla

string additionalTitle = this.ReportContext.ReportConfiguration.Title != null ? $"{this.ReportContext.ReportConfiguration.Title} - " : null;

reportRenderer.BeginClassReport(this.CreateTargetDirectory(), @class.Assembly.ShortName, @class.Name, additionalTitle);
reportRenderer.BeginClassReport(this.CreateTargetDirectory(), @class.Assembly.ShortName, @class.Name, @class.DisplayName, additionalTitle);

if (this.ReportContext.ReportConfiguration.Title != null)
{
Expand All @@ -74,7 +74,7 @@ public virtual void CreateClassReport(IReportRenderer reportRenderer, Class @cla
}

reportRenderer.BeginKeyValueTable();
reportRenderer.KeyValueRow(ReportResources.Class, @class.Name);
reportRenderer.KeyValueRow(ReportResources.Class, @class.DisplayName);
reportRenderer.KeyValueRow(ReportResources.Assembly, @class.Assembly.ShortName);
reportRenderer.KeyValueRow(ReportResources.Files3, @class.Files.Select(f => f.Path));
reportRenderer.KeyValueRow(ReportResources.CoveredLines, @class.CoveredLines.ToString(CultureInfo.InvariantCulture));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)
if (summaryResult.Assemblies.Any())
{
var maximumNameLength = summaryResult.Assemblies
.SelectMany(a => a.Classes).Select(c => c.Name)
.SelectMany(a => a.Classes).Select(c => c.DisplayName)
.Union(summaryResult.Assemblies.Select(a => a.Name))
.Max(n => n.Length);

Expand All @@ -117,8 +117,8 @@ public void CreateSummaryReport(SummaryResult summaryResult)
string classQuota = @class.CoverageQuota.HasValue ? @class.CoverageQuota.Value.ToString("f1", CultureInfo.InvariantCulture) + "%" : string.Empty;
reportTextWriter.WriteLine(
" {0}{1} {2}",
@class.Name,
new string(' ', maximumNameLength - @class.Name.Length + 6 - classQuota.Length),
@class.DisplayName,
new string(' ', maximumNameLength - @class.DisplayName.Length + 6 - classQuota.Length),
classQuota);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net5.0</TargetFrameworks>
<RootNamespace>ReportGenerator.DotnetCorePluginLoader</RootNamespace>
<AssemblyVersion>4.8.6.0</AssemblyVersion>
<FileVersion>4.8.6.0</FileVersion>
<AssemblyVersion>4.8.7.0</AssemblyVersion>
<FileVersion>4.8.7.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<AssemblyName>ReportGenerator</AssemblyName>
<RootNamespace>Palmmedia.ReportGenerator</RootNamespace>
<StartupObject>Palmmedia.ReportGenerator.DotnetGlobalTool.Program</StartupObject>
<AssemblyVersion>4.8.6.0</AssemblyVersion>
<FileVersion>4.8.6.0</FileVersion>
<AssemblyVersion>4.8.7.0</AssemblyVersion>
<FileVersion>4.8.7.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/ReportGenerator.MSBuild/ReportGenerator.MSBuild.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<RootNamespace>Palmmedia.ReportGenerator.MSBuild</RootNamespace>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AssemblyVersion>4.8.6.0</AssemblyVersion>
<FileVersion>4.8.6.0</FileVersion>
<AssemblyVersion>4.8.7.0</AssemblyVersion>
<FileVersion>4.8.7.0</FileVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.8.0" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.9.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<!-- Version, adjust before build -->
<PropertyGroup>
<Version>4.8.6</Version>
<Version>4.8.7</Version>
</PropertyGroup>

<!-- Tools -->
Expand Down

0 comments on commit 0bc6d22

Please sign in to comment.