From: Peter Rabbitson Date: Mon, 29 Jun 2009 08:07:09 +0000 (+0000) Subject: Test cleanups X-Git-Tag: v0.08108~37^2~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a2287768f5c3dd665c469d7f9dfe99d369ff6781;p=dbsrgits%2FDBIx-Class.git Test cleanups --- diff --git a/t/31stats.t b/t/31stats.t index 9f0da40..4cd85a0 100644 --- a/t/31stats.t +++ b/t/31stats.t @@ -4,12 +4,7 @@ use strict; use warnings; use Test::More; -BEGIN { - eval "use DBD::SQLite"; - plan $@ - ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 12 ); -} +plan tests => 12; use lib qw(t/lib); diff --git a/t/83cache.t b/t/83cache.t index 45f50c1..f220a35 100644 --- a/t/83cache.t +++ b/t/83cache.t @@ -9,9 +9,8 @@ my $schema = DBICTest->init_schema(); my $queries; $schema->storage->debugcb( sub{ $queries++ } ); +my $sdebug = $schema->storage->debug; -eval "use DBD::SQLite"; -plan skip_all => 'needs DBD::SQLite for testing' if $@; plan tests => 23; my $rs = $schema->resultset("Artist")->search( @@ -53,7 +52,7 @@ $artist = $rs->first(); is( $queries, 1, 'revisiting a row does not issue a query when cache => 1' ); -$schema->storage->debug(0); +$schema->storage->debug($sdebug); my @a = $schema->resultset("Artist")->search( { }, @@ -99,7 +98,7 @@ is( $artist->count_related('cds'), 3, 'artist->count_related returns correct val is($queries, 1, 'only one SQL statement executed'); -$schema->storage->debug(0); +$schema->storage->debug($sdebug); # make sure related_resultset is deleted after object is updated $artist->set_column('name', 'New Name'); @@ -136,7 +135,7 @@ $artist = ($rs->all)[0]; is($queries, 1, 'only one SQL statement executed'); -$schema->storage->debug(0); +$schema->storage->debug($sdebug); my @objs; #$artist = $rs->find(1); @@ -185,5 +184,5 @@ $artist = $rs->find(1); is( $queries, 1, 'only one select statement on find with has_many prefetch on resultset' ); -$schema->storage->debug(0); +$schema->storage->debug($sdebug); diff --git a/t/86might_have.t b/t/86might_have.t index 81cbf84..8ebf7b8 100644 --- a/t/86might_have.t +++ b/t/86might_have.t @@ -8,14 +8,11 @@ use DBICTest; my $schema = DBICTest->init_schema(); my $queries; -#$schema->storage->debugfh(IO::File->new('t/var/temp.trace', 'w')); $schema->storage->debugcb( sub{ $queries++ } ); +my $sdebug = $schema->storage->debug; -eval "use DBD::SQLite"; -plan skip_all => 'needs DBD::SQLite for testing' if $@; plan tests => 2; - my $cd = $schema->resultset("CD")->find(1); $cd->title('test'); @@ -28,7 +25,7 @@ $cd->update; is($queries, 1, 'liner_notes (might_have) not prefetched - do not load liner_notes on update'); -$schema->storage->debug(0); +$schema->storage->debug($sdebug); my $cd2 = $schema->resultset("CD")->find(2, {prefetch => 'liner_notes'}); @@ -43,5 +40,4 @@ $cd2->update; is($queries, 1, 'liner_notes (might_have) prefetched - do not load liner_notes on update'); -$schema->storage->debug(0); - +$schema->storage->debug($sdebug); diff --git a/t/prefetch/grouped.t b/t/prefetch/grouped.t index 7fa6ca8..a0caecd 100644 --- a/t/prefetch/grouped.t +++ b/t/prefetch/grouped.t @@ -10,6 +10,7 @@ use DBIC::SqlMakerTest; plan 'no_plan'; my $schema = DBICTest->init_schema(); +my $sdebug = $schema->storage->debug; my $cd_rs = $schema->resultset('CD')->search ( { 'tracks.cd' => { '!=', undef } }, @@ -47,6 +48,7 @@ for ($cd_rs->all) { { my $query_cnt = 0; $schema->storage->debugcb ( sub { $query_cnt++ } ); + $schema->storage->debug (1); $track_rs->reset; while (my $collapsed_track = $track_rs->next) { @@ -57,6 +59,7 @@ for ($cd_rs->all) { is ($query_cnt, 0, 'No queries on prefetched titles'); $schema->storage->debugcb (undef); + $schema->storage->debug ($sdebug); } # Test sql by hand, as the sqlite db will simply paper over @@ -184,6 +187,7 @@ for ($cd_rs->all) { my $query_cnt = 0; $schema->storage->debugcb ( sub { $query_cnt++ } ); + $schema->storage->debug (1); is ($top_cd->get_column ('track_count'), 4, 'Track count fetched correctly'); is ($top_cd->tracks->count, 4, 'Count of prefetched tracks rs still correct'); @@ -196,4 +200,5 @@ for ($cd_rs->all) { is ($query_cnt, 0, 'No queries executed during prefetched data access'); $schema->storage->debugcb (undef); + $schema->storage->debug ($sdebug); } diff --git a/t/prefetch/multiple_hasmany.t b/t/prefetch/multiple_hasmany.t index 96d86c5..ca89d55 100644 --- a/t/prefetch/multiple_hasmany.t +++ b/t/prefetch/multiple_hasmany.t @@ -5,13 +5,13 @@ use Test::More; use Test::Exception; use lib qw(t/lib); use DBICTest; -use Data::Dumper; +use IO::File; plan tests => 10; my $schema = DBICTest->init_schema(); +my $sdebug = $schema->storage->debug; -use IO::File; # once the following TODO is complete, remove the 2 warning tests immediately # after the TODO block @@ -44,6 +44,9 @@ TODO: { ok(! $o_mm_warn, 'no warning on attempt to prefetch several same level has_many\'s (1 -> M + M)'); is($queries, 1, 'prefetch one->(has_many,has_many) ran exactly 1 query'); + $schema->storage->debugcb (undef); + $schema->storage->debug ($sdebug); + is($pr_tracks_count, $tracks_count, 'equal count of prefetched relations over several same level has_many\'s (1 -> M + M)'); for ($pr_tracks_rs, $tracks_rs) { @@ -79,6 +82,8 @@ TODO: { ok(! $m_o_mm_warn, 'no warning on attempt to prefetch several same level has_many\'s (M -> 1 -> M + M)'); is($queries, 1, 'prefetch one->(has_many,has_many) ran exactly 1 query'); + $schema->storage->debugcb (undef); + $schema->storage->debug ($sdebug); is($pr_tags_count, $tags_count, 'equal count of prefetched relations over several same level has_many\'s (M -> 1 -> M + M)'); diff --git a/t/prefetch/standard.t b/t/prefetch/standard.t index 56cf77d..ee4a9fa 100644 --- a/t/prefetch/standard.t +++ b/t/prefetch/standard.t @@ -6,19 +6,12 @@ use Test::Exception; use lib qw(t/lib); use DBICTest; use Data::Dumper; +use IO::File; my $schema = DBICTest->init_schema(); - my $orig_debug = $schema->storage->debug; -use IO::File; - -BEGIN { - eval "use DBD::SQLite"; - plan $@ - ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 45 ); -} +plan tests => 45; my $queries = 0; $schema->storage->debugcb(sub { $queries++; }); @@ -314,3 +307,5 @@ is($art_rs_pr->search_related('cds')->search_related('tracks')->first->title, is($queries, 0, 'chained search_related after has_many->has_many prefetch ran no queries'); +$schema->storage->debug($orig_debug); +$schema->storage->debugobj->callback(undef); diff --git a/t/relationship/core.t b/t/relationship/core.t index a55b296..26ecf9b 100644 --- a/t/relationship/core.t +++ b/t/relationship/core.t @@ -7,6 +7,7 @@ use lib qw(t/lib); use DBICTest; my $schema = DBICTest->init_schema(); +my $sdebug = $schema->storage->debug; plan tests => 78; @@ -57,7 +58,7 @@ is( $big_flop_cd->title, 'Big Flop', 'create_related ok' ); is($queries, 0, 'No SELECT made for belongs_to if key IS NULL'); $big_flop_cd->genre_inefficient; #should trigger a select query is($queries, 1, 'SELECT made for belongs_to if key IS NULL when undef_on_null_fk disabled'); - $schema->storage->debug(0); + $schema->storage->debug($sdebug); $schema->storage->debugcb(undef); } diff --git a/t/relationship/update_or_create_multi.t b/t/relationship/update_or_create_multi.t index e75fede..885b15c 100644 --- a/t/relationship/update_or_create_multi.t +++ b/t/relationship/update_or_create_multi.t @@ -8,9 +8,9 @@ use DBICTest; use DBIC::SqlMakerTest; my $schema = DBICTest->init_schema(); +my $sdebug = $schema->storage->debug; -#plan tests => 4; -plan 'no_plan'; +plan tests => 6; my $artist = $schema->resultset ('Artist')->first; @@ -74,6 +74,7 @@ $genre->update_or_create_related ('cds', { }); $schema->storage->debugcb(undef); +$schema->storage->debug ($sdebug); is_same_sql ( $sql[0], diff --git a/t/relationship/update_or_create_single.t b/t/relationship/update_or_create_single.t index 63ae4b1..1675525 100644 --- a/t/relationship/update_or_create_single.t +++ b/t/relationship/update_or_create_single.t @@ -7,8 +7,7 @@ use DBICTest; my $schema = DBICTest->init_schema(); -#plan tests => 4; -plan 'no_plan'; +plan tests => 9; my $artist = $schema->resultset ('Artist')->first;