Skip to content

Release Branch coverage #781

Closed
Closed

Description

@PragTob

After merging #694 this issue is here to keep track of the functionality until initial release and helps me & others :)

Big thanks to @som4ik @tycooon @stepozer @klyonrad and many others for their valuable contributions!

  • Merge initial PR Feature/branches coverage support #694
  • Merge corresponding html formatter PR Add ability to support branch coverage statistics ruby >= 2.5 simplecov-html#64
    • Address remaining code review feedback
  • Make sure problems with existing PR are solved (ref1 ref2)
    • parallel tests support works as intended
    • :nocov: blocks should be considered
  • Address initial code review comments
  • Change used option name to use branch coverage/chanege coverage type
  • add some feature tests
  • Investigate coverage reporting (it seems like it reports lines as covered when what we'd like to have are branches)
  • release pre release version for general/public testing (this and formatter)
  • make it possible that the branch coverage percentage is displayed as the "main" coverage and all our checks take it instead of line coverage
  • also allow people to do coverage checks versus multiple metrics for instance I want my line coverage to be at least 95% and my branch coverage to be at least 90%.
  • figure out problems with the format data is stored in Release Branch coverage #781
  • fix reported beta problems
  • release the "finished for now" branch coverage

Activity

  1. PragTob commented on Dec 15, 2019

    @PragTob
    CollaboratorAuthor

    👋

    Hi @som4ik - got around to writing a feature test for this. It seems to me (and my reading of the code) that we still report coverage on a per line basis - is this correct from your memory? 😅

    What I mean by that is that we use branch coverage to figure out which lines are covered and then we mark those lines as covered and report them as such. I think what we want is that we report it on a per branch basis (so instead of 80/100 lines covered we wanna say 33/38 branches covered or something to the tune of this).

    Confirmation would be nice!

  2. som4ik commented on Dec 16, 2019

    @som4ik
    Contributor

    Hi @PragTob 👋
    As I remember per line bases report is mandatory-default coverage report, passing :branches parameter to Coverage.start adds a new type of collected coverage result matrics, but doesn't cancel generating per line bases report.
    Just to clarify, we don't use per line bases to generate branch coverage metrics, you can notice that the coverage report displays already your suggestion:
    branch-1
    branch-2
    let me guess what made it confusing:

    • misleading here is the config parameter naming, use_branchable_report it should be at least add_branchable_report.
    • Branch class contains matrics start_line, end_line. (it's branch coverage metrics and it's not related to the per lines bases report ).
      Hope I answered the question 😄
  3. PragTob commented on Dec 16, 2019

    @PragTob
    CollaboratorAuthor

    Yeah you did thank you, then I just gotta tweak the cukes and selects on all of that. Thank you!

  4. PragTob commented on Dec 21, 2019

    @PragTob
    CollaboratorAuthor

    Yeah so I took a look at it and figured out that right now we basically just "add" branch coverage but there's no way to make it the "main coverage" aka the coverage by we fail if we say minimum coverage or something else.

    I think I want to do a first release with that, but I think it'd be good if people could decide what their "main coverage" would be (and then also display that most prominently).

    Another thing that my tests just showed me as counter intuitive is that if a file has no conditional statements at all there are no branches and hence we report 0 branches and say it's 100% covered even if no method defined in there is ever covered. Which is plenty weird I believe. On the other hand branch coverage by itself can't determine whether it's covered or not as the coverage data is literally empty...

    if anyone here had input on these points I'd appreciate it.

    edit: did my bunch of reading, and apparently that's how branch coverage is supposed to work. Curious because entire files could be not covered and one would never know. Maybe that's edge coverage, online resources aren't really generous about code coverage sadly.

  5. JonJagger commented on Dec 28, 2019

    @JonJagger

    I agree that does sound weird. Rather than thinking of branches being "off" the main trunk you could think simply of there being N different branches. N different paths. From that point of view, a file with some code which has no conditional statements doesn't have zero branches, it has one path.
    Maybe changing the vocabulary will help?
    Eg Use the word 'covered' in line messages.
    Eg Use the word 'taken' or 'visited' in branch/path messages?
    P.S. Awesome work. Can't wait to add this.

  6. JonJagger commented on Dec 29, 2019

    @JonJagger

    Some code that previously had 100% coverage just dropped to 99% coverage. Looking at the html report it shows this:
    simplecov-screenshot
    I don't understand how line 42 can have no coverage when it is a while and the block it controls 43-46 does have coverage (24 hits). My only guess is it's something to do with the previous line, 41, which has an && in it, and the forthcoming branch coverage?

  7. PragTob commented on Dec 29, 2019

    @PragTob
    CollaboratorAuthor

    @JonJagger 👋

    That seems unlikely, doesn't look like you have branch coverage activated (there would be little badges saying "+", 0 or something around there or something).

    I absolutely agree the line should be covered though, so that seems odd. But it reminds me off #764 where it was a coverage bug that some until line wasn't covered.

    Are you sure that this is related to some simplecov upgrade or maybe some ruby version upgrade in the middle of it?

  8. tleish commented on Dec 29, 2019

    @tleish

    @JonJagger - out of curiosity, what does the coverage for def same? look like?

  9. JonJagger commented on Dec 29, 2019

    @JonJagger

    The coverage for def same is
    simplecov-same-coverage

  10. JonJagger commented on Dec 29, 2019

    @JonJagger

    @JonJagger 👋

    That seems unlikely, doesn't look like you have branch coverage activated (there would be little badges saying "+", 0 or something around there or something).

    Yes. Sorry. I was not clear. My assumption was that my recent upgrade had got a new version of simplecov which had been refactored in preparation for the branch-coverage.

    I absolutely agree the line should be covered though, so that seems odd. But it reminds me off #764 where it was a coverage bug that some until line wasn't covered.

    Are you sure that this is related to some simplecov upgrade or maybe some ruby version upgrade in the middle of it?

    The app in question is docker containerized. It gets simplecov and ruby from a base image (Alpine).
    Shelling into that I can see the Gemfile.lock

    GEM
      remote: https://rubygems.org/
      specs:
        docile (1.3.2)
        json (2.3.0)
        minitest (5.13.0)
        ruby-prof (1.1.0)
        simplecov (0.17.1)
          docile (~> 1.1)
          json (>= 1.8, < 3)
          simplecov-html (~> 0.10.0)
        simplecov-html (0.10.2)
    

    And ruby -v gives

    ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux-musl]
    

    The previous docker image gives...

    GEM
      remote: https://rubygems.org/
      specs:
        daemons (1.3.1)
        docile (1.3.2)
        eventmachine (1.2.7)
        json (2.2.0)
        minitest (5.11.3)
        prometheus-client (0.9.0)
          quantile (~> 0.2.1)
        quantile (0.2.1)
        rack (2.0.7)
        ruby-prof (0.18.0)
        simplecov (0.16.1)
          docile (~> 1.1)
          json (>= 1.8, < 3)
          simplecov-html (~> 0.10.0)
        simplecov-html (0.10.2)
        thin (1.7.2)
          daemons (~> 1.0, >= 1.0.9)
          eventmachine (~> 1.0, >= 1.0.4)
          rack (>= 1, < 3)
    

    and

    ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux-musl]
    

    I will build a new image with the previous version of simplecov and report back...
    The code being covered has not changed.

  11. JonJagger commented on Dec 29, 2019

    @JonJagger

    Rebuilding with simplecov set to 0.16.1 the coverage anomaly goes away...
    simplecov-0 16 1-coverage
    I note also that ruby -v gives 2.5.7p206

  12. PragTob commented on Dec 29, 2019

    @PragTob
    CollaboratorAuthor

    @JonJagger could you please open a separate issue as it seems to be not connected to this then? Also the ruby version changes so that's still my suspect but it could ofc still be that 0.17.0/0.17.1 broke something.

  13. JonJagger commented on Dec 29, 2019

    @JonJagger

    I am now unable to reproduce the anomaly locally with simplecov set to 0.16.1, 0.17.0, 0.17.1
    However I am still getting the same coverage anomaly on images built on my CI cloud-pipeline.
    I will dig some more and if need be open a new issue.

  14. PragTob commented on Dec 29, 2019

    @PragTob
    CollaboratorAuthor

    @JonJagger maybe running tests in parallel? That makes things a lot fancier and more likely to have weird errors :)

  15. 14 remaining items

  16. tycooon commented on Jan 9, 2020

    @tycooon

    Shouldn't this be three branches?

    Unfortunately, this is not how Ruby branch coverage work. You could store the condition result in a variable x and your code would look like return if x. So this is just 2 branches from ruby perspective.

    In case you care about branch coverage a lot, you should probably structure your code like so:

    return if cond1
    return if cond2
    true

    This way you can ensure that all combinations are covered.

  17. tycooon commented on Jan 9, 2020

    @tycooon

    Isn't this two branches?

    No, because there are no conditionals in this code. Method any might be always returning 42, who knows? Ruby is a dynamic language.

  18. PragTob commented on Jan 10, 2020

    @PragTob
    CollaboratorAuthor

    @klyonrad yeah what @tycooon said :) Seems odd to me that the line is makred red though, I'd expect it to be green since it has line coverage (but missing branch coverage) - haven't looked into that yet but I might like it better this way either way :D

  19. PragTob commented on Jan 12, 2020

    @PragTob
    CollaboratorAuthor

    @klyonrad @deivid-rodriguez moved that issue to #820 and will try to chip away at it today as it's a rather critical bug.

  20. PragTob commented on Jan 19, 2020

    @PragTob
    CollaboratorAuthor

    0.18.0.beta2 has been released, I'd be happy if y'all gave it another should have some really great improvements! https://github.com/colszowka/simplecov/blob/master/CHANGELOG.md#0180beta2-2020-01-19

  21. PragTob commented on Jan 23, 2020

    @PragTob
    CollaboratorAuthor

    has anyone tried out the beta2/beta3 releases? Would be happy about feedback!

  22. klyonrad commented on Jan 23, 2020

    @klyonrad

    Not on a grand scale, only sometimes: It does not break 🎉 😍

    The change in showing names and hit counts (!!) for the branch certainly makes it better. Although it starts to look funny when you have a lot (!) of branches in one line 🔱

    Even in string interpolation things you can see the difference, or even more subtle (and mean) the nil check (&.) operator!

    I will try to motivate my former team to test it in their project and report success or failure (the one where I tested over a year and reported issues)

  23. PragTob commented on Jan 25, 2020

    @PragTob
    CollaboratorAuthor

    @klyonrad thanks a bunch!

    I might just go ahead and release it though (testing is great anyhow) but I figure that's the best way to get people to test it.

    I haven't even tested it with &. - probably should add a test case for that just for fun and profit.

    If you have ideas how to make multiple per one line more readable, your ideas are welcome. Off the top of my I'd say sort them by order of appearance (we have the start_col/end_col available) or maybe show more information on hover.

    Thanks!

  24. PragTob commented on Jan 28, 2020

    @PragTob
    CollaboratorAuthor

    And 0.18.0 is released 🎉

    Didn't manage to get in the display as "main coverage" but I don't think it's the main killer feature. There are some spots where we need to up support and they're in my head and I might/will make issues for them.

    I figured it was more important to finally get this into everyone's hands so they can let me/us know what works and what doesn't.

  25. added theissue type on May 6, 2026
  26. changed the issue type fromtoon May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions