Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with handling of multiple assemblies with the same name #426

Merged
merged 1 commit into from Jun 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ReportGenerator.Core/Parser/DynamicCodeCoverageParser.cs
Expand Up @@ -83,7 +83,7 @@ public ParserResult Parse(XContainer report)
/// <returns>The <see cref="Assembly"/>.</returns>
private Assembly ProcessAssembly(XElement module)
{
string assemblyName = module.Attribute("name").Value;
string assemblyName = module.Attribute("name").Value + "_" + module.Attribute("id").Value;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will prevent the tool from mixing code coverage data from different versions of the same module (same name) together (when those coverage data exists in the same coverage file). E.g. x86 and x64 version of the same DLL.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you generating the XML file by hand? I.e. are you manually copying the relevant section from the x86 coverage file to the x64 file or vice versa?
If yes: How about renaming the modules to "???_x86" and "???_x64" if you want separate results? The id looks "ugly" in the report.
In generell users would expect that modules with the same name are handled as a single module. I'm not willing to change that behavior, because users rely on it. Often ReportGenerator is used to merge several coverage files.
You are the first user that does not want to merge the results :-)


Logger.DebugFormat(Resources.CurrentAssembly, assemblyName);

Expand Down Expand Up @@ -187,7 +187,9 @@ private static CodeFile ProcessFile(XElement module, string fileId, ClassWithNam
var linesOfFile = methods
.Elements("ranges")
.Elements("range")
.Where(r => r.Attribute("source_id").Value == fileId)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevent the tool from applying the same coverage for different files invoked in the method being processed. It should only apply the associated coverage for the file.

.Where(l => l.Attribute("start_line").Value != "15732480")
.Distinct()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Distinct() make any difference here? You apply Distinct() to a list of XElement objects, this will always return the full list of elements. I guess you can remove that line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove it.

.Select(l => new
{
LineNumberStart = int.Parse(l.Attribute("start_line").Value, CultureInfo.InvariantCulture),
Expand Down
Expand Up @@ -299,7 +299,7 @@ public void TestMethods(IEnumerable<TestMethod> testMethods, IEnumerable<FileAna
codeElement.FirstLine,
codeElement.CoverageQuota.HasValue ? coverageRounded.ToString() : "undefined",
codeElement.CoverageQuota.HasValue ? ReportResources.Coverage2 + " " + codeElement.CoverageQuota.Value.ToString(CultureInfo.InvariantCulture) + "% - " : string.Empty,
WebUtility.HtmlEncode(codeElement.Name),
WebUtility.HtmlEncode($"File {item.Key} => " + codeElement.Name),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add file index before the method name, so that we know which file is associated with this method instance. This is to handle the scenario that multiple files may be invoke for the same method, and there are multiple method instances listed on the class coverage page.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, but in the sidebar the horizontal space is limited. I would prefer to show the file index only in the tooltip.

codeElement.CodeElementType == CodeElementType.Method ? "cube" : "wrench");
}
}
Expand Down Expand Up @@ -626,7 +626,8 @@ public void KeyValueRow(string key, string value)
/// <param name="files">The files.</param>
public void KeyValueRow(string key, IEnumerable<string> files)
{
string value = string.Join("<br />", files.Select(v => string.Format(CultureInfo.InvariantCulture, "<a href=\"#{0}\" class=\"navigatetohash\">{1}</a>", WebUtility.HtmlEncode(StringHelper.ReplaceNonLetterChars(v)), WebUtility.HtmlEncode(v))));
int fileIndex = 0;
string value = string.Join("<br />", files.Select(v => string.Format(CultureInfo.InvariantCulture, "<a href=\"#{0}\" class=\"navigatetohash\">{1}</a>", WebUtility.HtmlEncode(StringHelper.ReplaceNonLetterChars(v)), WebUtility.HtmlEncode($"File {fileIndex++}: " + v))));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assign a file index to each file to shown on the class coverage page. So that we can reference to this file index in those method instances - when there are multiple instances of the same method listed on that page.


this.reportTextWriter.WriteLine(
"<tr><th>{0}</th><td>{1}</td></tr>",
Expand Down Expand Up @@ -686,11 +687,11 @@ public void MetricsTable(Class @class)
WebUtility.HtmlEncode(methodMetric.FullName),
fileIndex,
methodMetric.Line,
WebUtility.HtmlEncode(methodMetric.ShortName));
WebUtility.HtmlEncode($"File {fileIndex} => " + methodMetric.ShortName));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add file index before the method name, so that we know which file is associated with this method instance. This is to handle the scenario that multiple files may be invoke for the same method, and there are multiple method instances listed on the class coverage page.

}
else
{
this.reportTextWriter.Write("<td title=\"{0}\">{1}</td>", WebUtility.HtmlEncode(methodMetric.FullName), WebUtility.HtmlEncode(methodMetric.ShortName));
this.reportTextWriter.Write("<td title=\"{0}\">{1}</td>", WebUtility.HtmlEncode(methodMetric.FullName), WebUtility.HtmlEncode(file.Path + " => " + methodMetric.ShortName));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add file index before the method name, so that we know which file is associated with this method instance. This is to handle the scenario that multiple files may be invoke for the same method, and there are multiple method instances listed on the class coverage page.

}

foreach (var metric in metrics)
Expand Down