Skip to content

Commit

Permalink
#285: Added lcov output format
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed Sep 29, 2019
1 parent 779c840 commit 355f1a5
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Explanations:
Report types: The output formats and scope (separated by semicolon).
Values: Badges, Cobertura, CsvSummary, Html, HtmlChart, HtmlInline,
HtmlInline_AzurePipelines, HtmlInline_AzurePipelines_Dark, HtmlSummary, Latex,
LatexSummary, MHtml, PngChart, SonarQube, TeamCitySummary, TextSummary, Xml, XmlSummary
LatexSummary, lcov, MHtml, PngChart, SonarQube, TeamCitySummary, TextSummary, Xml, XmlSummary
Source directories: Optional directories which contain the corresponding source code (separated by semicolon).
The source directories are used if coverage report contains classes without path information.
History directory: Optional directory for storing persistent coverage information.
Expand Down Expand Up @@ -118,7 +118,7 @@ If you need a custom format, you can create a [plugin](https://github.com/daniel

| **Input formats** | **Output formats** |
|:------------------|:-------------------|
| <ul><li>[OpenCover](https://github.com/OpenCover/opencover) ([Nuget](https://www.nuget.org/packages/OpenCover))<br/>OpenCover format is also generated by [coverlet](https://github.com/tonerdo/coverlet/) and [altcover](https://github.com/SteveGilham/altcover)</li><li>[dotCover](https://www.jetbrains.com/dotcover/help/dotCover__Console_Runner_Commands.html) ([Nuget](https://www.nuget.org/packages/JetBrains.dotCover.CommandLineTools/), /ReportType=DetailedXML)</li><li>Visual Studio ([vstest.console.exe](https://github.com/danielpalme/ReportGenerator/wiki/Visual-Studio-Coverage-Tools#vstestconsoleexe), [CodeCoverage.exe](https://github.com/danielpalme/ReportGenerator/wiki/Visual-Studio-Coverage-Tools#codecoverageexe))</li><li>[NCover](https://www.ncover.com/info/download) (tested version 1.5.8, other versions may not work)</li><li>[Cobertura](https://github.com/cobertura/cobertura)</li><li>[JaCoCo](https://www.jacoco.org/jacoco/index.html)</li><li>[Clover](https://openclover.org/)</li><li>Mono ([mprof-report](https://www.mono-project.com/docs/debug+profile/profile/profiler/#analyzing-the-profile-data))</li><li>[gcov](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html)</li><li>[lcov](https://github.com/linux-test-project/lcov)</li></ul> | <ul><li>HTML, HTMLSummary, HTMLInline, HtmlInline_AzurePipelines, HtmlInline_AzurePipelines_Dark, HTMLChart, [MHTML](https://en.wikipedia.org/wiki/MHTML)</li><li>Cobertura</li><li>[SonarQube](https://docs.sonarqube.org/latest/analysis/generic-test)</li><li>XML, XMLSummary</li><li>Latex, LatexSummary</li><li>TextSummary</li><li>CsvSummary</li><li>PngChart</li><li>Badges</li><li>[Custom reports](https://github.com/danielpalme/ReportGenerator/wiki/Custom-reports)</li></ul><br /><br /> |
| <ul><li>[OpenCover](https://github.com/OpenCover/opencover) ([Nuget](https://www.nuget.org/packages/OpenCover))<br/>OpenCover format is also generated by [coverlet](https://github.com/tonerdo/coverlet/) and [altcover](https://github.com/SteveGilham/altcover)</li><li>[dotCover](https://www.jetbrains.com/dotcover/help/dotCover__Console_Runner_Commands.html) ([Nuget](https://www.nuget.org/packages/JetBrains.dotCover.CommandLineTools/), /ReportType=DetailedXML)</li><li>Visual Studio ([vstest.console.exe](https://github.com/danielpalme/ReportGenerator/wiki/Visual-Studio-Coverage-Tools#vstestconsoleexe), [CodeCoverage.exe](https://github.com/danielpalme/ReportGenerator/wiki/Visual-Studio-Coverage-Tools#codecoverageexe))</li><li>[NCover](https://www.ncover.com/info/download) (tested version 1.5.8, other versions may not work)</li><li>[Cobertura](https://github.com/cobertura/cobertura)</li><li>[JaCoCo](https://www.jacoco.org/jacoco/index.html)</li><li>[Clover](https://openclover.org/)</li><li>Mono ([mprof-report](https://www.mono-project.com/docs/debug+profile/profile/profiler/#analyzing-the-profile-data))</li><li>[gcov](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html)</li><li>[lcov](https://github.com/linux-test-project/lcov)</li></ul> | <ul><li>HTML, HTMLSummary, HTMLInline, HtmlInline_AzurePipelines, HtmlInline_AzurePipelines_Dark, HTMLChart, [MHTML](https://en.wikipedia.org/wiki/MHTML)</li><li>Cobertura</li><li>[SonarQube](https://docs.sonarqube.org/latest/analysis/generic-test)</li><li>[lcov](https://github.com/linux-test-project/lcov)</li><li>XML, XMLSummary</li><li>Latex, LatexSummary</li><li>TextSummary</li><li>CsvSummary</li><li>PngChart</li><li>Badges</li><li>[Custom reports](https://github.com/danielpalme/ReportGenerator/wiki/Custom-reports)</li></ul><br /> |

### Screenshots
The screenshots show two snippets of the generated reports:
Expand Down
Binary file modified docs/resources/SampleReports.zip
Binary file not shown.
2 changes: 2 additions & 0 deletions src/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The following output formats are supported by ReportGenerator:
-HTML, HTMLSummary, HTMLInline, HtmlInline_AzurePipelines, HtmlInline_AzurePipelines_Dark, HTMLChart, MHTML
-Cobertura
-SonarQube
-lcov
-XML, XMLSummary
-Latex, LatexSummary
-TeamCitySummary
Expand Down Expand Up @@ -64,6 +65,7 @@ CHANGELOG

* New: Issue #205: Support for .NET Core 3.0
* New: Issue #262: Performance improvements
* New: Issue #285: Added lcov output format
* Fix: Issue #283: Improved logging of coverage report paths
* Fix: Issue #284: Fixed layout issue in Google Chrome
* Fix: Improved merging of partially covered lines
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using Palmmedia.ReportGenerator.Core.Logging;
using Palmmedia.ReportGenerator.Core.Parser.Analysis;
using Palmmedia.ReportGenerator.Core.Properties;

namespace Palmmedia.ReportGenerator.Core.Reporting.Builders
{
/// <summary>
/// Creates summary report in lcov (See: https://github.com/linux-test-project/lcov, http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php) (no reports for classes are generated).
/// </summary>
public class LCovSummaryReportBuilder : IReportBuilder
{
/// <summary>
/// The Logger.
/// </summary>
private static readonly ILogger Logger = LoggerFactory.GetLogger(typeof(LCovSummaryReportBuilder));

/// <summary>
/// Gets the report type.
/// </summary>
/// <value>
/// The report type.
/// </value>
public string ReportType => "lcov";

/// <summary>
/// Gets or sets the report context.
/// </summary>
/// <value>
/// The report context.
/// </value>
public IReportContext ReportContext { get; set; }

/// <summary>
/// Creates a class report.
/// </summary>
/// <param name="class">The class.</param>
/// <param name="fileAnalyses">The file analyses that correspond to the class.</param>
public void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalyses)
{
}

/// <summary>
/// Creates the summary report.
/// </summary>
/// <param name="summaryResult">The summary result.</param>
public void CreateSummaryReport(SummaryResult summaryResult)
{
if (summaryResult == null)
{
throw new ArgumentNullException(nameof(summaryResult));
}

string targetPath = Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "lcov.info");

Logger.InfoFormat(" " + Resources.WritingReportFile, targetPath);

using (var reportTextWriter = new StreamWriter(new FileStream(targetPath, FileMode.Create), Encoding.UTF8))
{
reportTextWriter.WriteLine("TN:");

foreach (var assembly in summaryResult.Assemblies)
{
foreach (var @class in assembly.Classes)
{
foreach (var file in @class.Files)
{
reportTextWriter.WriteLine($"SF:{file.Path}");

foreach (var codeElement in file.CodeElements)
{
reportTextWriter.WriteLine($"FN:{codeElement.FirstLine.ToString(CultureInfo.InvariantCulture)},{codeElement.Name}");
}

int coveredLines = 0;
int instrumentedLines = 0;

for (int i = 1; i < file.LineCoverage.Count; i++)
{
int coverage = file.LineCoverage[i];

if (coverage >= 0)
{
reportTextWriter.WriteLine($"DA:{i.ToString(CultureInfo.InvariantCulture)},{coverage.ToString(CultureInfo.InvariantCulture)}");

instrumentedLines++;

if (coverage > 0)
{
coveredLines++;
}
}
}

// LF:<number of instrumented lines>
reportTextWriter.WriteLine($"LF:{instrumentedLines.ToString(CultureInfo.InvariantCulture)}");

// LH:<number of lines with a non-zero execution count>
reportTextWriter.WriteLine($"LH:{coveredLines.ToString(CultureInfo.InvariantCulture)}");

reportTextWriter.WriteLine("end_of_record");
}
}
}

reportTextWriter.Flush();
}
}
}
}

0 comments on commit 355f1a5

Please sign in to comment.