Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/coverlet.core/Reporters/OpenCoverReporter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -76,8 +77,8 @@ public string Report(CoverageResult result)

method.Add(new XAttribute("cyclomaticComplexity", methCyclomaticComplexity.ToString()));
method.Add(new XAttribute("nPathComplexity", "0"));
method.Add(new XAttribute("sequenceCoverage", methLineCoverage.Percent.ToString()));
method.Add(new XAttribute("branchCoverage", methBranchCoverage.Percent.ToString()));
method.Add(new XAttribute("sequenceCoverage", Math.Round(methLineCoverage.Percent * 100, 2).ToString("G", CultureInfo.InvariantCulture)));
method.Add(new XAttribute("branchCoverage", Math.Round(methBranchCoverage.Percent * 100, 2).ToString("G", CultureInfo.InvariantCulture)));
method.Add(new XAttribute("isConstructor", meth.Key.Contains("ctor").ToString()));
method.Add(new XAttribute("isGetter", meth.Key.Contains("get_").ToString()));
method.Add(new XAttribute("isSetter", meth.Key.Contains("set_").ToString()));
Expand Down Expand Up @@ -157,8 +158,8 @@ public string Report(CoverageResult result)
methodSummary.Add(new XAttribute("visitedSequencePoints", methLineCoverage.Covered.ToString()));
methodSummary.Add(new XAttribute("numBranchPoints", methBranchCoverage.Total.ToString()));
methodSummary.Add(new XAttribute("visitedBranchPoints", methBranchCoverage.Covered.ToString()));
methodSummary.Add(new XAttribute("sequenceCoverage", methLineCoverage.Percent.ToString()));
methodSummary.Add(new XAttribute("branchCoverage", methBranchCoverage.Percent.ToString()));
methodSummary.Add(new XAttribute("sequenceCoverage", Math.Round(methLineCoverage.Percent * 100, 2).ToString("G", CultureInfo.InvariantCulture)));
methodSummary.Add(new XAttribute("branchCoverage", Math.Round(methBranchCoverage.Percent * 100, 2).ToString("G", CultureInfo.InvariantCulture)));
methodSummary.Add(new XAttribute("maxCyclomaticComplexity", methCyclomaticComplexity.ToString()));
methodSummary.Add(new XAttribute("minCyclomaticComplexity", methCyclomaticComplexity.ToString()));
methodSummary.Add(new XAttribute("visitedClasses", "0"));
Expand Down Expand Up @@ -191,8 +192,8 @@ public string Report(CoverageResult result)
classSummary.Add(new XAttribute("visitedSequencePoints", classLineCoverage.Covered.ToString()));
classSummary.Add(new XAttribute("numBranchPoints", classBranchCoverage.Total.ToString()));
classSummary.Add(new XAttribute("visitedBranchPoints", classBranchCoverage.Covered.ToString()));
classSummary.Add(new XAttribute("sequenceCoverage", classLineCoverage.Percent.ToString()));
classSummary.Add(new XAttribute("branchCoverage", classBranchCoverage.Percent.ToString()));
classSummary.Add(new XAttribute("sequenceCoverage", Math.Round(classLineCoverage.Percent * 100, 2).ToString("G", CultureInfo.InvariantCulture)));
classSummary.Add(new XAttribute("branchCoverage", Math.Round(classBranchCoverage.Percent * 100, 2).ToString("G", CultureInfo.InvariantCulture)));
classSummary.Add(new XAttribute("maxCyclomaticComplexity", classMaxCyclomaticComplexity.ToString()));
classSummary.Add(new XAttribute("minCyclomaticComplexity", classMinCyclomaticComplexity.ToString()));
classSummary.Add(new XAttribute("visitedClasses", classVisited ? "1" : "0"));
Expand All @@ -214,16 +215,16 @@ public string Report(CoverageResult result)
}

var moduleLineCoverage = summary.CalculateLineCoverage(result.Modules);
var moduleBranchCoverage = summary.CalculateLineCoverage(result.Modules);
var moduleBranchCoverage = summary.CalculateBranchCoverage(result.Modules);
var moduleMaxCyclomaticComplexity = summary.CalculateMaxCyclomaticComplexity(result.Modules);
var moduleMinCyclomaticComplexity = summary.CalculateMinCyclomaticComplexity(result.Modules);

coverageSummary.Add(new XAttribute("numSequencePoints", moduleLineCoverage.Total.ToString()));
coverageSummary.Add(new XAttribute("visitedSequencePoints", moduleLineCoverage.Covered.ToString()));
coverageSummary.Add(new XAttribute("numBranchPoints", moduleBranchCoverage.Total.ToString()));
coverageSummary.Add(new XAttribute("visitedBranchPoints", moduleBranchCoverage.Covered.ToString()));
coverageSummary.Add(new XAttribute("sequenceCoverage", moduleLineCoverage.Percent.ToString()));
coverageSummary.Add(new XAttribute("branchCoverage", moduleBranchCoverage.Percent.ToString()));
coverageSummary.Add(new XAttribute("sequenceCoverage", Math.Round(moduleLineCoverage.Percent * 100, 2).ToString("G", CultureInfo.InvariantCulture)));
coverageSummary.Add(new XAttribute("branchCoverage", Math.Round(moduleBranchCoverage.Percent * 100, 2).ToString("G", CultureInfo.InvariantCulture)));
coverageSummary.Add(new XAttribute("maxCyclomaticComplexity", moduleMaxCyclomaticComplexity.ToString()));
coverageSummary.Add(new XAttribute("minCyclomaticComplexity", moduleMinCyclomaticComplexity.ToString()));
coverageSummary.Add(new XAttribute("visitedClasses", visitedClasses.ToString()));
Expand Down
13 changes: 12 additions & 1 deletion test/coverlet.core.tests/Reporters/OpenCoverReporterTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Xunit;

namespace Coverlet.Core.Reporters.Tests
Expand All @@ -16,7 +20,11 @@ public void TestReport()
result.Modules.Add("Coverlet.Core.Reporters.Tests", CreateFirstDocuments());

OpenCoverReporter reporter = new OpenCoverReporter();
Assert.NotEqual(string.Empty, reporter.Report(result));
string report = reporter.Report(result);
Assert.NotEmpty(report);
XDocument doc = XDocument.Load(new MemoryStream(Encoding.UTF8.GetBytes(report)));
Assert.Empty(doc.Descendants().Attributes("sequenceCoverage").Where(v => v.Value != "33.3"));
Assert.Empty(doc.Descendants().Attributes("branchCoverage").Where(v => v.Value != "25"));
}

[Fact]
Expand All @@ -42,10 +50,13 @@ private static Documents CreateFirstDocuments()
Lines lines = new Lines();
lines.Add(1, 1);
lines.Add(2, 0);
lines.Add(3, 0);

Branches branches = new Branches();
branches.Add(new BranchInfo { Line = 1, Hits = 1, Offset = 23, EndOffset = 24, Path = 0, Ordinal = 1 });
branches.Add(new BranchInfo { Line = 1, Hits = 0, Offset = 23, EndOffset = 27, Path = 1, Ordinal = 2 });
branches.Add(new BranchInfo { Line = 1, Hits = 0, Offset = 40, EndOffset = 41, Path = 0, Ordinal = 3 });
branches.Add(new BranchInfo { Line = 1, Hits = 0, Offset = 40, EndOffset = 44, Path = 1, Ordinal = 4 });

Methods methods = new Methods();
var methodString = "System.Void Coverlet.Core.Reporters.Tests.OpenCoverReporterTests.TestReport()";
Expand Down