Merge 'warnfree' into 'trunk'
Peter Rabbitson [Tue, 7 Oct 2008 14:02:04 +0000 (14:02 +0000)]
Another round of warning-squashing:
Fix source registration/unregistration in several places
Accomodate postgres being really load on CREATE
Move the taint tests to a non-mainstream schema - hopefully this one will not be disturbed for a while
Fix warning due to File::Copy being sloppy
Test for TxnScopeGuard warnings
Test for multiple register_class warnings
Blindly silence a weird warning within a TODO in t/47bind_attribute.t. Hopefully when the TODO is resolved, it will be obvious what was causing it

lib/DBIx/Class/InflateColumn/File.pm
t/47bind_attribute.t
t/54taint.t
t/63register_class.t
t/72pg.t
t/81transactions.t
t/93storage_replication.t
t/98savepoints.t
t/bindtype_columns.t

index d462bcc..78e316b 100644 (file)
@@ -95,8 +95,10 @@ sub _save_file_column {
 
     my $fs_file = $self->_file_column_file($column, $value->{filename});
     mkpath [$fs_file->dir];
-    
-    File::Copy::copy($value->{handle}, $fs_file);
+
+    # File::Copy doesn't like Path::Class (or any for that matter) objects,
+    # thus ->stringify (http://rt.perl.org/rt3/Public/Bug/Display.html?id=59650)
+    File::Copy::copy($value->{handle}, $fs_file->stringify);
 
     $self->_file_column_callback($value, $self, $column);
 
index 8f66f6c..3bc1935 100644 (file)
@@ -73,6 +73,10 @@ $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] })
 is ( $rs->count, 1, '...cookbook (bind first) + chained search' );
 
 TODO: {
+    # not sure what causes an uninit warning here, please remove when the TODO starts to pass,
+    # so the real reason for the warning can be found and fixed
+    local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /uninitialized/ };
+
     local $TODO = 'bind args order needs fixing (semifor)';
     $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] })
         ->search({ 'artistid' => 1 }, {
index 8e93b48..69f69ef 100644 (file)
@@ -13,11 +13,11 @@ BEGIN {
     : ( tests => 2 );
 }
 
-package DBICTest::Schema;
+package DBICTest::Plain;
 
-# Use the default test class namespace to avoid the need for a
+# Use the Plain test class namespace to avoid the need for a
 # new test infrastructure. If invalid classes will be introduced to
-# 't/lib/DBICTest/Schema/' someday, this has to be reworked.
+# 't/lib/DBICTest/Plain/' someday, this has to be reworked.
 
 use lib qw(t/lib);
 
@@ -28,6 +28,6 @@ use base qw/DBIx::Class::Schema/;
 eval{ __PACKAGE__->load_classes() };
 cmp_ok( $@, 'eq', '',
         'Loading classes with Module::Find worked in taint mode' );
-ok( __PACKAGE__->sources(), 'At least on source has been registered' );
+ok( __PACKAGE__->source('Test'), 'The Plain::Test source has been registered' );
 
 1;
index 2fdc07c..513c6d3 100644 (file)
@@ -1,17 +1,25 @@
 use strict;
 use warnings;  
 
-use Test::More tests => 2;
+use Test::More tests => 3;
 use lib qw(t/lib);
 use DBICTest;
 use DBICTest::Schema;
 use DBICTest::Schema::Artist;
 
 DBICTest::Schema::Artist->source_name('MyArtist');
-DBICTest::Schema->register_class('FooA', 'DBICTest::Schema::Artist');
+{
+    my $w;
+    local $SIG{__WARN__} = sub { $w = shift };
+    DBICTest::Schema->register_class('FooA', 'DBICTest::Schema::Artist');
+    like ($w, qr/use register_extra_source/, 'Complain about using register_class on an already-registered class');
+}
 
 my $schema = DBICTest->init_schema();
 
 my $a = $schema->resultset('FooA')->search;
 is($a->count, 3, 'have 3 artists');
 is($schema->class('FooA'), 'DBICTest::FooA', 'Correct artist class');
+
+# clean up
+DBICTest::Schema->_unregister_source('FooA');
index 0003205..a3336bf 100644 (file)
--- a/t/72pg.t
+++ b/t/72pg.t
@@ -47,13 +47,16 @@ SKIP: {
 my $dbh = $schema->storage->dbh;
 $schema->source("Artist")->name("testschema.artist");
 $schema->source("SequenceTest")->name("testschema.sequence_test");
-$dbh->do("CREATE SCHEMA testschema;");
-$dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(100), charfield CHAR(10));");
-$dbh->do("CREATE TABLE testschema.sequence_test (pkid1 integer, pkid2 integer, nonpkid integer, name VARCHAR(100), CONSTRAINT pk PRIMARY KEY(pkid1, pkid2));");
-$dbh->do("CREATE SEQUENCE pkid1_seq START 1 MAXVALUE 999999 MINVALUE 0");
-$dbh->do("CREATE SEQUENCE pkid2_seq START 10 MAXVALUE 999999 MINVALUE 0");
-$dbh->do("CREATE SEQUENCE nonpkid_seq START 20 MAXVALUE 999999 MINVALUE 0");
-ok ( $dbh->do('CREATE TABLE testschema.casecheck (id serial PRIMARY KEY, "name" VARCHAR(1), "NAME" VARCHAR(2), "UC_NAME" VARCHAR(3));'), 'Creation of casecheck table');
+{
+    local $SIG{__WARN__} = sub {};
+    $dbh->do("CREATE SCHEMA testschema;");
+    $dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(100), charfield CHAR(10));");
+    $dbh->do("CREATE TABLE testschema.sequence_test (pkid1 integer, pkid2 integer, nonpkid integer, name VARCHAR(100), CONSTRAINT pk PRIMARY KEY(pkid1, pkid2));");
+    $dbh->do("CREATE SEQUENCE pkid1_seq START 1 MAXVALUE 999999 MINVALUE 0");
+    $dbh->do("CREATE SEQUENCE pkid2_seq START 10 MAXVALUE 999999 MINVALUE 0");
+    $dbh->do("CREATE SEQUENCE nonpkid_seq START 20 MAXVALUE 999999 MINVALUE 0");
+    ok ( $dbh->do('CREATE TABLE testschema.casecheck (id serial PRIMARY KEY, "name" VARCHAR(1), "NAME" VARCHAR(2), "UC_NAME" VARCHAR(3));'), 'Creation of casecheck table');
+}
 
 # This is in Core now, but it's here just to test that it doesn't break
 $schema->class('Artist')->load_components('PK::Auto');
index 7d30b5c..89160a8 100644 (file)
@@ -8,7 +8,7 @@ use DBICTest;
 
 my $schema = DBICTest->init_schema();
 
-plan tests => 63;
+plan tests => 64;
 
 my $code = sub {
   my ($artist, @cd_titles) = @_;
@@ -235,7 +235,11 @@ my $fail_code = sub {
         $schema2->txn_begin();
     };
     my $err = $@;
-    ok(($err eq ''), 'Pre-connection nested transactions.');
+    ok(! $err, 'Pre-connection nested transactions.');
+
+    # although not connected DBI would still warn about rolling back at disconnect
+    $schema2->txn_rollback;
+    $schema2->txn_rollback;
     $schema2->storage->disconnect;
 }
 $schema->storage->disconnect;
@@ -268,12 +272,17 @@ $schema->storage->disconnect;
 
   ok(!$artist_rs->find({name => 'Death Cab for Cutie'}), "Artist not created");
 
-
   eval {
-    # The 0 arg says done die, just let the scope guard go out of scope 
+    my $w;
+    local $SIG{__WARN__} = sub { $w = shift };
+
+    # The 0 arg says don't die, just let the scope guard go out of scope 
     # forcing a txn_rollback to happen
     outer($schema, 0);
+
+    like ($w, qr/A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or an error/, 'Out of scope warning detected');
   };
+
   local $TODO = "Work out how this should work";
   is($@, "Not sure what we want here, but something", "Rollback okay");
 
index 07e696a..ab2ffe4 100644 (file)
@@ -59,8 +59,11 @@ TESTSCHEMACLASSES: {
     ## Get the Schema and set the replication storage type
     
     sub init_schema {
+        # current SQLT SQLite producer does not handle DROP TABLE IF EXISTS, trap warnings here
+        local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /no such table.+DROP TABLE/ };
+
         my $class = shift @_;
-        
+
         my $schema = DBICTest->init_schema(
             sqlite_use_file => 1,
             storage_type=>{
index 8e85f20..28b00cf 100644 (file)
@@ -30,7 +30,11 @@ $schema->storage->debugobj($stats);
 
 $schema->storage->debug(1);
 
-$schema->storage->dbh->do ($create_sql);
+{
+    local $SIG{__WARN__} = sub {};
+    $schema->storage->dbh->do ('DROP TABLE IF EXISTS artist');
+    $schema->storage->dbh->do ($create_sql);
+}
 
 $schema->resultset('Artist')->create({ name => 'foo' });
 
index 5b83255..8edf7af 100644 (file)
@@ -16,16 +16,18 @@ my $schema = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit =
 
 my $dbh = $schema->storage->dbh;
 
-$dbh->do(qq[
-
-       CREATE TABLE artist
-       (
-               artistid                serial  NOT NULL        PRIMARY KEY,
-               media                   bytea   NOT NULL,
-               name                    varchar NULL
-       );
-],{ RaiseError => 1, PrintError => 1 });
-
+{
+    local $SIG{__WARN__} = sub {};
+    $dbh->do('DROP TABLE IF EXISTS artist');
+    $dbh->do(qq[
+        CREATE TABLE artist
+        (
+            artistid        serial  NOT NULL    PRIMARY KEY,
+            media           bytea   NOT NULL,
+            name            varchar NULL
+        );
+    ],{ RaiseError => 1, PrintError => 1 });
+}
 
 $schema->class('Artist')->load_components(qw/