Skip to content

Commit

Permalink
#690 Fixed handling of history files for classes with not unique names
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed Sep 13, 2024
1 parent 2a2ed5d commit 78a1a92
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ For further details take a look at LICENSE.txt.

CHANGELOG

5.3.10.0

* Fix: #690 Fixed handling of history files for classes with not unique names

5.3.9.0

* New: #685 Extended "raw mode" for dotCover format (settings:rawMode=true) to disable that coverage data of nested or compiler generated
Expand Down
19 changes: 18 additions & 1 deletion src/ReportGenerator.Core/Parser/Analysis/Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,20 @@ public class Class
/// <param name="name">The name of the class.</param>
/// <param name="assembly">The assembly.</param>
internal Class(string name, Assembly assembly)
: this(name, name, assembly)
{
}

Check warning on line 43 in src/ReportGenerator.Core/Parser/Analysis/Class.cs

View workflow job for this annotation

GitHub Actions / build


/// <summary>
/// Initializes a new instance of the <see cref="Class"/> class.
/// </summary>
/// <param name="name">The name of the class.</param>
/// <param name="assembly">The assembly.</param>
internal Class(string name, string rawName, Assembly assembly)

Check warning on line 50 in src/ReportGenerator.Core/Parser/Analysis/Class.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'rawName' has no matching param tag in the XML comment for 'Class.Class(string, string, Assembly)' (but other parameters do)
{
this.Name = name ?? throw new ArgumentNullException(nameof(name));
this.RawName = rawName ?? throw new ArgumentNullException(nameof(rawName));
this.Assembly = assembly ?? throw new ArgumentNullException(nameof(assembly));

this.DisplayName = name;
Expand Down Expand Up @@ -95,6 +107,11 @@ internal Class(string name, Assembly assembly)
/// </summary>
public string DisplayName { get; }

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

/// <summary>
/// Gets the assembly.
/// </summary>
Expand Down Expand Up @@ -214,7 +231,7 @@ public override bool Equals(object obj)
else
{
var @class = (Class)obj;
return @class.Name.Equals(this.Name) && @class.Assembly.Equals(this.Assembly);
return @class.RawName.Equals(this.RawName) && @class.Assembly.Equals(this.Assembly);
}
}

Expand Down
21 changes: 10 additions & 11 deletions src/ReportGenerator.Core/Parser/CoberturaParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private Assembly ProcessAssembly(XElement[] modules, string assemblyName)

var assembly = new Assembly(assemblyName);

Parallel.ForEach(classNames, c => this.ProcessClass(classes, assembly, c.Name, c.DisplayName));
Parallel.ForEach(classNames, c => this.ProcessClass(classes, assembly, c));

return assembly;
}
Expand All @@ -139,20 +139,19 @@ private Assembly ProcessAssembly(XElement[] modules, string assemblyName)
/// </summary>
/// <param name="allClasses">All class elements.</param>
/// <param name="assembly">The assembly.</param>
/// <param name="className">Name of the class.</param>
/// <param name="classDisplayName">Diesplay name of the class.</param>
private void ProcessClass(XElement[] allClasses, Assembly assembly, string className, string classDisplayName)
/// <param name="classNameParserResult">Name of the class.</param>
private void ProcessClass(XElement[] allClasses, Assembly assembly, ClassNameParserResult classNameParserResult)
{
bool FilterClass(XElement element)
{
var name = element.Attribute("name").Value;

return name.Equals(className)
return name.Equals(classNameParserResult.Name)
|| (!this.RawMode
&& name.StartsWith(className, StringComparison.Ordinal)
&& (name[className.Length] == '$'
|| name[className.Length] == '/'
|| name[className.Length] == '.'));
&& name.StartsWith(classNameParserResult.Name, StringComparison.Ordinal)
&& (name[classNameParserResult.Name.Length] == '$'
|| name[classNameParserResult.Name.Length] == '/'
|| name[classNameParserResult.Name.Length] == '.'));
}

var classes = allClasses
Expand All @@ -171,14 +170,14 @@ bool FilterClass(XElement element)
// If all files are removed by filters, then the whole class is omitted
if ((files.Length == 0 && !this.FileFilter.HasCustomFilters) || filteredFiles.Length > 0)
{
var @class = new Class(classDisplayName, assembly);
var @class = new Class(classNameParserResult.DisplayName, classNameParserResult.RawName, assembly);

foreach (var file in filteredFiles)
{
var fileClasses = classes
.Where(c => c.Attribute("filename").Value.Equals(file))
.ToArray();
@class.AddFile(this.ProcessFile(fileClasses, @class, className, file));
@class.AddFile(this.ProcessFile(fileClasses, @class, classNameParserResult.Name, file));
}

assembly.AddClass(@class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal void ApplyHistoricCoverage(IEnumerable<Assembly> assemblies, List<Histo

foreach (var item in assemblies.SelectMany(t => t.Classes))
{
classes[this.GetFullClassName(item.Assembly.Name, item.Name)] = item;
classes[this.GetFullClassName(item.Assembly.Name, item.RawName)] = item;
}

Parallel.ForEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal void CreateReport(IEnumerable<Assembly> assemblies, DateTime executionT
{
var classElement = new XElement(
"class",
new XAttribute("name", @class.Name),
new XAttribute("name", @class.RawName),
new XAttribute("coveredlines", @class.CoveredLines.ToString(CultureInfo.InvariantCulture)),
new XAttribute("coverablelines", @class.CoverableLines.ToString(CultureInfo.InvariantCulture)),
new XAttribute("totallines", @class.TotalLines.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)),
Expand Down

0 comments on commit 78a1a92

Please sign in to comment.