Author: turnstep
Date: Wed Jan 16 20:31:58 2008
New Revision: 10575

Modified:
   DBD-Pg/trunk/README
   DBD-Pg/trunk/t/01connect.t
   DBD-Pg/trunk/t/02attribs.t
   DBD-Pg/trunk/t/03dbmethod.t
   DBD-Pg/trunk/t/03smethod.t
   DBD-Pg/trunk/t/04misc.t
   DBD-Pg/trunk/t/06bytea.t
   DBD-Pg/trunk/t/07copy.t
   DBD-Pg/trunk/t/08async.t
   DBD-Pg/trunk/t/09arrays.t
   DBD-Pg/trunk/t/12placeholders.t
   DBD-Pg/trunk/t/20savepoints.t
   DBD-Pg/trunk/t/99cleanup.t
   DBD-Pg/trunk/t/dbdpg_test_setup.pl

Log:
Remove DBI_DSN requirement from tests entirely, have them all skip no 
connection.


Modified: DBD-Pg/trunk/README
==============================================================================
--- DBD-Pg/trunk/README (original)
+++ DBD-Pg/trunk/README Wed Jan 16 20:31:58 2008
@@ -107,15 +107,15 @@
 TESTING:
 --------
 
-The tests are designed to connect to a live database.  The following
-environment variables must be set for the tests to run:
+The tests rely on being able to connect to a valid Postgres database. 
+The easiest way to ensure this is to set the following environment variables:
 
        DBI_DSN=dbi:Pg:dbname=<database>
        DBI_USER=<username>
        DBI_PASS=<password>
 
-If you are running on a non-standard port, you must add it 
-to the DBI_DSN variable like this:
+If you are running on a non-standard port, you must set PGPORT or 
+add it to the DBI_DSN variable like this:
 
        DBI_DSN='dbi:Pg:dbname=<database>;port=<port#>'
 
@@ -124,10 +124,6 @@
 
        DBI_DSN='dbi:Pg:dbname="<data;base>"'
 
-The tests assume that a schema named "public" is available. To override 
-this, set the environment variable DBD_SCHEMA to a valid schema 
-before testing.
-
 You can increase the verbosity of the tests by setting the 
 environment variable TEST_VERBOSE. You can also enable tracing 
 within the tests themselves by setting DBD_TRACE to whatever 

Modified: DBD-Pg/trunk/t/01connect.t
==============================================================================
--- DBD-Pg/trunk/t/01connect.t  (original)
+++ DBD-Pg/trunk/t/01connect.t  Wed Jan 16 20:31:58 2008
@@ -8,16 +8,20 @@
 use DBI;
 use DBD::Pg;
 use Test::More;
+use lib 't','.';
+require 'dbdpg_test_setup.pl';
 select(($|=1,select(STDERR),$|=1)[1]);
 
 ## Define this here in case we get to the END block before a connection is 
made.
 my ($pgversion,$pglibversion,$pgvstring,$pgdefport) = ('?','?','?','?');
 
