Massive cleanup of DateTime test dependencies, other interim
[dbsrgits/DBIx-Class.git] / t / inflate / datetime_sybase_asa.t
index 5a20da0..c05f229 100644 (file)
@@ -3,6 +3,7 @@ use warnings;
 
 use Test::More;
 use Test::Exception;
+use Scope::Guard ();
 use lib qw(t/lib);
 use DBICTest;
 
@@ -15,36 +16,34 @@ 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 = (
-    ['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'],
   );
@@ -72,15 +71,18 @@ 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;
   }
 }
 
 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/;
   }
 }