List:Commits« Previous MessageNext Message »
From:capttofu Date:May 10 2008 1:41pm
Subject:[svn:DBD-mysql] r11233 - DBD-mysql/trunk/t
View as plain text  
Author: capttofu
Date: Sat May 10 04:41:18 2008
New Revision: 11233

Modified:
   DBD-mysql/trunk/t/35limit.t
   DBD-mysql/trunk/t/71impdata.t
   DBD-mysql/trunk/t/75supported_sql.t
   DBD-mysql/trunk/t/80procs.t
   DBD-mysql/trunk/t/insertid.t
   DBD-mysql/trunk/t/multi_statement.t
   DBD-mysql/trunk/t/param_values.t

Log:
In process of re-writing test suit to use Test::More


Modified: DBD-mysql/trunk/t/35limit.t
==============================================================================
--- DBD-mysql/trunk/t/35limit.t	(original)
+++ DBD-mysql/trunk/t/35limit.t	Sat May 10 04:41:18 2008
@@ -18,8 +18,7 @@
 eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password,
                       { RaiseError => 1, PrintError => 1, AutoCommit => 0 });};
 if ($@) {
-    plan skip_all => 
-        "ERROR: $DBI::errstr. Can't continue test";
+    plan skip_all => "ERROR: $@. Can't continue test";
 }
 plan tests => 111; 
 

Modified: DBD-mysql/trunk/t/71impdata.t
==============================================================================
--- DBD-mysql/trunk/t/71impdata.t	(original)
+++ DBD-mysql/trunk/t/71impdata.t	Sat May 10 04:41:18 2008
@@ -8,14 +8,15 @@
 
 use Test::More;
 
-our ($mdriver, $test_dsn, $test_user, $test_password);
+use vars qw($test_dsn $test_user $test_password);
 
-my $dbh    = DBI->connect( $test_dsn, $test_user, $test_password);
+my $dbh;
+eval {$dbh= DBI->connect( $test_dsn, $test_user, $test_password);};
+if ($@) {
+    plan skip_all => "$@. Can't continue test";
+}
 
 my $drh    = $dbh->{Driver};
-if (! defined $dbh) {
-    plan skip_all => "Can't connect to database. Can't continue test";
-}
 if (! defined $drh) {
     plan skip_all => "Can't obtain driver handle. Can't continue test";
 }
@@ -23,7 +24,10 @@
 unless ($dbh->can('take_imp_data')) {
     plan skip_all => "version of DBI $DBI::VERSION doesn't support this test. Can't
continue test";
 }
-plan tests => 8;
+plan tests => 10;
+
+pass("Connected to database");
+pass("Obtained driver handle");
 
 my $connection_id1 = connection_id($dbh);
 

Modified: DBD-mysql/trunk/t/75supported_sql.t
==============================================================================
--- DBD-mysql/trunk/t/75supported_sql.t	(original)
+++ DBD-mysql/trunk/t/75supported_sql.t	Sat May 10 04:41:18 2008
@@ -1,95 +1,51 @@
-#!/usr/bin/perl
+#!perl -w
 
 use strict;
-use vars qw($state $test_dsn $test_user $test_password $mdriver $dbdriver);
-use DBI;
+use vars qw($table $test_dsn $test_user $test_password);
 use Carp qw(croak);
-use Data::Dumper;
-$^W =1;
+use DBI ();
+use Test::More;
+use lib 't', '.';
+require 'lib.pl';
 
-use DBI;
-$mdriver = "";
 my ($row, $vers, $test_procs);
-foreach my $file ("lib.pl", "t/lib.pl", "DBD-mysql/t/lib.pl") {
-  do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
-    exit 10;
-  }
-  if ($mdriver ne '') {
-    last;
-  }
-}
-
-sub ServerError() {
-    print STDERR ("Cannot connect: ", $DBI::errstr, "\n",
-	"\tEither your server is not up and running or you have no\n",
-	"\tpermissions for acessing the DSN $test_dsn.\n",
-	"\tThis test requires a running server and write permissions.\n",
-	"\tPlease make sure your server is running and you have\n",
-	"\tpermissions, then retry.\n");
-    exit 10;
-}
 
