Skip to content

Commit

Permalink
#536: Improved support for C code in Visual Studio coverage input for…
Browse files Browse the repository at this point in the history
…mat (*.coveragexml)
  • Loading branch information
danielpalme committed Feb 2, 2023
1 parent 77a9d09 commit 4527e0a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Readme.txt
Expand Up @@ -68,6 +68,7 @@ CHANGELOG

5.1.16.0

* Fix: #536: Improved support for C code in Visual Studio coverage input format (*.coveragexml)
* Fix: #585: Improved merging of results in SonarQube output format

5.1.15.0
Expand Down
Expand Up @@ -18,6 +18,7 @@ internal void Execute(XContainer report)
foreach (var module in report.Descendants("module").ToArray())
{
ApplyClassNameToStartupCodeElements(module);
AddMissingTypeNames(module);
}
}

Expand Down Expand Up @@ -116,5 +117,41 @@ private static void ApplyClassNameToStartupCodeElements(XElement module)
}
}
}

/// <summary>
/// Applies type names to funtions with empty 'type_name' attribute.
/// </summary>
/// <param name="module">The module.</param>
private static void AddMissingTypeNames(XElement module)
{
var functionsWithoutTypeNameInModule = module
.Elements("functions")
.Elements("function")
.Where(c => c.Attribute("type_name").Value == string.Empty)
.ToArray();

if (functionsWithoutTypeNameInModule.LongLength > 0)
{
var classNamesBySoureFileId = module
.Elements("source_files")
.Elements("source_file")
.ToDictionary(e => e.Attribute("id").Value, e =>
{
string path = e.Attribute("path").Value.Replace("/", "\\");
return path.Substring(path.LastIndexOf('\\') + 1);
});

foreach (var function in functionsWithoutTypeNameInModule)
{
string firstSourceId = function.Elements("ranges").Elements("range").FirstOrDefault()?.Attribute("source_id").Value;

if (firstSourceId != null && classNamesBySoureFileId.TryGetValue(firstSourceId, out string className))
{
function.Attribute("type_name").Value = className;
}
}
}
}
}
}
Expand Up @@ -762,7 +762,8 @@ public void MetricsTable(Class @class)
.SelectMany(f => f.MethodMetrics)
.SelectMany(m => m.Metrics)
.Distinct()
.OrderBy(m => m.Name);
.OrderBy(m => m.Name)
.ToArray();

this.reportTextWriter.WriteLine("<div class=\"table-responsive\">");
this.reportTextWriter.WriteLine("<table class=\"overview table-fixed\">");
Expand Down

0 comments on commit 4527e0a

Please sign in to comment.