-my $bail = 0;
-if (defined $ENV{DBI_DSN}){
+my $dbh = connect_database();
+
+if (! defined $dbh) {
+       plan skip_all => 'Connection to database failed, cannot continue 
testing';
+}
+else {
        plan tests => 15;
-} else {
-       plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the 
README file';
 }
 
 # Trapping a connection error can be tricky, but we only have to do it 
@@ -25,20 +29,7 @@
 # the first is when we truly do not connect, usually a bad DBI_DSN;
 # the second is an invalid login, usually a bad DBI_USER or DBI_PASS
 
-my ($dbh,$t);
-
-eval {
-       $dbh = DBI->connect($ENV{DBI_DSN}, $ENV{DBI_USER}, $ENV{DBI_PASS},
-                                                                               
        {RaiseError => 1, PrintError => 0, AutoCommit => 0});
-};
-if ($@) {
-       if (! $DBI::errstr) {
-               BAIL_OUT "Could not connect: $@";
-       }
-       else {
-               BAIL_OUT "Could not connect: $DBI::errstr";
-       }
-}
+my ($t);
 
 pass('Established a connection to the database');
 
@@ -50,14 +41,13 @@
 ok( $dbh->disconnect(), 'Disconnect from the database');
 
 # Connect two times. From this point onward, do a simpler connection check
-ok( $dbh = DBI->connect($ENV{DBI_DSN}, $ENV{DBI_USER}, $ENV{DBI_PASS},
-                                                                               
                {RaiseError => 1, PrintError => 0, AutoCommit => 0}),
-               'Connected with first database handle');
-
-my $dbh2;
-ok( $dbh2 = DBI->connect($ENV{DBI_DSN}, $ENV{DBI_USER}, $ENV{DBI_PASS},
-                                                                               
                 {RaiseError => 1, PrintError => 0, AutoCommit => 0}),
-               'Connected with second database handle');
+$dbh = connect_database();
+
+pass('Connected with first database handle');
+
+my $dbh2 = connect_database();
+
+pass('Connected with second database handle');
 
 my $sth = $dbh->prepare('SELECT 123');
 ok ( $dbh->disconnect(), 'Disconnect with first database handle');
@@ -70,6 +60,7 @@
 ok( $@, 'Execute fails on a disconnected statement');
 
 # Try out various connection options
+$ENV{DBI_DSN} ||= '';
 SKIP: {
        my $alias = qr{(database|db|dbname)};
        if ($ENV{DBI_DSN} !~ /$alias\s*=\s*\S+/) {
@@ -123,12 +114,18 @@
        my $user = exists $ENV{DBI_USER} ? $ENV{DBI_USER} : '<not set>';
 
        my $extra = '';
-       for (sort qw/HOST HOSTADDR PORT DATABASE USER PASSWORD OPTIONS SERVICE 
SSLMODE SYSCONFDIR/) {
+       for (sort qw/HOST HOSTADDR PORT DATABASE USER PASSWORD PASSFILE OPTIONS 
REALM
+                 REQUIRESSL KRBSRVNAME CONNECT_TIMEOUT SERVICE SSLMODE 
SYSCONFDIR/) {
                my $name = "PG$_";
                if (exists $ENV{$name} and defined $ENV{$name}) {
                        $extra .= sprintf "\n%-21s $ENV{$name}", $name;
                }
        }
+       for my $name (qw/DBI_DRIVER DBI_USER DBI_PASS DBI_AUTOPROXY/) {
+               if (exists $ENV{$name} and defined $ENV{$name}) {
+                       $extra .= sprintf "\n%-21s $ENV{$name}", $name;
+               }
+       }
 
        diag
                "\nDBI                   Version $DBI::VERSION\n".

Modified: DBD-Pg/trunk/t/02attribs.t
==============================================================================
--- DBD-Pg/trunk/t/02attribs.t  (original)
+++ DBD-Pg/trunk/t/02attribs.t  Wed Jan 16 20:31:58 2008
@@ -11,14 +11,15 @@
 require 'dbdpg_test_setup.pl';
 select(($|=1,select(STDERR),$|=1)[1]);
 
-if (defined $ENV{DBI_DSN}) {
+my $dbh = connect_database();
+
+if (defined $dbh) {
        plan tests => 132;
 }
 else {
-       plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the 
README file';
+       plan skip_all => 'Connection to database failed, cannot continue 
testing';
 }
 
-my $dbh = connect_database();
 ok( defined $dbh, 'Connect to database for handle attributes testing');
 
 my $attributes_tested = q{
@@ -178,8 +179,8 @@
 #
 
 SKIP: {
-       if ($ENV{DBI_DSN} !~ /^dbi:Pg:(.*)$/) {
-               fail(q{Cannot test DB handle attribute "Name": invalid 
DBI_DSN});
+       if (!exists $ENV{DBI_DSN} or $ENV{DBI_DSN} !~ /^dbi:Pg:(.*)$/) {
+               skip q{Cannot test DB handle attribute "Name": invalid 
DBI_DSN}, 1;
        }
        else {
                $expected = $1 || $ENV{PGDATABASE};

Modified: DBD-Pg/trunk/t/03dbmethod.t
==============================================================================
--- DBD-Pg/trunk/t/03dbmethod.t (original)
+++ DBD-Pg/trunk/t/03dbmethod.t Wed Jan 16 20:31:58 2008
@@ -20,14 +20,15 @@
 require 'dbdpg_test_setup.pl';
 select(($|=1,select(STDERR),$|=1)[1]);
 
-if (defined $ENV{DBI_DSN}) {
+my $dbh = connect_database();
+
+if (defined $dbh) {
        plan tests => 207;
 }
 else {
-       plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the 
README file';
+       plan skip_all => 'Connection to database failed, cannot continue 
testing';
 }
 
-my $dbh = connect_database();
 ok( defined $dbh, 'Connect to database for database handle method testing');
 
 my ($pglibversion,$pgversion) = 
($dbh->{pg_lib_version},$dbh->{pg_server_version});

Modified: DBD-Pg/trunk/t/03smethod.t
==============================================================================
--- DBD-Pg/trunk/t/03smethod.t  (original)
+++ DBD-Pg/trunk/t/03smethod.t  Wed Jan 16 20:31:58 2008
@@ -14,14 +14,15 @@
 require 'dbdpg_test_setup.pl';
 select(($|=1,select(STDERR),$|=1)[1]);
 
-if (defined $ENV{DBI_DSN}) {
+my $dbh = connect_database();
+
+if (defined $dbh) {
        plan tests => 71;
 }
 else {
-       plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the 
README file';
+       plan skip_all => 'Connection to database failed, cannot continue 
testing';
 }
 
-my $dbh = connect_database();
 ok( defined $dbh, 'Connect to database for statement handle method testing');
 
 my $pglibversion = $dbh->{pg_lib_version};

Modified: DBD-Pg/trunk/t/04misc.t
==============================================================================
--- DBD-Pg/trunk/t/04misc.t     (original)
+++ DBD-Pg/trunk/t/04misc.t     Wed Jan 16 20:31:58 2008
@@ -11,13 +11,15 @@
 require 'dbdpg_test_setup.pl';
 select(($|=1,select(STDERR),$|=1)[1]);
 
-if (defined $ENV{DBI_DSN}) {
+my $dbh = connect_database();
+
+if (defined $dbh) {
        plan tests => 6;
-} else {
-       plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the 
README file';
+}
+else {
+       plan skip_all => 'Connection to database failed, cannot continue 
testing';
 }
 
-my $dbh = connect_database();
 ok( defined $dbh, 'Connect to database for miscellaneous tests');
 
 #

Modified: DBD-Pg/trunk/t/06bytea.t
==============================================================================
--- DBD-Pg/trunk/t/06bytea.t    (original)
+++ DBD-Pg/trunk/t/06bytea.t    Wed Jan 16 20:31:58 2008
@@ -11,13 +11,15 @@
 require 'dbdpg_test_setup.pl';
 select(($|=1,select(STDERR),$|=1)[1]);
 
-if (defined $ENV{DBI_DSN}){
+my $dbh = connect_database();
+
+if (defined $dbh) {
        plan tests => 7;
-} else {
-       plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the 
README file';
+}
+else {
+       plan skip_all => 'Connection to database failed, cannot continue 
testing';
 }
 
-my $dbh = connect_database();
 ok( defined $dbh, 'Connect to database for bytea testing');
 
 my ($pglibversion,$pgversion) = 
($dbh->{pg_lib_version},$dbh->{pg_server_version});

Modified: DBD-Pg/trunk/t/07copy.t
==============================================================================
--- DBD-Pg/trunk/t/07copy.t     (original)
+++ DBD-Pg/trunk/t/07copy.t     Wed Jan 16 20:31:58 2008
@@ -10,13 +10,15 @@
 require 'dbdpg_test_setup.pl';
 select(($|=1,select(STDERR),$|=1)[1]);
 
-if (defined $ENV{DBI_DSN}) {
+my $dbh = connect_database();
+
+if (defined $dbh) {
        plan tests => 54;
-} else {
-       plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the 
README file';
+}
+else {
+       plan skip_all => 'Connection to database failed, cannot continue 
testing';
 }
 
-my $dbh = connect_database();
 ok( defined $dbh, 'Connect to database for bytea testing');
 
 my ($sth,$count,$result,$expected,@data);

Modified: DBD-Pg/trunk/t/08async.t
==============================================================================
--- DBD-Pg/trunk/t/08async.t    (original)
+++ DBD-Pg/trunk/t/08async.t    Wed Jan 16 20:31:58 2008
@@ -11,11 +11,12 @@
 require 'dbdpg_test_setup.pl';
 select(($|=1,select(STDERR),$|=1)[1]);
 
-if (!defined $ENV{DBI_DSN}) {
-       plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the 
README file';
+my $dbh = connect_database();
+
+if (!defined $dbh) {
+       plan skip_all => 'Connection to database failed, cannot continue 
testing';
 }
 
-my $dbh = connect_database();
 my $pglibversion = $dbh->{pg_lib_version};
 
 if ($pglibversion < 80000) {

Modified: DBD-Pg/trunk/t/09arrays.t
==============================================================================
--- DBD-Pg/trunk/t/09arrays.t   (original)
+++ DBD-Pg/trunk/t/09arrays.t   Wed Jan 16 20:31:58 2008
@@ -12,17 +12,19 @@
 require 'dbdpg_test_setup.pl';
 select(($|=1,select(STDERR),$|=1)[1]);
 
-if (defined $ENV{DBI_DSN}) {
+my $dbh = connect_database();
+
+if (defined $dbh) {
        plan tests => 213;
-} else {
-       plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the 
README file';
+}
+else {
+       plan skip_all => 'Connection to database failed, cannot continue 
testing';
 }
 
-my ($sth,$result);
-
-my $dbh = connect_database();
 ok( defined $dbh, 'Connect to database for array testing');
 
+my ($sth,$result);
+
 my $pgversion = $dbh->{pg_server_version};
 
 if ($pgversion >= 80100) {

Modified: DBD-Pg/trunk/t/12placeholders.t
==============================================================================
--- DBD-Pg/trunk/t/12placeholders.t     (original)
+++ DBD-Pg/trunk/t/12placeholders.t     Wed Jan 16 20:31:58 2008
@@ -9,13 +9,15 @@
 require 'dbdpg_test_setup.pl';
 select(($|=1,select(STDERR),$|=1)[1]);
 
-if (defined $ENV{DBI_DSN}) {
+my $dbh = connect_database();
+
+if (defined $dbh) {
        plan tests => 26;
-} else {
-       plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the 
README file';
+}
+else {
+       plan skip_all => 'Connection to database failed, cannot continue 
testing';
 }
 
-my $dbh = connect_database();
 ok( defined $dbh, 'Connect to database for placeholder testing');
 
 my ($pglibversion,$pgversion) = 
($dbh->{pg_lib_version},$dbh->{pg_server_version});

Modified: DBD-Pg/trunk/t/20savepoints.t
==============================================================================
--- DBD-Pg/trunk/t/20savepoints.t       (original)
+++ DBD-Pg/trunk/t/20savepoints.t       Wed Jan 16 20:31:58 2008
@@ -10,13 +10,15 @@
 require 'dbdpg_test_setup.pl';
 select(($|=1,select(STDERR),$|=1)[1]);
 
-if (defined $ENV{DBI_DSN}) {
+my $dbh = connect_database();
+
+if (defined $dbh) {
        plan tests => 3;
-} else {
-       plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the 
README file';
+}
+else {
+       plan skip_all => 'Connection to database failed, cannot continue 
testing';
 }
 
-my $dbh = connect_database();
 ok( defined $dbh, 'Connect to database for savepoint testing');
 
 my $pgversion = $dbh->{pg_server_version};

Modified: DBD-Pg/trunk/t/99cleanup.t
==============================================================================
--- DBD-Pg/trunk/t/99cleanup.t  (original)
+++ DBD-Pg/trunk/t/99cleanup.t  Wed Jan 16 20:31:58 2008
@@ -9,13 +9,15 @@
 require 'dbdpg_test_setup.pl';
 select(($|=1,select(STDERR),$|=1)[1]);
 
-if (defined $ENV{DBI_DSN}) {
+my $dbh = connect_database({nosetup => 1});
+
+if (defined $dbh) {
        plan tests => 1;
-} else {
-       plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the 
README file';
+}
+else {
+       plan skip_all => 'Connection to database failed, cannot continue 
testing';
 }
 
-my $dbh = connect_database({nosetup => 1});
 ok( defined $dbh, 'Connect to database for cleanup');
 
 cleanup_database($dbh);

Modified: DBD-Pg/trunk/t/dbdpg_test_setup.pl
==============================================================================
--- DBD-Pg/trunk/t/dbdpg_test_setup.pl  (original)
+++ DBD-Pg/trunk/t/dbdpg_test_setup.pl  Wed Jan 16 20:31:58 2008
@@ -6,13 +6,13 @@
 use DBI;
 select(($|=1,select(STDERR),$|=1)[1]);
 
-my @schemas = 
+my @schemas =
        (
         'dbd_pg_testschema',
         'dbd_pg_testschema2',
         );
 
-my @tables = 
+my @tables =
        (
         'dbd_pg_test5',
         'dbd_pg_test4',
@@ -24,7 +24,7 @@
         'dbd_pg_test',
         );
 
-my @sequences = 
+my @sequences =
        (
         'dbd_pg_testsequence',
         'dbd_pg_testschema2.dbd_pg_testsequence2',
@@ -46,8 +46,11 @@
        my $dbh = $arg->{dbh} || '';
 
        if (!$dbh) {
-               $dbh = DBI->connect($ENV{DBI_DSN}, $ENV{DBI_USER}, 
$ENV{DBI_PASS},
-                                                       {RaiseError => 1, 
PrintError => 0, AutoCommit => 1});
+               eval {
+                       $dbh = DBI->connect($ENV{DBI_DSN}, $ENV{DBI_USER}, 
$ENV{DBI_PASS},
+                                                               {RaiseError => 
1, PrintError => 0, AutoCommit => 1});
+               };
+               $@ and return undef;
        }
        if ($arg->{nosetup}) {
                $dbh->do("SET search_path TO $S");
@@ -57,9 +60,9 @@
 
                $dbh->do("CREATE SCHEMA $S");
                $dbh->do("SET search_path TO $S");
-               $dbh->do("CREATE SEQUENCE dbd_pg_testsequence");
+               $dbh->do('CREATE SEQUENCE dbd_pg_testsequence');
                # If you add columns to this, please do not use reserved words!
-               my $SQL = qq{
+               my $SQL = q{
 CREATE TABLE dbd_pg_test (
   id         integer not null primary key,
   lii        integer unique not null default nextval('dbd_pg_testsequence'),
@@ -78,7 +81,7 @@
 $dbh->{Warn} = 0;
 $dbh->do($SQL);
 $dbh->{Warn} = 1;
-$dbh->do("COMMENT ON COLUMN dbd_pg_test.id IS 'Bob is your uncle'");
+$dbh->do(q{COMMENT ON COLUMN dbd_pg_test.id IS 'Bob is your uncle'});
 
 } ## end setup
 
@@ -98,7 +101,7 @@
 sub schema_exists {
 
        my ($dbh,$schema) = @_;
-       my $SQL = "SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = ?";
+       my $SQL = 'SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = ?';
        my $sth = $dbh->prepare_cached($SQL);
        my $count = $sth->execute($schema);
        $sth->finish();
@@ -110,8 +113,8 @@
 sub relation_exists {
 
        my ($dbh,$schema,$name) = @_;
-       my $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace 
n ".
-               "WHERE n.oid=c.relnamespace AND n.nspname = ? AND c.relname = 
?";
+       my $SQL = 'SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace 
n '.
+               'WHERE n.oid=c.relnamespace AND n.nspname = ? AND c.relname = 
?';
        my $sth = $dbh->prepare_cached($SQL);
        my $count = $sth->execute($schema,$name);
        $sth->finish();
@@ -148,6 +151,8 @@
        }
        $dbh->commit() if ! $dbh->{AutoCommit};
 
+       return;
+
 }
 
 1;

Reply via email to