Author: petdance
Date: Tue May 11 09:29:44 2004
New Revision: 337

Modified:
   dbi/trunk/t/41prof_dump.t
   dbi/trunk/t/42prof_data.t
Log:
Updated tests to use Test::More.  Added -T flags.

Modified: dbi/trunk/t/41prof_dump.t
==============================================================================
--- dbi/trunk/t/41prof_dump.t   (original)
+++ dbi/trunk/t/41prof_dump.t   Tue May 11 09:29:44 2004
@@ -1,4 +1,4 @@
-#!perl -w
+#!perl -Tw
 use strict;
 
 #
@@ -6,7 +6,6 @@
 # 
 
 use DBI;
-use DBI::ProfileDumper;
 
 BEGIN {
     if ($DBI::PurePerl) {
@@ -15,22 +14,25 @@
     }
 }
 
-use Test;
-BEGIN { plan tests => 7; }
+BEGIN {
+    use Test::More;
 
-use Data::Dumper;
-$Data::Dumper::Indent = 1;
-$Data::Dumper::Terse = 1;
+    plan tests => 11;
+    use_ok( 'DBI' );
+    use_ok( 'DBI::ProfileDumper' );
+}
 
 my $dbh = DBI->connect("dbi:ExampleP:", '', '', 
                        { RaiseError=>1, Profile=>"DBI::ProfileDumper" });
-ok(ref $dbh->{Profile}, "DBI::ProfileDumper");
-ok(ref $dbh->{Profile}{Data}, 'HASH');
-ok(ref $dbh->{Profile}{Path}, 'ARRAY');
+isa_ok( $dbh, 'DBI::db' );
+isa_ok( $dbh->{Profile}, "DBI::ProfileDumper" );
+isa_ok( $dbh->{Profile}{Data}, 'HASH' );
+isa_ok( $dbh->{Profile}{Path}, 'ARRAY' );
 
 # do a little work
 my $sql = "select mode,size,name from ?";
 my $sth = $dbh->prepare($sql);
+isa_ok( $sth, 'DBI::st' );
 $sth->execute(".");
 
 $sth->{Profile}->flush_to_disk();
@@ -42,21 +44,22 @@
 undef $dbh;
 
 # wrote the profile to disk?
-ok(-s "dbi.prof");
+ok( -s "dbi.prof", 'Profile is on disk and nonzero size' );
 
 open(PROF, "dbi.prof") or die $!;
 my $prof = join('', <PROF>);
 close PROF;
 
 # has a header?
-ok($prof =~ /^DBI::ProfileDumper\s+([\d.]+)/);
+ok( $prof =~ /^DBI::ProfileDumper\s+([\d.]+)/, 'Found a version number' );
+# Can't use like() because we need $1
 
 # version matches VERSION? (DBI::ProfileDumper uses $self->VERSION so
 # it's a stringified version object that looks like N.N.N)
-ok($1, DBI::ProfileDumper->VERSION);
+is( $1, DBI::ProfileDumper->VERSION, 'Version numbers match' );
 
 # check that expected key is there
-ok($prof =~ /\+\s+1\s+\Q$sql\E/m);
+like($prof, qr/\+\s+1\s+\Q$sql\E/m);
 
 # unlink("dbi.prof"); # now done by 'make clean'
 

Modified: dbi/trunk/t/42prof_data.t
==============================================================================
--- dbi/trunk/t/42prof_data.t   (original)
+++ dbi/trunk/t/42prof_data.t   Tue May 11 09:29:44 2004
@@ -1,13 +1,7 @@
 #!perl -w
 use strict;
 
-#
-# test script for DBI::ProfileData
-# 
-
 use DBI;
-use DBI::ProfileDumper;
-use DBI::ProfileData;
 
 BEGIN {
     if ($DBI::PurePerl) {
@@ -16,21 +10,23 @@
     }
 }
 
