From: Peter Rabbitson Date: Wed, 19 Jan 2011 11:13:32 +0000 (+0100) Subject: Cleanup some of the storage tests (no func. changes) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f3d405dcdbcc0645ad304387a945d36d869a5aca;p=dbsrgits%2FDBIx-Class-Historic.git Cleanup some of the storage tests (no func. changes) --- diff --git a/t/storage/base.t b/t/storage/base.t index c0bde46..6b25576 100644 --- a/t/storage/base.t +++ b/t/storage/base.t @@ -3,6 +3,7 @@ use warnings; use Test::More; use Test::Warn; +use Test::Exception; use lib qw(t/lib); use DBICTest; use Data::Dumper; @@ -42,24 +43,20 @@ is( ref($schema->storage), 'DBIx::Class::Storage::DBI::SQLite', 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"); diff --git a/t/storage/dbi_coderef.t b/t/storage/dbi_coderef.t index 84a0dbc..b5b7961 100644 --- a/t/storage/dbi_coderef.t +++ b/t/storage/dbi_coderef.t @@ -7,17 +7,17 @@ use DBICTest; 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'}); diff --git a/t/storage/on_connect_do.t b/t/storage/on_connect_do.t index ca13d6c..31d39c6 100644 --- a/t/storage/on_connect_do.t +++ b/t/storage/on_connect_do.t @@ -1,7 +1,11 @@ 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'; @@ -46,8 +50,9 @@ is_deeply ( [ [ 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(); @@ -75,8 +80,10 @@ sub check_exists { 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; }