more informative tests
Arthur Axel 'fREW' Schmidt [Tue, 1 Feb 2011 04:58:06 +0000 (22:58 -0600)]
Makefile.PL
lib/DBIx/Class/SQLMaker.pm
t/sqlmaker/op_dt.t

index 7fd81e6..2d2069b 100644 (file)
@@ -34,6 +34,7 @@ my $test_requires = {
   'File::Temp'               => '0.22',
   'Test::Builder'            => '0.33',
   'Test::Exception'          => '0.31',
+  'Test::Fatal'              => '0.003',
   'Test::More'               => '0.92',
   'Test::Warn'               => '0.21',
 
index 57d9216..4f794d2 100644 (file)
@@ -195,11 +195,11 @@ sub _where_op_CONVERT_DATETIME {
 }
 
 sub _unsupported_date_extraction {
-   "date part extraction not supported for part $_[1] with database $_[2]"
+   "date part extraction not supported for part \"$_[1]\" with database \"$_[2]\""
 }
 
 sub _unsupported_date_diff {
-   "date diff not supported for part $_[1] with database $_[2]"
+   "date diff not supported for part \"$_[1]\" with database \"$_[2]\""
 }
 
 sub _datetime_sql { die 'date part extraction not implemented for this database' }
index 22b0bec..b5bfb0f 100644 (file)
@@ -2,6 +2,7 @@ use strict;
 use warnings;
 
 use Test::More;
+use Test::Fatal;
 
 use lib qw(t/lib);
 use DBIC::SqlMakerTest;
@@ -31,6 +32,7 @@ is_same_sql_bind (
     WHERE artist.when_began = ?
   ",
   [['artist.when_began', '2010-12-14 12:12:12']],
+  '-dt works'
 );
 
 is_same_sql_bind (
@@ -46,6 +48,7 @@ is_same_sql_bind (
    ['artist.when_began', '2010-12-14 12:12:12'],
    ['artist.when_ended', '2010-12-16 12:12:12'],
   ],
+  '-dt works'
 );
 
 is_same_sql_bind (
@@ -54,7 +57,8 @@ is_same_sql_bind (
        { -op => [ '=', 12, { -dt_month => { -ident => 'artist.when_began' } } ] },
        { -op => [ '=', 2010, { -dt_get => [year => \'artist.when_began'] } ] },
        { -op => [ '=', 14, { -dt_get => [day_of_month => \'artist.when_began'] } ] },
-       { -op => [ '=', 10, { -dt_diff => [second => { -ident => 'artist.when_began' }, \'artist.when_ended'] } ] },
+       { -op => [ '=', 100, { -dt_diff => [second => { -ident => 'artist.when_began' }, \'artist.when_ended'] } ] },
+       { -op => [ '=', 10, { -dt_diff => [day => { -ident => 'artist.when_played_last' }, \'artist.when_ended'] } ] },
     ]
   } ) ],
   "SELECT *
@@ -63,15 +67,20 @@ is_same_sql_bind (
        ( ? = STRFTIME('%m', artist.when_began) ) AND
        ( ? = STRFTIME('%Y', artist.when_began) ) AND
        ( ? = STRFTIME('%d', artist.when_began) ) AND
-       ( ? = ( STRFTIME('%s', artist.when_began) - STRFTIME('%s', artist.when_ended)))
+       ( ? = ( STRFTIME('%s', artist.when_began) - STRFTIME('%s', artist.when_ended))) AND
+       ( ? = ( JULIANDAY(artist.when_played_last) - JULIANDAY(artist.when_ended)))
      ) )
   ",
   [
    ['', 12],
    ['', 2010],
    ['', 14],
+   ['', 100],
    ['', 10],
   ],
+  '-dt_month, -dt_get, and -dt_diff work'
 );
 
+like exception { $sql_maker->select('foo', '*', { -dt_diff => [year => \'artist.lololol', \'artist.fail'] }) }, qr/date diff not supported for part "year" with database "SQLite"/, 'SQLite does not support year diff';
+
 done_testing;