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