-while(Testing())
-{
-  my ($table, $errstr);
-  Test($state or my $dbh = DBI->connect($test_dsn, $test_user, $test_password,
-  { RaiseError => 1, AutoCommit => 1})) or ServerError() ;
+my $dbh;
+eval {$dbh = DBI->connect($test_dsn, $test_user, $test_password,
+  { RaiseError => 1, AutoCommit => 1})};
 
-  $table="t1";
+if ($@) {
+  plan skip_all => "ERROR: $DBI::errstr. Can't continue test";
+}
+plan tests => 10; 
 
-  Test($state or $dbh->do("DROP TABLE IF EXISTS $table")) or
-    DbiError($dbh->err, $dbh->errstr);
+ok $dbh->do("DROP TABLE IF EXISTS $table");
 
-  Test($state or my $sth= $dbh->prepare("
+my $create = <<EOT;
 CREATE TABLE $table (
-  id INT,
+  id INT(4),
   name VARCHAR(32)
-  )")) or
-    DbiError($dbh->err, $dbh->errstr);
+  )
+EOT
 
-  Test($state or ($sth->execute())) or 
-    DbiError($dbh->err, $dbh->errstr);
+ok $dbh->do($create),"create $table";
 
-  Test($state or
-    $sth= $dbh->prepare("SHOW TABLES LIKE '$table'"))
-    or DbiError($dbh->err, $dbh->errstr);
-
-  Test($state or $sth->execute())
-	   or DbiError($dbh->err, $dbh->errstr);
-  Test(
-    $state or 
-    (defined($row= $sth->fetchrow_arrayref)  &&
-    (!defined($errstr= $sth->errstr) || $sth->errstr eq '')))
-         or DbiError($sth->err, $sth->errstr);
-
-  Test ($state or ($row->[0] eq "$table")) 
-      or print "results not equal to '$table' \n";
-
-  Test($state or
-    $sth= $dbh->prepare("DROP TABLE $table")) or
-    DbiError($dbh->err, $dbh->errstr);
-
-  Test($state or $sth->execute()) or 
-    DbiError($dbh->err, $dbh->errstr);
-
-  Test($state or
-    $sth=$dbh->prepare("CREATE TABLE $table (a int)")) or
-    DbiError($dbh->err, $dbh->errstr);
-
-  Test($state or $sth->execute()) or 
-    DbiError($dbh->err, $dbh->errstr);
-
-  Test($state or
-    $sth= $dbh->prepare("ALTER TABLE $table ADD COLUMN b varchar(31)")) or
-    DbiError($dbh->err, $dbh->errstr);
-
-  Test($state or $sth->execute()) or 
-    DbiError($dbh->err, $dbh->errstr);
-
-  Test($state or
-    $sth = $dbh->prepare("DROP TABLE $table")) or
-    DbiError($dbh->err, $dbh->errstr);
+my $sth= $dbh->prepare("SHOW TABLES LIKE '$table'") or die "$DBI::errstr";
 
-  Test($state or $sth->execute()) or 
-    DbiError($dbh->err, $dbh->errstr);
-}
+ok $sth->execute();
+
+$row= $sth->fetchrow_arrayref or die "$DBI::errstr";
+
+cmp_ok $row->[0], 'eq', $table, "\$row->[0] eq $table";
+
+ok $sth->finish;
+
+ok $dbh->do("DROP TABLE $table"), "drop $table";
+
+ok $dbh->do("CREATE TABLE $table (a int)"), "creating $table again with 1 col";
+
+ok $dbh->do("ALTER TABLE $table ADD COLUMN b varchar(31)"), "alter $table ADD COLUMN";
+
+ok $dbh->do("DROP TABLE $table"), "drop $table";
+
+ok $dbh->disconnect;

Modified: DBD-mysql/trunk/t/80procs.t
==============================================================================
--- DBD-mysql/trunk/t/80procs.t	(original)
+++ DBD-mysql/trunk/t/80procs.t	Sat May 10 04:41:18 2008
@@ -1,86 +1,48 @@
-#!/usr/bin/perl
+#!perl -w
 
 use strict;
-use vars qw($test_dsn $test_user $test_password $mdriver $state);
+use lib 't', '.';
+require 'lib.pl';
 use DBI;
+use DBI::Const::GetInfoType;
+use Test::More;
 use Carp qw(croak);
-use Data::Dumper;
-$^W =1;
+use vars qw($table $test_dsn $test_user $test_password);
 
-use DBI;
-$mdriver = "";
 my ($row, $vers, $test_procs, $dbh, $sth);
-foreach my $file ("lib.pl", "t/lib.pl", "DBD-mysql/t/lib.pl") {
-  do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
-    exit 10;
-  }
-  if ($mdriver ne '') {
-    last;
-  }
-}
+eval {$dbh = DBI->connect($test_dsn, $test_user, $test_password,
+  { RaiseError => 1, AutoCommit => 1})};
 
