use Test::More;
use Test::Exception;
+use Scope::Guard ();
use lib qw(t/lib);
use DBICTest;
_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 = (
- ['TIMESTAMP', 'last_updated_at', '2004-08-21 14:36:48.080444'],
+ ['TIMESTAMP', 'last_updated_at', '2004-08-21 14:36:48.080445'],
# date only (but minute precision according to ASA docs)
['DATE', 'small_dt', '2004-08-21 00:00:00.000000'],
);
->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;
}
}
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/;
}
}