Skip to content

Color Method Links to Match their Coverage Percent #348

Closed
@aschlicht

Description

@aschlicht

@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

Activity

danielpalme

danielpalme commented on May 21, 2020

@danielpalme
Owner

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

added a commit that references this issue on May 21, 2020

#348: Added coverage indicator for methods/properties

a325580
aschlicht

aschlicht commented on May 22, 2020

@aschlicht
Author

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

danielpalme commented on May 22, 2020

@danielpalme
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

aschlicht commented on May 22, 2020

@aschlicht
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.

added a commit that references this issue on May 23, 2020

#348: Added coverage indicator for methods/properties

afa1b81
danielpalme

danielpalme commented on May 23, 2020

@danielpalme
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

aschlicht commented on May 23, 2020

@aschlicht
Author

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

sungam3r commented on May 23, 2020

@sungam3r

I see that too.

danielpalme

danielpalme commented on May 23, 2020

@danielpalme
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

danielpalme commented on May 26, 2020

@danielpalme
Owner
aschlicht

aschlicht commented on May 26, 2020

@aschlicht
Author

@danielpalme Thank you!

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @danielpalme@aschlicht@sungam3r

        Issue actions

          Color Method Links to Match their Coverage Percent · Issue #348 · danielpalme/ReportGenerator