-
Notifications
You must be signed in to change notification settings - Fork 392
Relative paths lcov #1004
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
Closed
Closed
Relative paths lcov #1004
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d4eb476
Refactored functions to determine base paths from CoberturaReporter i…
phaniva 0e97f5d
Added dependency on IFilePathHelper for ReporterFactory (#263)
phaniva 6454217
Updated LcovReporter to include only relative paths for source files …
phaniva 35afa29
Merge branch 'master' of https://github.com/coverlet-coverage/coverle…
phaniva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Coverlet.Core.Abstractions | ||
| { | ||
| interface IFilePathHelper | ||
| { | ||
| IEnumerable<string> GetBasePaths(IEnumerable<string> paths, bool useSourceLink); | ||
| string GetRelativePathFromBase(IEnumerable<string> basePaths, string path, bool useSourceLink); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| using Coverlet.Core.Abstractions; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.IO; | ||
| using System.Linq; | ||
|
|
||
|
|
||
| namespace Coverlet.Core.Helpers | ||
| { | ||
| internal class FilePathHelper : IFilePathHelper | ||
| { | ||
| public IEnumerable<string> GetBasePaths(IEnumerable<string> paths, bool useSourceLink) | ||
| { | ||
| /* | ||
| Workflow | ||
|
|
||
| Path1 c:\dir1\dir2\file1.cs | ||
| Path2 c:\dir1\file2.cs | ||
| Path3 e:\dir1\file2.cs | ||
|
|
||
| 1) Search for root dir | ||
| c:\ -> c:\dir1\dir2\file1.cs | ||
| c:\dir1\file2.cs | ||
| e:\ -> e:\dir1\file2.cs | ||
|
|
||
| 2) Split path on directory separator i.e. for record c:\ ordered ascending by fragment elements | ||
| Path1 = [c:|dir1|file2.cs] | ||
| Path2 = [c:|dir1|dir2|file1.cs] | ||
|
|
||
| 3) Find longest shared path comparing indexes | ||
| Path1[0] = Path2[0], ..., PathY[0] -> add to final fragment list | ||
| Path1[n] = Path2[n], ..., PathY[n] -> add to final fragment list | ||
| Path1[n+1] != Path2[n+1], ..., PathY[n+1] -> break, Path1[n] was last shared fragment | ||
|
|
||
| 4) Concat created fragment list | ||
| */ | ||
| if (useSourceLink) | ||
| { | ||
| return new[] { string.Empty }; | ||
| } | ||
|
|
||
| return paths.GroupBy(Directory.GetDirectoryRoot).Select(group => | ||
| { | ||
| var splittedPaths = group.Select(absolutePath => absolutePath.Split(Path.DirectorySeparatorChar)) | ||
| .OrderBy(absolutePath => absolutePath.Length).ToList(); | ||
| if (splittedPaths.Count == 1) | ||
| { | ||
| return group.Key; | ||
| } | ||
|
|
||
| var basePathFragments = new List<string>(); | ||
| bool stopSearch = false; | ||
| splittedPaths[0].Select((value, index) => (value, index)).ToList().ForEach(fragmentIndexPair => | ||
| { | ||
| if (stopSearch) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (splittedPaths.All(sp => fragmentIndexPair.value.Equals(sp[fragmentIndexPair.index]))) | ||
| { | ||
| basePathFragments.Add(fragmentIndexPair.value); | ||
| } | ||
| else | ||
| { | ||
| stopSearch = true; | ||
| } | ||
| }); | ||
| return string.Concat(string.Join(Path.DirectorySeparatorChar.ToString(), basePathFragments), Path.DirectorySeparatorChar); | ||
| }); | ||
| } | ||
|
|
||
| public string GetRelativePathFromBase(IEnumerable<string> basePaths, string path, bool useSourceLink) | ||
| { | ||
| if (useSourceLink) | ||
| { | ||
| return path; | ||
| } | ||
|
|
||
| foreach (var basePath in basePaths) | ||
| { | ||
| if (path.StartsWith(basePath)) | ||
| { | ||
| return path.Substring(basePath.Length); | ||
| } | ||
| } | ||
|
|
||
| Debug.Assert(false, "Unexpected, we should find at least one path starts with one pre-build roots list"); | ||
|
|
||
| return path; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think that extract a service is too much for a path helper...I mean we won't inject different implementation there are no different way to get that path from file system.
Should be enough add a new base class
abstract ReporterBaseand add this two method asprotectedand inherit the reporter that needs this logic.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.
So only the reporter classes that need this behavior will inherit from ReporterBase and rest of them will continue to implement IReporter?
Why not inherit every reporter class from ReporterBase to keep things consistent?
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.
Ok I won't oppose, the important things is that we have less code as possible to maintain, let's go for base class inherited by reporters
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.
Cool. I am going to close this pr and open a new one with base class design.
Here is the new pr.
#1120