Skip to content
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

Color Method Links to Match their Coverage Percent #348

Closed
aschlicht opened this issue May 20, 2020 · 10 comments
Closed

Color Method Links to Match their Coverage Percent #348

aschlicht opened this issue May 20, 2020 · 10 comments

Comments

@aschlicht
Copy link

@danielpalme What do you think about coloring the method links to match their coverage percent? I'm referring to the method / property links on the right side of an html page that shows the source code and highlights which lines are covered or not. I think users could more quickly navigate to uncovered or partially covered methods if they are color coded. The method name could be colored and / or the icon next to the function / method name could be color coded.

I don't know which input types support function coverage information. I do know gcov supports covered line % in a function because I use gcov with the ceedling unit tests. We recently added support to call report generator from ceedling.

I experimented with changing a few report generator source files and it appears to work well. These changes set the method name color, not the icon color. Not sure if the way I made the changes goes along with your design, so I sent the .cs source files in a zip file instead of a pull request.

Consider an enable / disable command line option similar to those found here, if you think some people may like this change while others dislike it:
https://github.com/danielpalme/ReportGenerator/wiki/Settings

ColorCodeMethodNames.zip

@danielpalme
Copy link
Owner

I will have a look at this within the next days.

@aschlicht
Copy link
Author

aschlicht commented May 22, 2020

Thank you for looking at this enhancement request already. You have a more generic way of calculating method / property coverage, which is great! I also like the look of the vertical bars much better than coloring the method name.

I pulled your 4.6.0 branch and so far I see either 0% or 100% for gcov. I think it is because of this line from GCovParser.cs. The first and last line number are equal, so there can only be either 0 or 1 covered lines of code.

codeElements.Add(new CodeElement(name, CodeElementType.Method, maxiumLineNumber + 1, maxiumLineNumber + 1));

I'm not sure of a great way to determine when a function ends from gcov files. Could update the previous function's last line when encountering the next "function" text or end-of-file. The .gcov file does have the "blocks executed" percentage already calculated and in the file. Could use that value. You know your report generator tool well and maybe you already have a better idea.

I put a new regular expression for parsing the gcov function line in GCovParser.cs. Letting you know in case that helps.

/// <summary>
/// Regex to analyze if a line contains function coverage data.
/// </summary>
private static Regex functionCoverageRegex = new Regex("function\\s*(?<FunctionName>[^\\s]+)\\s*called\\s*(?<CalledCount>\\d+)\\s*returned\\s*(?<ReturnedPercent>\\d+)%\\s*blocks\\sexecuted\\s*(?<BlocksExecutedPercent>\\d+)%");

@danielpalme
Copy link
Owner

I'm still working on it.
Gcov is pretty limited. The regular expression is not perfect, because you get the block coverage and not the line coverage.
ReportGenerator is all about line coverage and block coverage is similar but not the same.
This might result in discussions like "The coverage does not match...".

@aschlicht
Copy link
Author

I believe it's not ready yet. If you thought it was, you would have published a release. I was interested in your approach, so I took a look, tested it, and gave some feedback. I think it looks great. Thank you for working on this feature.

I didn't know about the line coverage and block coverage difference. You are correct. People would log issues saying the coverage does not match.

@danielpalme
Copy link
Owner

If you like you can try my changes again. It now works for all input formats.

Instead of the block coverage I'm detecting the first and last line of each method.
This has some limitations for gcov since gcov does don't contain a status for each line.
But it should be good enough in most situation.

@aschlicht
Copy link
Author

aschlicht commented May 23, 2020

I tried only with gcov through ceedling and your latest changes are working well. I like having a way to quickly navigate to the source code needing additional unit tests. Thank you for making these changes.

Maybe it's my eyes, but to me it appears the red part of the coverage percent indicator is slightly offset toward the left when compared to the green part. Do you see that as well? Maybe that is intentional.

image

@sungam3r
Copy link

I see that too.

@danielpalme
Copy link
Owner

I see it too. But it disappears when I zoom in.
It's a straight line implemented as simple CSS border with gradient (see https://github.com/danielpalme/ReportGenerator/blob/v4.6.0/src/ReportGenerator.Core/Reporting/Builders/Rendering/resources/custom.css#L63)

@danielpalme
Copy link
Owner

@aschlicht
Copy link
Author

@danielpalme Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants