in reply to [SOLVED]: Testing a DB connect() or die()

RaiseError=>1
Will cause "any method which results in an error will cause the DBI to effectively do a die" (From the DBI docs).

So - it dies before it can execute your "or die".

The docs suggest an "eval" to catch the "die".

        ...it is unhealthy to remain near things that are in the process of blowing up.     man page for WARP, by Larry Wall

Replies are listed 'Best First'.
Re^2: Testing a DB connect() or die()
by stevieb (Canon) on Oct 12, 2016 at 23:23 UTC

    Per NetWallah's reply, I changed my code to this:

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

    ...and my tests to send in db_err => 0 in the calls to new(), and I get 100% coverage. I don't think I'll make this a user-visible param (but I will document it) as I always want the upper module to take care of the problem, but to ensure I've covered it, it works.

    This was a case of me not reading enough documentation.

Re^2: Testing a DB connect() or die()
by stevieb (Canon) on Oct 12, 2016 at 23:10 UTC

    For the love of all things good. That's two issues in a row that I just didn't read enough documentation. (In a sad attempt to defend against my own ineptitude, I didn't think looking that high up in the docs, but that is far from reason).

    Thanks NetWallah, I'll make the RaiseError a method param or config variable for this specific test, and report back here with the results.

    Due to the numerous processes that are operating simultaneously in this application, it forces me to push test setup instructions far up the chain so that it can be tested without having the physical hardware I require (Raspberry Pi, and specific sensors attached). This one however, is something I should have noticed, but I digress... even though I haven't used DB in years, that's no excuse for me not reading the docs.