-sub ServerError() {
-    print STDERR ("Cannot connect: ", $DBI::errstr, "\n",
-	"\tEither your server is not up and running or you have no\n",
-	"\tpermissions for acessing the DSN $test_dsn.\n",
-	"\tThis test requires a running server and write permissions.\n",
-	"\tPlease make sure your server is running and you have\n",
-	"\tpermissions, then retry.\n");
-    exit 10;
+if ($@) {
+    plan skip_all => 
+        "ERROR: $DBI::errstr. Can't continue test";
 }
 
-$dbh = DBI->connect($test_dsn, $test_user, $test_password,
-  { RaiseError => 1, AutoCommit => 1}) or ServerError() ;
-
-$sth= $dbh->prepare("select version()") or
-  DbiError($dbh->err, $dbh->errstr);
-
-$sth->execute() or 
-  DbiError($dbh->err, $dbh->errstr);
-
-$row= $sth->fetchrow_arrayref() or
-  DbiError($dbh->err, $dbh->errstr);
-
 # 
 # DROP/CREATE PROCEDURE will give syntax error 
-# for these versions
+# for versions < 5.0
 #
-if ($row->[0] =~ /^5/)
-{
-  $test_procs= 1;
+if ($dbh->get_info($GetInfoType{SQL_DBMS_VER}) lt "5.0") {
+    plan skip_all => 
+        "SKIP TEST: You must have MySQL version 5.0 and greater for this test to run";
 }
-$sth->finish();
-$dbh->disconnect();
+plan tests => 24;
 
-if (! $test_procs)
-{
-  print "1..0 # Skip MySQL Server version $row->[0] doesn't support stored
procedures\n";
-  exit(0);
-}
+$dbh->disconnect();
 
-while(Testing())
-{
-  my ($table, $rows);
-  Test($state or $dbh = DBI->connect($test_dsn, $test_user, $test_password,
-  { RaiseError => 1, AutoCommit => 1})) or ServerError() ;
+$dbh = DBI->connect($test_dsn, $test_user, $test_password,
+  { RaiseError => 1, AutoCommit => 1}) or die "$DBI::errstr";
 
-  # don't want this during make test!
+ok defined($dbh);
 
-  $table= 't1';
-  Test($state or $dbh->do("DROP TABLE IF EXISTS $table"))
-    or DbiError($dbh->err, $dbh->errstr);
+ok $dbh->do("DROP TABLE IF EXISTS $table");
 
-  my $drop_proc= "DROP PROCEDURE IF EXISTS testproc";
-  Test($state or ($sth = $dbh->prepare($drop_proc))) or
-    DbiError($dbh->err, $dbh->errstr);
+my $drop_proc= "DROP PROCEDURE IF EXISTS testproc";
 
-  Test($state or ($sth->execute())) or 
-    DbiError($dbh->err, $dbh->errstr);
+ok $dbh->do($drop_proc);
 
-  Test($state or ($sth= $dbh->do($drop_proc))) or 
-    DbiError($dbh->err, $dbh->errstr);
 
-  my $proc_create = <<EOPROC;
+my $proc_create = <<EOPROC;
 create procedure testproc() deterministic
   begin
     declare a,b,c,d int;
@@ -95,100 +57,73 @@
   end
 EOPROC
 
-  Test($state or $sth = $dbh->prepare($proc_create)) or
-    DbiError($dbh->err, $dbh->errstr);
-
-  Test($state or $sth->execute()) or 
-    DbiError($dbh->err, $dbh->errstr);
-
-
-    my $proc_call = 'CALL testproc()';
-    Test($state or $sth = $dbh->prepare($proc_call)) or
-    DbiError($dbh->err, $dbh->errstr);
-
-    Test($state or $sth->execute()) or 
-      DbiError($dbh->err, $dbh->errstr);
+ok $dbh->do($proc_create);
 
-    $sth->finish;
+my $proc_call = 'CALL testproc()';
 
-    my $proc_select = 'SELECT @a';
-    Test($state or $sth = $dbh->prepare($proc_select)) or
-    DbiError($dbh->err, $dbh->errstr);
+ok $dbh->do($proc_call);
 
-    Test($state or $sth->execute()) or 
-      DbiError($dbh->err, $dbh->errstr);
+my $proc_select = 'SELECT @a';
+$sth = $dbh->prepare($proc_select) or die "$DBI::errstr";
 
-    $sth->finish;
+ok $sth->execute();
 
-  Test($state or ($sth=$dbh->prepare("DROP PROCEDURE testproc"))) or
-    DbiError($dbh->err, $dbh->errstr);
+ok $sth->finish;
 
-  Test($state or $sth->execute()) or 
-    DbiError($dbh->err, $dbh->errstr);
+ok $dbh->do("DROP PROCEDURE testproc");
 
-  Test($state or $dbh->do("drop procedure if exists test_multi_sets")) or
-    DbiError($dbh->err, $dbh->errstr);
+ok $dbh->do("drop procedure if exists test_multi_sets");
 
-  Test($state or $dbh->do("
+$proc_create = <<EOT;
         create procedure test_multi_sets ()
         deterministic
         begin
         select user() as first_col;
         select user() as first_col, now() as second_col;
         select user() as first_col, now() as second_col, now() as third_col;
-        end")) or
-    DbiError($dbh->err, $dbh->errstr);
+        end
+EOT
 
+ok $dbh->do($proc_create);
 
-  Test($state or $sth = $dbh->prepare("call test_multi_sets()")) or
-    DbiError($dbh->err, $dbh->errstr);
+$sth = $dbh->prepare("call test_multi_sets()") or die "$DBI::errstr";
 
-  Test($state or $rows = $sth->execute()) or 
-    DbiError($dbh->err, $dbh->errstr);
+ok $sth->execute();
 
-  my $dataset;
+cmp_ok $sth->{NUM_OF_FIELDS}, '==', 1, "num_of_fields == 1";
 
-  Test($state or ($sth->{NUM_OF_FIELDS} == 1)) or
-    DbiError($dbh->err, $dbh->errstr);
-
-  Test($state or $dataset = $sth->fetchrow_arrayref()) or 
-    DbiError($dbh->err, $dbh->errstr);
+my $resultset = $sth->fetchrow_arrayref() or die "$DBI::errstr";
   
-  Test($state or ($dataset && @$dataset == 1)) or
-    DbiError($dbh->err, $dbh->errstr);
+ok defined $resultset;
 
-  my $more_results;
+cmp_ok @$resultset, '==', 1, "1 row in resultset";
 
-  Test($state or $more_results =  $sth->more_results()) or
-    DbiError($dbh->err, $dbh->errstr);
+undef $resultset;
 
-  Test($state or ($sth->{NUM_OF_FIELDS} == 2)) or
-    DbiError($dbh->err, $dbh->errstr);
+ok $sth->more_results();
 
-  Test($state or $dataset = $sth->fetchrow_arrayref()) or
-    DbiError($dbh->err, $dbh->errstr);
+cmp_ok $sth->{NUM_OF_FIELDS}, '==', 2, "NUM_OF_FIELDS == 2";
 
-  Test($state or ($dataset && @$dataset == 2)) or
-    DbiError($dbh->err, $dbh->errstr);
+$resultset= $sth->fetchrow_arrayref() or die "$DBI::errstr";
 
-  Test($state or $more_results =  $sth->more_results()) or
-    DbiError($dbh->err, $dbh->errstr);
+ok defined $resultset;
 
-  Test($state or ($sth->{NUM_OF_FIELDS} == 3)) or
-    DbiError($dbh->err, $dbh->errstr);
+cmp_ok @$resultset, '==', 2, "2 rows in resultset";
 
-  Test($state or $dataset = $sth->fetchrow_arrayref()) or
-    DbiError($dbh->err, $dbh->errstr);
+undef $resultset;
 
-  Test($state or ($dataset && @$dataset == 3)) or
-    DbiError($dbh->err, $dbh->errstr);
+ok $sth->more_results();
 
-  Test($state or !($more_results =  $sth->more_results())) or
-    DbiError($dbh->err, $dbh->errstr);
+cmp_ok $sth->{NUM_OF_FIELDS}, '==', 3, "NUM_OF_FIELDS == 3";
 
-  local $SIG{__WARN__} = sub { die @_ };
+$resultset= $sth->fetchrow_arrayref() or die "$DBI::errstr";
 
-  Test($state or $dbh->disconnect()) or 
-    DbiError($dbh->err, $dbh->errstr);
+ok defined $resultset;
 
-}
+cmp_ok @$resultset, '==', 3, "3 Rows in resultset";
+
+local $SIG{__WARN__} = sub { die @_ };
+
+ok $sth->finish;
+
+ok $dbh->disconnect();

Modified: DBD-mysql/trunk/t/insertid.t
==============================================================================
--- DBD-mysql/trunk/t/insertid.t	(original)
+++ DBD-mysql/trunk/t/insertid.t	Sat May 10 04:41:18 2008
@@ -2,66 +2,65 @@
 
 use strict;
 use DBI ();
+use Test::More;
+use Data::Dumper;
 
-use vars qw($test_dsn $test_user $test_password $state);
-require "t/lib.pl";
+use vars qw($table $test_dsn $test_user $test_password);
+use lib 't', '.';
+require "lib.pl";
 
-while (Testing()) {
-  my ($dbh, $sth, $sth2);
-  my $max_id;
-  #
-  # Connect to the database
-  Test($state or
-       ($dbh = DBI->connect($test_dsn, $test_user, $test_password,
-			    {RaiseError => 1})));
-
-  #
-  # Find a possible new table name
-  #
-  my $table = "t1";
-  # Drop the table
-  Test($state or $dbh->do("DROP TABLE IF EXISTS $table"));
-
-  #
-  # Create a new table
-  #
-  my $q = <<"QUERY";
-CREATE TABLE $table (id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
-                     name VARCHAR(64))
-QUERY
-  Test($state or $dbh->do($q));
-
-  #
-  # Insert a row
-  #
-  $q = "INSERT INTO $table (name) VALUES (?)";
-  Test($state or $dbh->do($q, undef, "Jochen"));
-
-  #
-  # Verify $dbh->insertid
-  Test($state or ($dbh->{'mysql_insertid'} eq "1"));
-
-  #
-  # Insert another row
-  #
-  Test($state or ($sth = $dbh->prepare($q)));
-  Test($state or $sth->execute());
-  Test($state or ($sth2= $dbh->prepare("SELECT max(id) FROM $table"))); 
-  Test($state or $sth2->execute());
-  Test($state or ($max_id= $sth2->fetch()));
-  # IMPORTANT: this will fail if you are using replication with
-  # an offset and auto_increment_increment, where your 
-  # auto_increment values are stepped (ex: 1, 11, 21, ...)
-  Test($state or $sth->{'mysql_insertid'} == $max_id->[0]);
-  Test($state or $dbh->{'mysql_insertid'} == $max_id->[0]);
-  Test($state or $sth->finish());
-  Test($state or $sth2->finish());
-
-  #
-  # Drop the table
-  Test($state or $dbh->do("DROP TABLE $table"));
-
-  #
-  # Close the database connection
-  Test($state or ($dbh->disconnect() or 1));
+my $dbh;
+
+eval{$dbh = DBI->connect($test_dsn, $test_user, $test_password,
+			    {RaiseError => 1});};
+
+if ($@) {
+    plan skip_all => 
+        "ERROR: $DBI::errstr. Can't continue test";
 }
+plan tests => 15; 
+
+ok $dbh->do("DROP TABLE IF EXISTS $table");
+
+my $create = <<EOT;
+CREATE TABLE $table (
+  id INT(3) PRIMARY KEY AUTO_INCREMENT NOT NULL,
+  name VARCHAR(64))
+EOT
+
+ok $dbh->do($create), "create $table";
+
+my $query= "INSERT INTO $table (name) VALUES (?)";
+
+my $sth= $dbh->prepare($query) or die "$DBI::errstr";
+
+ok defined $sth;
+
+ok $sth->execute("Jochen");
+
+cmp_ok $dbh->{'mysql_insertid'}, '==', 1, "insert id == $dbh->{mysql_insertid}";
+
+ok $sth->execute("Patrick");
+
+my $sth2= $dbh->prepare("SELECT max(id) FROM $table") or die "$DBI::errstr";
+
+ok defined $sth2;
+
+ok $sth2->execute();
+
+my $max_id= $sth2->fetch() or die "$DBI::errstr";
+
+ok defined $max_id;
+
+cmp_ok $sth->{'mysql_insertid'}, '==', $max_id->[0], "sth insert id
$sth->{'mysql_insertid'} == max(id) $max_id->[0]  in $table";
+
+cmp_ok $dbh->{'mysql_insertid'}, '==', $max_id->[0], "dbh insert id
$dbh->{'mysql_insertid'} == max(id) $max_id->[0] in $table";
+
+
+ok $sth->finish();
+
+ok $sth2->finish();
+
+ok $dbh->do("DROP TABLE $table");
+
+ok $dbh->disconnect();

Modified: DBD-mysql/trunk/t/multi_statement.t
==============================================================================
--- DBD-mysql/trunk/t/multi_statement.t	(original)
+++ DBD-mysql/trunk/t/multi_statement.t	Sat May 10 04:41:18 2008
@@ -1,26 +1,26 @@
 #!perl -w
 # vim: ft=perl
 
-use Test::More tests => 7;
+use strict;
+use Test::More;
 use DBI;
 use DBI::Const::GetInfoType;
-use strict;
+use lib 't', '.';
+require 'lib.pl';
 $|= 1;
 
-my $mdriver= "";
-our ($test_dsn, $test_user, $test_password);
-foreach my $file ("lib.pl", "t/lib.pl") {
-  do $file;
-  if ($@) {
-    print STDERR "Error while executing $file: $@\n";
-    exit 10;
-  }
-  last if $mdriver ne '';
-}
+use vars qw($table $test_dsn $test_user $test_password);
 
-my $dbh= DBI->connect($test_dsn, $test_user, $test_password,
+my $dbh;
+eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password,
                       { RaiseError => 1, PrintError => 1, AutoCommit => 0,
-                        mysql_multi_statements => 1 });
+                        mysql_multi_statements => 1 });};
+
+if ($@) {
+    plan skip_all => "ERROR: $@. Can't continue test";
+}
+plan tests => 7; 
+
 ok(defined $dbh, "Connected to database with multi statement support");
 
 $dbh->{mysql_server_prepare}= 0;
@@ -29,10 +29,10 @@
   skip "Server doesn't support multi statements", 6 
     if $dbh->get_info($GetInfoType{SQL_DBMS_VER}) lt "4.1";
 
-  ok($dbh->do("DROP TABLE IF EXISTS t1"), "clean up");
-  ok($dbh->do("CREATE TABLE t1 (a INT)"), "create table");
+  ok($dbh->do("DROP TABLE IF EXISTS $table"), "clean up");
+  ok($dbh->do("CREATE TABLE $table (a INT)"), "create table");
 
-  ok($dbh->do("INSERT INTO t1 VALUES (1); INSERT INTO t1 VALUES (2);"));
+  ok($dbh->do("INSERT INTO $table VALUES (1); INSERT INTO $table VALUES (2);"));
 
   $dbh->disconnect();
 
@@ -41,9 +41,9 @@
                        mysql_multi_statements => 0 });
   ok(defined $dbh, "Connected to database without multi statement support");
 
