update: This was solved in this node, thanks to NetWallah in this reply. It boiled down to me not following through on reading documentation./update

I've got this code in the new() method of a DB class (code has been re-aligned as to not wrap here on PM):

$self->{db} = DBI->connect( "dbi:SQLite:dbname=$db_file", "", "", {RaiseError => 1} ) or die $DBI::errstr;

...and although I have tests that use this call hundreds of times, I wrote two specific tests to make both sides of the or pass:

{ # crash the connect() my $ok = eval { App::RPi::EnvUI::DB->new( db_file => '/' ); 1; }; is $ok, undef, "when a DBH can't be created, we die"; like $@, qr/unable to open database/, "...and the error message is sane"; } { # good connect() my $db = App::RPi::EnvUI::DB->new( testing => 1 ); is ref $db->{db}, 'DBI::db', "dbh loaded ok"; }

Both of those tests pass with no problems. However, when I run cover -test on the gamut, it shows this in the output:

23 50 T F unless $self->{'db'} = 'DBI'->connect("dbi:SQLite:dbname=$db +_file", '', '', {'RaiseError', 1})

Where the F (false) is covered, but the T (true) isn't. Line 23 is the DB connect code I showed above, and the 50 is telling me only half of the equation has been tested.

Am I missing something obvious here as to why I can't get 100% coverage on this branch?

This one branch is the only item keeping me from 100% coverage on this module.

To clarify, all tests pass before I view the coverage results:

Files=19, Tests=894, 83 wallclock secs ... Result: PASS

In reply to [SOLVED]: Testing a DB connect() or die() by stevieb

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.