-use Test;
-BEGIN { plan tests => 18; }
-
-use Data::Dumper;
-$Data::Dumper::Indent = 1;
-$Data::Dumper::Terse = 1;
+BEGIN {
+    use Test::More;
+    plan tests=>32;
+    use_ok( 'DBI::ProfileDumper' );
+    use_ok( 'DBI::ProfileData' );
+}
 
 my $sql = "select mode,size,name from ?";
 
 my $dbh = DBI->connect("dbi:ExampleP:", '', '', 
                        { RaiseError=>1, Profile=>"6/DBI::ProfileDumper" });
+isa_ok( $dbh, 'DBI::db', 'Created connection' );
 
 # do a little work
 foreach (1,2,3) {
   my $sth = $dbh->prepare($sql);
+  isa_ok( $sth, 'DBI::st', 'Created handle' );
   for my $loop (1..20) {  
     $sth->execute(".");
     $sth->fetchrow_hashref;
@@ -43,14 +39,12 @@
 
 
 # wrote the profile to disk?
-ok(-s "dbi.prof");
+ok(-s "dbi.prof", "Profile written to disk, non-zero size" );
 
 # load up
 my $prof = DBI::ProfileData->new();
-ok($prof);
-ok(ref $prof eq 'DBI::ProfileData');
-
-ok($prof->count() >= 3);
+isa_ok( $prof, 'DBI::ProfileData' );
+cmp_ok( $prof->count, '>=', 3, 'At least 3 profile data items' );
 
 # try a few sorts
 my $nodes = $prof->nodes;
@@ -58,16 +52,17 @@
 my $longest = $nodes->[0][4];
 ok($longest);
 $prof->sort(field => "longest", reverse => 1);
-ok($nodes->[0][4] < $longest);
+cmp_ok( $nodes->[0][4], '<', $longest );
 
 $prof->sort(field => "count");
 my $most = $nodes->[0];
 ok($most);
 $prof->sort(field => "count", reverse => 1);
-ok($nodes->[0][0] < $most->[0]);
+cmp_ok( $nodes->[0][0], '<', $most->[0] );
 
 # remove the top count and make sure it's gone
 my $clone = $prof->clone();
+isa_ok( $clone, 'DBI::ProfileData' );
 $clone->sort(field => "count");
 ok($clone->exclude(key1 => $most->[7]));
 
@@ -78,6 +73,7 @@
 
 # there can only be one
 $clone = $prof->clone();
+isa_ok( $clone, 'DBI::ProfileData' );
 ok($clone->match(key1 => $clone->nodes->[0][7]));
 ok($clone->match(key2 => $clone->nodes->[0][8]));
 ok($clone->count == 1);
@@ -90,6 +86,7 @@
 # test escaping of \n and \r in keys
 $dbh = DBI->connect("dbi:ExampleP:", '', '', 
                     { RaiseError=>1, Profile=>"6/DBI::ProfileDumper" });
+isa_ok( $dbh, 'DBI::db', 'Created connection' );
 
 my $sql2 = 'select size from . where name = "LITERAL: \r\n"';
 my $sql3 = "select size from . where name = \"EXPANDED: \r\n\"";
@@ -97,10 +94,12 @@
 # do a little work
 foreach (1,2,3) {
   my $sth2 = $dbh->prepare($sql2);
+  isa_ok( $sth2, 'DBI::st' );
   $sth2->execute();
   $sth2->fetchrow_hashref;
   $sth2->finish;
   my $sth3 = $dbh->prepare($sql3);
+  isa_ok( $sth3, 'DBI::st' );
   $sth3->execute();
   $sth3->fetchrow_hashref;
   $sth3->finish;
@@ -109,7 +108,7 @@
 
 # load dbi.prof
 $prof = DBI::ProfileData->new();
-ok($prof and ref $prof eq 'DBI::ProfileData');
+isa_ok( $prof, 'DBI::ProfileData' );
 
 # make sure the keys didn't get garbled
 $Data = $prof->Data;

Reply via email to