CC: | timb [...] cpan.org |
Subject: | Fails to Catch Certain DBI Exceptions |
Date: | Tue, 21 Feb 2006 22:24:30 -0800 |
To: | bug-test-exception [...] rt.cpan.org |
From: | "David E. Wheeler" <dwheeler [...] cpan.org> |
Some DBI exceptions are not properly caught by Test::Exception. For
example, this script:
use strict;
use Test::More tests => 1;
use Test::Exception;
use DBI;
dies_ok { DBI->connect('dbi:Pg:dbname=ick', 'postgres', '') }
'DBI should die with bogus values';
When I run it, I get:
1..1
DBI connect('dbname=ick','postgres',...) failed: FATAL: database
"ick" does not exist
at /usr/local/lib/perl5/site_perl/5.8.7/Test/Exception.pm line 128
not ok 1 - DBI should die with bogus values
# Failed test 'DBI should die with bogus values'
# in /Users/david/bin/try at line 9.
# Looks like you failed 1 test of 1.
That's not what I expect, of course. The problem doesn't exist for
all DBI exceptions, though. If I change the DSN to just 'foo',
dies_ok will catch it. But when I have a correct DSN and database
username and password, DBD::Pg that generates the exception (using
DBI's exception-handling C function, I believe), and then
Test::Exception doesn't catch it.
This is not local to DBD::Pg. If I change the test to use SQLite:
dies_ok { DBI->connect('dbi:SQLite:dbname=/root/foo', '', '') }
'DBI should die with bogus values';
Then I get the same problem:
1..1
DBI connect('dbname=/root/foo','',...) failed: unable to open
database file(1) at dbdimp.c line 94 at /usr/local/lib/perl5/
site_perl/5.8.7/Test/Exception.pm line 128
not ok 1 - DBI should die with bogus values
# Failed test 'DBI should die with bogus values'
# in /Users/david/bin/try at line 10.
# Looks like you failed 1 test of 1.
I'm Cc'ing Tim on this in case he has some suggestions as to what
might be different about exceptions thrown by the DBI.
Thanks!
David