use Test::More;
use Test::Warn;
+use Test::Exception;
use lib qw(t/lib);
use DBICTest;
use Data::Dumper;
my $storage = $schema->storage;
$storage->ensure_connected;
-eval {
+throws_ok {
$schema->storage->throw_exception('test_exception_42');
-};
-like($@, qr/\btest_exception_42\b/, 'basic exception');
+} qr/\btest_exception_42\b/, 'basic exception';
-eval {
+throws_ok {
$schema->resultset('CD')->search_literal('broken +%$#$1')->all;
-};
-like($@, qr/prepare_cached failed/, 'exception via DBI->HandleError, etc');
+} qr/prepare_cached failed/, 'exception via DBI->HandleError, etc';
bless $storage, "DBICTest::ExplodingStorage";
$schema->storage($storage);
-eval {
+lives_ok {
$schema->resultset('Artist')->create({ name => "Exploding Sheep" });
-};
-
-is($@, "", "Exploding \$sth->execute was caught");
+} 'Exploding $sth->execute was caught';
is(1, $schema->resultset('Artist')->search({name => "Exploding Sheep" })->count,
"And the STH was retired");
plan tests => 1;
-# Set up the "usual" sqlite for DBICTest
+# Set up the "usual" sqlite for DBICTest and disconnect
my $normal_schema = DBICTest->init_schema( sqlite_use_file => 1 );
+$normal_schema->storage->disconnect;
# Steal the dsn, which should be like 'dbi:SQLite:t/var/DBIxClass.db'
-my $normal_dsn = $normal_schema->storage->_dbi_connect_info->[0];
-
-# Make sure we have no active connection
-$normal_schema->storage->disconnect;
+my @dsn = ($normal_schema->storage->_dbi_connect_info->[0], undef, undef, {
+ RaiseError => 1
+});
# Make a new clone with a new connection, using a code reference
-my $code_ref_schema = $normal_schema->connect(sub { DBI->connect($normal_dsn); });
+my $code_ref_schema = $normal_schema->connect(sub { DBI->connect(@dsn); });
# Stolen from 60core.t - this just verifies things seem to work at all
my @art = $code_ref_schema->resultset("Artist")->search({ }, { order_by => 'name DESC'});
use strict;
use warnings;
+# !!! do not replace this with done_testing - tests reside in the callbacks
+# !!! number of calls is important
use Test::More tests => 12;
+# !!!
+use Test::Exception;
use lib qw(t/lib);
use base 'DBICTest';
[ [ 2 ], [ 3 ], [ 7 ] ],
'on_connect_do() worked'
);
-eval { $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent'); };
-ok $@, 'Searching for nonexistent table dies';
+dies_ok {
+ $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent');
+} 'Searching for nonexistent table dies';
$schema->storage->disconnect();
sub check_dropped {
my $storage = shift;
- eval { $storage->dbh->do('SELECT 1 FROM TEST_empty'); };
- ok $@, 'Reading from dropped table fails';
+
+ dies_ok {
+ $storage->dbh->do('SELECT 1 FROM TEST_empty');
+ } 'Reading from dropped table fails';
return;
}