-
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
Fix cobertura Jenkins reporter + source link support #614
Conversation
update fork
Update fork
Update fork
Update fork
Update fork
Update fork
Update fork
Update fork
|
Filename attribute is now relative to system root and the reports can properly be displayed in jenkins running on linux or windows. I also attached a snipped form the generated report where the source tag and the filename tag can be seen. This doesn't really solve the issue #413 because the introduced relative paths aren't relative to the project base. |
|
Thanks David bit busy next week I'll take a look asap! |
src/coverlet.core/CoverageResult.cs
Outdated
| { | ||
| public string Identifier; | ||
| public Modules Modules; | ||
| public bool IsSourceLinkUsed; |
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.
nit: I prefer to maintain switch name UseSourceLink
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.
Done
| using System.Globalization; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Runtime.InteropServices; |
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.
Is this necessary?
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.
Done
| return Encoding.UTF8.GetString(stream.ToArray()); | ||
| } | ||
|
|
||
| private static IEnumerable<string> GetRootDirs(Modules modules, bool isSourceLinkUsed) |
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.
why not
if (isSourceLinkUsed)
{
return new[] { string.Empty };
}
else
{
return modules.Values.SelectMany(k => k.Keys).Select(Directory.GetDirectoryRoot).Distinct();
}Does it work?
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 tested it. Done.
| return sources.Select(Directory.GetDirectoryRoot).Distinct(); | ||
| } | ||
|
|
||
| private static string GetRelativePathFromBase(IEnumerable<string> basePaths, string path, bool isSourceLinkUsed) |
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.
rename rootPaths and useSourceLink pls
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.
Done
| { | ||
| if (path.StartsWith(basePath)) | ||
| { | ||
| relativePath = path.Substring(basePath.Length); |
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
if (isSourceLinkUsed)
{
return path;
}
foreach (var root in basePaths)
{
if (path.StartsWith(root))
{
return path.Substring(root.Length);
}
}
Debug.Assert(false, "Unexpected, we should find at least one path starts with one pre-build roots list");
return path;it seems more logic to me...when we found one valid root we can return immediatly, if we don't found any valid root(unexpected) we return original path, so we avoid exception and we'll generate a file(better than nothing), I added also an assertion so on debug we'll catch possible problem.
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 agree. Done.
|
Thank's @daveMueller for the effort here and sorry for the delay. I'd like to add more tests on this
|
|
@daveMueller let me know if you want complete this or if can finish this PR on top of your precious work! |
@MarcoRossignoli Yes I will complete it. I already did most of the things you mentioned locally. My daytime job has been keeping me busy last week but I think I will find some free time on the weekend. |
|
No worries no rush, only asked to know! |
|
@MarcoRossignoli I still want to refactore the tests. Had some problems to get them running on X plat and so they are still not really clean. If you have some ideas what could be changed, please let me know. |
| CoberturaReporter reporter = new CoberturaReporter(); | ||
| string report = reporter.Report(result); | ||
|
|
||
| var doc = XDocument.Load(new MemoryStream(Encoding.UTF8.GetBytes(report))); |
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
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);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.
| CoberturaReporter reporter = new CoberturaReporter(); | ||
| string report = reporter.Report(result); | ||
|
|
||
| var doc = XDocument.Load(new MemoryStream(Encoding.UTF8.GetBytes(report))); |
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.
ok maybe cleanup a bit with doc.Element("coverage").Element("packages").Element("package").Element("classes").Elements().Select(e => e.Attribute("filename").Value).Single();
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.
Done
|
@daveMueller can you test and attach also a reportgenerator result?Only to be sure to be compatible with it(most used tool). |
|
@MarcoRossignoli are the attached screenshots sufficient? Here is the relevant part of a cobertura report: And this is the reportgenerator output for the cobertura report. |
|
yep thank you |
|
@danielpalme can you take a look at report generated at #614 (comment) and double confirm that it's ok? |
|
Your code looks fine to me.
|
This is the old behavior, but we need to split root+relative due to Jenkins reporter, it doesn't work well without |
MarcoRossignoli
left a comment
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.
Looks fine!
|
Thank's Dave! |



closes #197, closes #408 and really closes #295 and maintains #257