Attempt to build a dist on travis if all tests pass
[dbsrgits/DBIx-Class.git] / t / storage / error.t
CommitLineData
a4b2f17b 1use strict;
a4b2f17b 2use warnings;
3
56166f36 4use Test::More;
5use Test::Warn;
6use Test::Exception;
a4b2f17b 7
8use lib qw(t/lib);
0d8817bc 9use DBICTest;
56166f36 10
e60dc79f 11my $schema = DBICTest->init_schema;
a4b2f17b 12
56166f36 13warnings_are ( sub {
b720efd1 14 throws_ok (
15 sub {
16 $schema->resultset('CD')->create({ title => 'vacation in antarctica' })
17 },
cfa136aa 18 qr/DBI Exception.+cd\.artist.+NULL/s
b720efd1 19 ); # as opposed to some other error
56166f36 20}, [], 'No warnings besides exception' );
a4b2f17b 21
b720efd1 22my $dbh = $schema->storage->dbh;
23
24throws_ok (
25 sub {
26 $dbh->do ('INSERT INTO nonexistent_table VALUES (1)')
27 },
0007aedf 28 qr/DBI Exception.+no such table.+nonexistent_table/s,
b720efd1 29 'DBI exceptions properly handled by dbic-installed callback'
30);
31
68fe9141 32# This usage is a bit unusual but it was actually seen in the wild
b720efd1 33# destruction of everything except the $dbh should use the proper
34# exception fallback:
35
cc1924ac 36SKIP: {
0d8817bc 37 if (DBIx::Class::_ENV_::PEEPEENESS) {
cc1924ac 38 skip "Your perl version $] appears to leak like a sieve - skipping garbage collected \$schema test", 1;
39 }
40
b720efd1 41 undef ($schema);
42 throws_ok (
43 sub {
44 $dbh->do ('INSERT INTO nonexistent_table VALUES (1)')
45 },
0007aedf 46 qr/DBI Exception.+unhandled by DBIC.+no such table.+nonexistent_table/s,
b720efd1 47 'callback works after $schema is gone'
48 );
49}
50
56166f36 51done_testing;