-
Notifications
You must be signed in to change notification settings - Fork 392
Fix cobertura Jenkins reporter + source link support #614
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
Changes from all commits
a6e0687
84c0aff
5b4e316
45075e1
ef7d0b0
a50f143
28e038c
a8198b6
83cae50
26e4959
7ffb1de
ab54646
529437f
595194f
761662b
bc24dd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,9 @@ | |
| using System.Globalization; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Runtime.InteropServices; | ||
| using System.Text; | ||
| using System.Threading; | ||
| using System.Xml; | ||
| using System.Xml.Linq; | ||
| using Xunit; | ||
|
|
||
|
|
@@ -37,7 +37,15 @@ public void TestReport() | |
| classes.Add("Coverlet.Core.Reporters.Tests.CoberturaReporterTests", methods); | ||
|
|
||
| Documents documents = new Documents(); | ||
| documents.Add("doc.cs", classes); | ||
|
|
||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
| documents.Add(@"C:\doc.cs", classes); | ||
| } | ||
| else | ||
| { | ||
| documents.Add(@"/doc.cs", classes); | ||
| } | ||
|
|
||
| result.Modules = new Modules(); | ||
| result.Modules.Add("module", documents); | ||
|
|
@@ -102,7 +110,14 @@ public void TestEnsureParseMethodStringCorrectly( | |
| classes.Add("Google.Protobuf.Reflection.MessageDescriptor", methods); | ||
|
|
||
| Documents documents = new Documents(); | ||
| documents.Add("doc.cs", classes); | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
| documents.Add(@"C:\doc.cs", classes); | ||
| } | ||
| else | ||
| { | ||
| documents.Add(@"/doc.cs", classes); | ||
| } | ||
|
|
||
| result.Modules = new Modules(); | ||
| result.Modules.Add("module", documents); | ||
|
|
@@ -120,5 +135,77 @@ public void TestEnsureParseMethodStringCorrectly( | |
| Assert.Equal(expectedMethodName, methodAttrs["name"]); | ||
| Assert.Equal(expectedSignature, methodAttrs["signature"]); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TestReportWithTwoDifferentDirectories() | ||
| { | ||
| CoverageResult result = new CoverageResult(); | ||
| result.Identifier = Guid.NewGuid().ToString(); | ||
|
|
||
| var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); | ||
|
|
||
| string absolutePath1; | ||
| string absolutePath2; | ||
|
|
||
| if (isWindows) | ||
| { | ||
| absolutePath1 = @"C:\projA\file.cs"; | ||
| absolutePath2 = @"E:\projB\file.cs"; | ||
| } | ||
| else | ||
| { | ||
| absolutePath1 = @"/projA/file.cs"; | ||
| absolutePath2 = @"/projB/file.cs"; | ||
| } | ||
|
|
||
| var classes = new Classes {{"Class", new Methods()}}; | ||
| var documents = new Documents {{absolutePath1, classes}, {absolutePath2, classes}}; | ||
|
|
||
| result.Modules = new Modules {{"Module", documents}}; | ||
|
|
||
| CoberturaReporter reporter = new CoberturaReporter(); | ||
| string report = reporter.Report(result); | ||
|
|
||
| var doc = XDocument.Load(new MemoryStream(Encoding.UTF8.GetBytes(report))); | ||
|
|
||
| List<string> rootPaths = doc.Element("coverage").Element("sources").Elements().Select(e => e.Value).ToList(); | ||
| List<string> relativePaths = doc.Element("coverage").Element("packages").Element("package") | ||
| .Element("classes").Elements().Select(e => e.Attribute("filename").Value).ToList(); | ||
|
|
||
| List<string> possiblePaths = new List<string>(); | ||
| foreach (string root in rootPaths) | ||
| { | ||
| foreach (string relativePath in relativePaths) | ||
| { | ||
| possiblePaths.Add(Path.Combine(root, relativePath)); | ||
| } | ||
| } | ||
|
|
||
| Assert.Contains(absolutePath1, possiblePaths); | ||
| Assert.Contains(absolutePath2, possiblePaths); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TestReportWithSourcelinkPaths() | ||
| { | ||
| CoverageResult result = new CoverageResult {UseSourceLink = true, Identifier = Guid.NewGuid().ToString()}; | ||
|
|
||
| var absolutePath = | ||
| @"https://raw.githubusercontent.com/johndoe/Coverlet/02c09baa8bfdee3b6cdf4be89bd98c8157b0bc08/Demo.cs"; | ||
|
|
||
| var classes = new Classes {{"Class", new Methods()}}; | ||
| var documents = new Documents {{absolutePath, classes}}; | ||
|
|
||
| result.Modules = new Modules {{"Module", documents}}; | ||
|
|
||
| CoberturaReporter reporter = new CoberturaReporter(); | ||
| string report = reporter.Report(result); | ||
|
|
||
| var doc = XDocument.Load(new MemoryStream(Encoding.UTF8.GetBytes(report))); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok maybe cleanup a bit with
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| var fileName = doc.Element("coverage").Element("packages").Element("package").Element("classes").Elements() | ||
| .Select(e => e.Attribute("filename").Value).Single(); | ||
|
|
||
| Assert.Equal(absolutePath, fileName); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about
This should be the expected alg of every reporter that can read a cobertura format...we try every permutation root+path and check if exists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I changed it that way.