-  ok(not $dbh->do("INSERT INTO t1 VALUES (1); INSERT INTO t1 VALUES (2);"));
+  ok(not $dbh->do("INSERT INTO $table VALUES (1); INSERT INTO $table VALUES (2);"));
 
-  ok($dbh->do("DROP TABLE IF EXISTS t1"), "clean up");
+  ok($dbh->do("DROP TABLE IF EXISTS $table"), "clean up");
 };
 
 $dbh->disconnect();

Modified: DBD-mysql/trunk/t/param_values.t
==============================================================================
--- DBD-mysql/trunk/t/param_values.t	(original)
+++ DBD-mysql/trunk/t/param_values.t	Sat May 10 04:41:18 2008
@@ -5,46 +5,39 @@
 
 use strict;
 use DBI ();
+use Test::More;
 
-use vars qw($test_dsn $test_user $test_password $state);
-require "t/lib.pl";
+use vars qw($table $test_dsn $test_user $test_password);
+use lib '.','t';
+require 'lib.pl';
+
+my $dbh;
+eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password,
+                      { RaiseError => 1, PrintError => 1, AutoCommit => 0 });};
+if ($@) {
+    plan skip_all => "ERROR: $@. Can't continue test";
+}
+plan tests => 7; 
+
+ok $dbh->do("DROP TABLE IF EXISTS $table");
 
