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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |