Skip to content

Commit

Permalink
#470: Improved support for Go coverage files
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed Dec 28, 2021
1 parent 162c7b1 commit fa1258c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ CHANGELOG

* Fix: #466: Cobertura: Full method name for code elements
* Fix: #467: Cobertura: Added support for reports generated by dotnet-coverage
* Fix: #470: Improved support for Go coverage files

5.0.0.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ public void BeginSummaryReport(string targetDirectory, string fileName, string t
/// Begins the class report.
/// </summary>
/// <param name="targetDirectory">The target directory.</param>
/// <param name="assemblyName">Name of the assembly.</param>
/// <param name="assembly">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 classDisplayName, string additionalTitle)
public void BeginClassReport(string targetDirectory, Assembly assembly, string className, string classDisplayName, string additionalTitle)
{
this.classReport = true;

string targetPath = this.GetClassReportFilename(assemblyName, className);
string targetPath = this.GetClassReportFilename(assembly, className);

Logger.DebugFormat(Resources.WritingReportFile, targetPath);
this.CreateTextWriter(Path.Combine(targetDirectory, targetPath));
Expand Down Expand Up @@ -485,7 +485,7 @@ public void CustomSummary(IEnumerable<Assembly> assemblies, IEnumerable<RiskHots
this.javaScriptContent.AppendFormat("\"name\": \"{0}\",", @class.DisplayName.Replace(@"\", @"\\"));
this.javaScriptContent.AppendFormat(
" \"rp\": \"{0}\",",
this.onlySummary ? string.Empty : this.GetClassReportFilename(@class.Assembly.ShortName, @class.Name));
this.onlySummary ? string.Empty : this.GetClassReportFilename(@class.Assembly, @class.Name));
this.javaScriptContent.AppendFormat(" \"cl\": {0},", @class.CoveredLines);
this.javaScriptContent.AppendFormat(" \"ucl\": {0},", @class.CoverableLines - @class.CoveredLines);
this.javaScriptContent.AppendFormat(" \"cal\": {0},", @class.CoverableLines);
Expand Down Expand Up @@ -557,7 +557,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.DisplayName);
this.javaScriptContent.AppendFormat(" \"reportPath\": \"{0}\",", this.onlySummary ? string.Empty : this.GetClassReportFilename(riskHotspot.Assembly.ShortName, riskHotspot.Class.Name));
this.javaScriptContent.AppendFormat(" \"reportPath\": \"{0}\",", this.onlySummary ? string.Empty : this.GetClassReportFilename(riskHotspot.Assembly, riskHotspot.Class.Name));
this.javaScriptContent.AppendFormat(" \"methodName\": \"{0}\",", riskHotspot.MethodMetric.FullName);
this.javaScriptContent.AppendFormat(" \"methodShortName\": \"{0}\",", riskHotspot.MethodMetric.ShortName);
this.javaScriptContent.AppendFormat(" \"fileIndex\": {0},", riskHotspot.FileIndex);
Expand Down Expand Up @@ -1012,7 +1012,7 @@ public void RiskHotspots(IEnumerable<RiskHotspot> riskHotspots)
filenameColumn = string.Format(
CultureInfo.InvariantCulture,
"<a href=\"{0}\">{1}</a>",
WebUtility.HtmlEncode(this.GetClassReportFilename(riskHotspot.Assembly.ShortName, riskHotspot.Class.Name)),
WebUtility.HtmlEncode(this.GetClassReportFilename(riskHotspot.Assembly, riskHotspot.Class.Name)),
WebUtility.HtmlEncode(riskHotspot.Class.DisplayName));
}

Expand All @@ -1025,7 +1025,7 @@ public void RiskHotspots(IEnumerable<RiskHotspot> riskHotspots)
this.reportTextWriter.Write(
"<td title=\"{0}\"><a href=\"{1}#file{2}_line{3}\">{4}</a></td>",
WebUtility.HtmlEncode(riskHotspot.MethodMetric.FullName),
WebUtility.HtmlEncode(this.GetClassReportFilename(riskHotspot.Assembly.ShortName, riskHotspot.Class.Name)),
WebUtility.HtmlEncode(this.GetClassReportFilename(riskHotspot.Assembly, riskHotspot.Class.Name)),
riskHotspot.FileIndex,
riskHotspot.MethodMetric.Line,
WebUtility.HtmlEncode(riskHotspot.MethodMetric.ShortName));
Expand Down Expand Up @@ -1107,7 +1107,7 @@ public void SummaryClass(Class @class, bool branchCoverageAvailable)
filenameColumn = string.Format(
CultureInfo.InvariantCulture,
"<a href=\"{0}\">{1}</a>",
WebUtility.HtmlEncode(this.GetClassReportFilename(@class.Assembly.ShortName, @class.Name)),
WebUtility.HtmlEncode(this.GetClassReportFilename(@class.Assembly, @class.Name)),
WebUtility.HtmlEncode(@class.DisplayName));
}

Expand Down Expand Up @@ -1292,12 +1292,14 @@ private static string GetTooltip(LineAnalysis analysis)
/// <summary>
/// Gets the file name of the report file for the given class.
/// </summary>
/// <param name="assemblyName">Name of the assembly.</param>
/// <param name="assembly">The assembly.</param>
/// <param name="className">Name of the class.</param>
/// <returns>The file name.</returns>
private string GetClassReportFilename(string assemblyName, string className)
private string GetClassReportFilename(Assembly assembly, string className)
{
string key = assemblyName + "_" + className;
string assemblyName = assembly.ShortName;

string key = assembly.Name + "_" + className;

string fileName = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public interface IReportRenderer
/// Begins the class report.
/// </summary>
/// <param name="targetDirectory">The target directory.</param>
/// <param name="assemblyName">Name of the assembly.</param>
/// <param name="assembly">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 classDisplayName, string additionalTitle);
void BeginClassReport(string targetDirectory, Assembly assembly, string className, string classDisplayName, string additionalTitle);

/// <summary>
/// Saves a summary report.
Expand Down Expand Up @@ -148,13 +148,13 @@ public interface IReportRenderer
void SummaryClass(Class @class, bool branchCoverageAvailable);

/// <summary>
/// Adds metrics to the report
/// Adds metrics to the report.
/// </summary>
/// <param name="class">The class.</param>
void MetricsTable(Class @class);

/// <summary>
/// Adds metrics to the report
/// Adds metrics to the report.
/// </summary>
/// <param name="methodMetrics">The method metrics.</param>
void MetricsTable(IEnumerable<MethodMetric> methodMetrics);
Expand All @@ -175,7 +175,7 @@ public interface IReportRenderer
/// Renderes a chart with the given historic coverages.
/// </summary>
/// <param name="historicCoverages">The historic coverages.</param>
/// <param name="renderPngFallBackImage">Indicates whether PNG images are rendered as a fallback</param>
/// <param name="renderPngFallBackImage">Indicates whether PNG images are rendered as a fallback.</param>
void Chart(IEnumerable<HistoricCoverage> historicCoverages, bool renderPngFallBackImage);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ public void BeginSummaryReport(string targetDirectory, string fileName, string t
/// Begins the class report.
/// </summary>
/// <param name="targetDirectory">The target directory.</param>
/// <param name="assemblyName">Name of the assembly.</param>
/// <param name="assembly">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 classDisplayName, string additionalTitle)
public void BeginClassReport(string targetDirectory, Assembly assembly, string className, string classDisplayName, string additionalTitle)
{
if (this.classReportTextWriter == null)
{
Expand Down
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, @class.DisplayName, additionalTitle);
reportRenderer.BeginClassReport(this.CreateTargetDirectory(), @class.Assembly, @class.Name, @class.DisplayName, additionalTitle);

if (this.ReportContext.ReportConfiguration.Title != null)
{
Expand Down

0 comments on commit fa1258c

Please sign in to comment.