X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Finflate%2Fdatetime_sybase_asa.t;h=c05f22914c974633466c2aedc9ed5e1481362179;hb=68de943862f06cabd397d2e74d12cd9cdc999779;hp=761234df091b0adda22ea46b605f1344c279fc6d;hpb=51b1115faef9175029be549c017f8b7040312459;p=dbsrgits%2FDBIx-Class.git diff --git a/t/inflate/datetime_sybase_asa.t b/t/inflate/datetime_sybase_asa.t index 761234d..c05f229 100644 --- a/t/inflate/datetime_sybase_asa.t +++ b/t/inflate/datetime_sybase_asa.t @@ -3,6 +3,7 @@ use warnings; use Test::More; use Test::Exception; +use Scope::Guard (); use lib qw(t/lib); use DBICTest; @@ -15,32 +16,30 @@ Set $ENV{DBICTEST_SYBASE_ASA_DSN} and/or $ENV{DBICTEST_SYBASE_ASA_ODBC_DSN} _USER and _PASS to run this test'. Warning: This test drops and creates a table called 'track'"; EOF -} else { - eval "use DateTime; use DateTime::Format::Strptime;"; - if ($@) { - plan skip_all => 'needs DateTime and DateTime::Format::Strptime for testing'; - } } +plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt') + unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt'); + my @info = ( [ $dsn, $user, $pass ], [ $dsn2, $user2, $pass2 ], ); -my @handles_to_clean; +my $schema; foreach my $info (@info) { my ($dsn, $user, $pass) = @$info; next unless $dsn; - my $schema = DBICTest::Schema->clone; + $schema = DBICTest::Schema->clone; $schema->connection($dsn, $user, $pass, { on_connect_call => [ 'datetime_setup' ], }); - push @handles_to_clean, $schema->storage->dbh; + my $sg = Scope::Guard->new(\&cleanup); # coltype, col, date my @dt_types = ( @@ -72,7 +71,7 @@ SQL ->search({ trackid => $row->trackid }, { select => [$col] }) ->first ); - is( $row->$col, $dt, 'DateTime roundtrip' ); + is( $row->$col, $dt, "$type roundtrip" ); is $row->$col->nanosecond, $dt->nanosecond, 'nanoseconds survived' if 0+$dt->nanosecond; @@ -82,8 +81,8 @@ SQL done_testing; # clean up our mess -END { - foreach my $dbh (@handles_to_clean) { +sub cleanup { + if (my $dbh = $schema->storage->dbh) { eval { $dbh->do("DROP TABLE $_") } for qw/track/; } }