-while (Testing()) {
-  my ($dbh, $sth);
-  #
-  # Connect to the database
-  Test($state or
-       ($dbh = DBI->connect($test_dsn, $test_user, $test_password,
-                           {RaiseError => 0})));
-
-  #
-  # Find a possible new table name
-  #
-  my $table = 't1';
-  # Drop the table
-  Test($state or $dbh->do("DROP TABLE IF EXISTS $table"));
-
-  #
-  # Create a new table
-  #
-  my $q = <<"QUERY";
+my $create = <<EOT;
 CREATE TABLE $table (id INTEGER,
                      name VARCHAR(64))
-QUERY
-  Test($state or $dbh->do($q));
+EOT
 
-  #
-  # Insert a row
-  #
-  $q = "INSERT INTO $table (id, name) VALUES (?,?)";
-  Test($state or ($sth = $dbh->prepare($q)));
-  Test($state or ($sth->execute(1, 'two')));
-  Test($state or ($sth->{ParamValues}));
-  #
-  # Drop the table
-  Test($state or $dbh->do("DROP TABLE $table"));
-
-  #
-  # Close the database connection
-  Test($state or ($dbh->disconnect() or 1));
-}
+ok $dbh->do($create), "create $table";
+
+my $query = "INSERT INTO $table (id, name) VALUES (?,?)";
+
+my $sth = $dbh->prepare($query) or die "$DBI::errstr";
+
+ok $sth->execute(1, 'two');
+
+ok $sth->{ParamValues};
+
+ok $dbh->do("DROP TABLE $table");
+
+ok $sth->finish;
+
+ok $dbh->disconnect();
Thread
[svn:DBD-mysql] r11233 - DBD-mysql/trunk/tcapttofu10 May 2008