From: Arthur Axel 'fREW' Schmidt Date: Tue, 1 Feb 2011 04:58:06 +0000 (-0600) Subject: more informative tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6edb8b2f7c2fa0b7ce4ed80ea99ec2f830f3244c;p=dbsrgits%2FDBIx-Class.git more informative tests --- diff --git a/Makefile.PL b/Makefile.PL index 7fd81e6..2d2069b 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -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', diff --git a/lib/DBIx/Class/SQLMaker.pm b/lib/DBIx/Class/SQLMaker.pm index 57d9216..4f794d2 100644 --- a/lib/DBIx/Class/SQLMaker.pm +++ b/lib/DBIx/Class/SQLMaker.pm @@ -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' } diff --git a/t/sqlmaker/op_dt.t b/t/sqlmaker/op_dt.t index 22b0bec..b5bfb0f 100644 --- a/t/sqlmaker/op_dt.t +++ b/t/sqlmaker/op_dt.t @@ -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;