by changing my code to get 100% code coverage

Isn't the point of coverage to change your tests to increase coverage? Changing your logic for the sake of coverage seems backwards. (Note -- I'm not talking about changing layout of conditionals so that Devel::Cover can follow the logic.)

What your example does demonstrate is how seeking 100% coverage can help uncover faulty assumptions in either the requirements or the underlying code.

Using something like Carp::Assert or something similar might help here

I like that for clarity of intent, but of course, it's only hiding the lack of coverage of the failure of the assertion. Your assert line of code will be "covered", but the underlying logic won't.

Nevertheless, if I had to sum up your post, it would this:

Conditionals or branches that can't be covered because they always should be true (or false) should be converted into assertions instead.

And that does sound like good advice. ++

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.


In reply to Re: When 100% Code Coverage Backfires by xdg
in thread When 100% Code Coverage Backfires by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.