X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fstorage%2Ferror.t;h=6c9b15cd992cbcd433cb37b1377ce62f1d142731;hb=8d73fcd44e0441f0252744be32bada6816c5ff6b;hp=2efb8d59eb3d4067e66cdf31b49409670f4bf0e6;hpb=2dc8d9618fd296ecdd4484d3686832de0592e747;p=dbsrgits%2FDBIx-Class.git diff --git a/t/storage/error.t b/t/storage/error.t index 2efb8d5..6c9b15c 100644 --- a/t/storage/error.t +++ b/t/storage/error.t @@ -1,29 +1,55 @@ -use Class::C3; use strict; -use Test::More; use warnings; -BEGIN { - eval "use DBD::SQLite"; - plan $@ - ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 4 ); -} +use Test::More; +use Test::Warn; +use Test::Exception; use lib qw(t/lib); +use DBICTest; -use_ok( 'DBICTest' ); -use_ok( 'DBICTest::Schema' ); my $schema = DBICTest->init_schema; -{ - my $warnings; - local $SIG{__WARN__} = sub { $warnings .= $_[0] }; - eval { - $schema->resultset('CD') - ->create({ title => 'vacation in antarctica' }) - }; - like $@, qr/NULL/; # as opposed to some other error - unlike( $warnings, qr/uninitialized value/, "No warning from Storage" ); +warnings_are ( sub { + throws_ok ( + sub { + $schema->resultset('CD')->create({ title => 'vacation in antarctica' }) + }, + qr/DBI Exception.+(?x: + \QNOT NULL constraint failed: cd.artist\E + | + \Qcd.artist may not be NULL\E + )/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/DBI Exception.+no such table.+nonexistent_table/s, + '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: + +SKIP: { + if ( !!DBIx::Class::_ENV_::PEEPEENESS ) { + skip "Your perl version $] appears to leak like a sieve - skipping garbage collected \$schema test", 1; + } + + undef ($schema); + throws_ok ( + sub { + $dbh->do ('INSERT INTO nonexistent_table VALUES (1)') + }, + qr/DBI Exception.+unhandled by DBIC.+no such table.+nonexistent_table/s, + 'callback works after $schema is gone' + ); } +done_testing;