X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fstorage%2Ferror.t;h=68bbb5ad06237230affb6f6d0a1f81cce1bfb2dd;hb=a458e9e3a522099867e27e4c84cd94ca37e1355b;hp=e57d892764b9a7bf11c3fb65d0ced5c79114b0a3;hpb=56166f36313355d502a6517bf3316252d92d375a;p=dbsrgits%2FDBIx-Class.git diff --git a/t/storage/error.t b/t/storage/error.t index e57d892..68bbb5a 100644 --- a/t/storage/error.t +++ b/t/storage/error.t @@ -11,10 +11,40 @@ use_ok( 'DBICTest::Schema' ); my $schema = DBICTest->init_schema; +my $e_start = quotemeta('DBIx::Class::'); + warnings_are ( sub { - throws_ok (sub { - $schema->resultset('CD')->create({ title => 'vacation in antarctica' }); - }, qr/NULL/); # as opposed to some other error + throws_ok ( + sub { + $schema->resultset('CD')->create({ title => 'vacation in antarctica' }) + }, + qr/$e_start.+constraint failed.+NULL/s + ); # as opposed to some other error }, [], 'No warnings besides exception' ); +my $dbh = $schema->storage->dbh; + +throws_ok ( + sub { + $dbh->do ('INSERT INTO nonexistent_table VALUES (1)') + }, + qr/$e_start.+DBI Exception.+no such table/, + 'DBI exceptions properly handled by dbic-installed callback' +); + +# This usage is a bit unusual but it was actually seen in the wild +# destruction of everything except the $dbh should use the proper +# exception fallback: + +{ + undef ($schema); + throws_ok ( + sub { + $dbh->do ('INSERT INTO nonexistent_table VALUES (1)') + }, + qr/DBI Exception.+unhandled by DBIC.+no such table/, + 'callback works after $schema is gone' + ); +} + done_testing;