Add extra warning guard and object creation tests to 20invocations.t
Peter Rabbitson [Mon, 6 Sep 2010 08:39:52 +0000 (10:39 +0200)]
Redo test class names while we are at it

Makefile.PL
t/20invocations.t
t/23dumpmore.t
t/lib/DBICTest/Schema/13/Foo.pm [deleted file]
t/lib/DBICTest/Schema/14/Foo.pm [deleted file]
t/lib/DBICTest/Schema/_no_skip_load_external/Foo.pm [new file with mode: 0644]
t/lib/DBICTest/Schema/_skip_load_external/Foo.pm [new file with mode: 0644]

index 3b80337..a94ccf5 100644 (file)
@@ -13,6 +13,7 @@ all_from       'lib/DBIx/Class/Schema/Loader.pm';
 
 test_requires 'Test::Exception';
 test_requires 'Test::More'    => '0.94';
+test_requires 'Test::Warn'    => '0.21';
 test_requires 'DBI'           => '1.56';
 test_requires 'DBD::SQLite'   => '1.29';
 test_requires 'File::Copy';
index b8a6ef5..170dd77 100644 (file)
@@ -1,40 +1,42 @@
 use strict;
 use Test::More;
+use Test::Warn;
 use DBIx::Class::Schema::Loader::Optional::Dependencies;
 use lib qw(t/lib);
 use make_dbictest_db;
 
-local $SIG{__WARN__} = sub {
-    warn $_[0] unless $_[0] =~ /really_erase_my_files/
-};
-
 # Takes a $schema as input, runs 4 basic tests
 sub test_schema {
-    my ($testname, $schema) = @_;
+  my ($testname, $schema) = @_;
 
+  warnings_are ( sub {
     $schema = $schema->clone if !ref $schema;
     isa_ok($schema, 'DBIx::Class::Schema', $testname);
 
-    my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
-    isa_ok($foo_rs, 'DBIx::Class::ResultSet', $testname);
+    my $rel_foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
+    isa_ok($rel_foo_rs, 'DBIx::Class::ResultSet', $testname);
+
+    my $rel_foo = $rel_foo_rs->next;
+    isa_ok($rel_foo, "DBICTest::Schema::_${testname}::Foo", $testname);
 
-    my $foo_first = $foo_rs->first;
-    like(ref $foo_first, qr/DBICTest::Schema::\d+::Foo/, $testname);
+    is($rel_foo->footext, 'Foo record associated with the Bar with barid 3', "$testname correct object");
 
-    my $foo_first_text = $foo_first->footext;
-    is($foo_first_text, 'Foo record associated with the Bar with barid 3');
+    my $foo_rs = $schema->resultset('Foo');
+    my $foo_new = $foo_rs->create({footext => "${testname}_foo"});
+    is ($foo_rs->search({footext => "${testname}_foo"})->count, 1, "$testname object created") || die;
+  }, [], "No warnings during $testname invocations");
 }
 
 my @invocations = (
     'hardcode' => sub {
-        package DBICTest::Schema::5;
+        package DBICTest::Schema::_hardcode;
         use base qw/ DBIx::Class::Schema::Loader /;
         __PACKAGE__->naming('current');
         __PACKAGE__->connection($make_dbictest_db::dsn);
         __PACKAGE__;
     },
     'normal' => sub {
-        package DBICTest::Schema::6;
+        package DBICTest::Schema::_normal;
         use base qw/ DBIx::Class::Schema::Loader /;
         __PACKAGE__->loader_options();
         __PACKAGE__->naming('current');
@@ -43,14 +45,14 @@ my @invocations = (
     'make_schema_at' => sub {
         use DBIx::Class::Schema::Loader qw/ make_schema_at /;
         make_schema_at(
-            'DBICTest::Schema::7',
+            'DBICTest::Schema::_make_schema_at',
             { really_erase_my_files => 1, naming => 'current' },
             [ $make_dbictest_db::dsn ],
         );
-        DBICTest::Schema::7->clone;
+        DBICTest::Schema::_make_schema_at->clone;
     },
     'embedded_options' => sub {
-        package DBICTest::Schema::8;
+        package DBICTest::Schema::_embedded_options;
         use base qw/ DBIx::Class::Schema::Loader /;
         __PACKAGE__->naming('current');
         __PACKAGE__->connect(
@@ -59,7 +61,7 @@ my @invocations = (
         );
     },
     'embedded_options_in_attrs' => sub {
-        package DBICTest::Schema::9;
+        package DBICTest::Schema::_embedded_options_in_attrs;
         use base qw/ DBIx::Class::Schema::Loader /;
         __PACKAGE__->naming('current');
         __PACKAGE__->connect(
@@ -72,7 +74,7 @@ my @invocations = (
     'embedded_options_make_schema_at' => sub {
         use DBIx::Class::Schema::Loader qw/ make_schema_at /;
         make_schema_at(
-            'DBICTest::Schema::10',
+            'DBICTest::Schema::_embedded_options_make_schema_at',
             { },
             [
                 $make_dbictest_db::dsn,
@@ -82,10 +84,10 @@ my @invocations = (
                 } },
             ],
         );
-        "DBICTest::Schema::10";
+        "DBICTest::Schema::_embedded_options_make_schema_at";
     },
     'almost_embedded' => sub {
-        package DBICTest::Schema::11;
+        package DBICTest::Schema::_almost_embedded;
         use base qw/ DBIx::Class::Schema::Loader /;
         __PACKAGE__->loader_options(
             really_erase_my_files => 1,
@@ -99,35 +101,35 @@ my @invocations = (
     'make_schema_at_explicit' => sub {
         use DBIx::Class::Schema::Loader;
         DBIx::Class::Schema::Loader::make_schema_at(
-            'DBICTest::Schema::12',
+            'DBICTest::Schema::_make_schema_at_explicit',
             { really_erase_my_files => 1, naming => 'current' },
             [ $make_dbictest_db::dsn ],
         );
-        DBICTest::Schema::12->clone;
+        DBICTest::Schema::_make_schema_at_explicit->clone;
     },
     'no_skip_load_external' => sub {
         # By default we should pull in t/lib/DBICTest/Schema/13/Foo.pm $skip_me since t/lib is in @INC
         use DBIx::Class::Schema::Loader;
         DBIx::Class::Schema::Loader::make_schema_at(
-            'DBICTest::Schema::13',
+            'DBICTest::Schema::_no_skip_load_external',
             { really_erase_my_files => 1, naming => 'current' },
             [ $make_dbictest_db::dsn ],
         );
-        DBICTest::Schema::13->clone;
+        DBICTest::Schema::_no_skip_load_external->clone;
     },
     'skip_load_external' => sub {
         # When we explicitly skip_load_external t/lib/DBICTest/Schema/14/Foo.pm should be ignored
         use DBIx::Class::Schema::Loader;
         DBIx::Class::Schema::Loader::make_schema_at(
-            'DBICTest::Schema::14',
+            'DBICTest::Schema::_skip_load_external',
             { really_erase_my_files => 1, naming => 'current', skip_load_external => 1 },
             [ $make_dbictest_db::dsn ],
         );
-        DBICTest::Schema::14->clone;
+        DBICTest::Schema::_skip_load_external->clone;
     },
     (DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('use_moose') ?
-        ('moose' => sub {
-            package DBICTest::Schema::8;
+        ('use_moose' => sub {
+            package DBICTest::Schema::_use_moose;
             use base qw/ DBIx::Class::Schema::Loader /;
             __PACKAGE__->naming('current');
             __PACKAGE__->connect(
@@ -139,20 +141,28 @@ my @invocations = (
     ),
 );
 
-# 4 tests per k/v pair
-plan tests => 2 * @invocations + 2;  # + 2 more manual ones below.
+# 6 tests per k/v pair
+plan tests => 6 * (@invocations/2) + 2;  # + 2 more manual ones below.
 
-while(@invocations >= 2) {
+while(@invocations) {
     my $style = shift @invocations;
-    my $subref = shift @invocations;
-    test_schema($style, &$subref);
+    my $cref = shift @invocations;
+
+    my $schema = do {
+      local $SIG{__WARN__} = sub {
+        warn $_[0] unless $_[0] =~ /really_erase_my_files/
+      };
+      $cref->();
+    };
+
+    test_schema($style, $schema);
 }
 
 {
     no warnings 'once';
 
-    is($DBICTest::Schema::13::Foo::skip_me, "bad mojo",
+    is($DBICTest::Schema::_no_skip_load_external::Foo::skip_me, "bad mojo",
         "external content loaded");
-    is($DBICTest::Schema::14::Foo::skip_me, undef,
+    is($DBICTest::Schema::_skip_load_external::Foo::skip_me, undef,
         "external content not loaded with skip_load_external => 1");
 }
index 61b3429..8ad6eba 100644 (file)
@@ -177,29 +177,29 @@ rmtree($DUMP_PATH, 1, 1);
 
 # test loading external content
 do_dump_test(
-    classname => 'DBICTest::Schema::13',
+    classname => 'DBICTest::Schema::_no_skip_load_external',
     warnings => [
-        qr/Dumping manual schema for DBICTest::Schema::13 to directory /,
+        qr/Dumping manual schema for DBICTest::Schema::_no_skip_load_external to directory /,
         qr/Schema dump completed/,
     ],
     regexes => {
         Foo => [
-qr/package DBICTest::Schema::13::Foo;\nour \$skip_me = "bad mojo";\n1;/
+qr/package DBICTest::Schema::_no_skip_load_external::Foo;\nour \$skip_me = "bad mojo";\n1;/
         ],
     },
 );
 
 # test skipping external content
 do_dump_test(
-    classname => 'DBICTest::Schema::14',
+    classname => 'DBICTest::Schema::_skip_load_external',
     options => { skip_load_external => 1 },
     warnings => [
-        qr/Dumping manual schema for DBICTest::Schema::14 to directory /,
+        qr/Dumping manual schema for DBICTest::Schema::_skip_load_external to directory /,
         qr/Schema dump completed/,
     ],
     neg_regexes => {
         Foo => [
-qr/package DBICTest::Schema::14::Foo;\nour \$skip_me = "bad mojo";\n1;/
+qr/package DBICTest::Schema::_skip_load_external::Foo;\nour \$skip_me = "bad mojo";\n1;/
         ],
     },
 );
@@ -216,10 +216,10 @@ EOF
 close $fh;
 
 do_dump_test(
-    classname => 'DBICTest::Schema::14',
+    classname => 'DBICTest::Schema::_skip_load_external',
     options => { config_file => $config_file },
     warnings => [
-        qr/Dumping manual schema for DBICTest::Schema::14 to directory /,
+        qr/Dumping manual schema for DBICTest::Schema::_skip_load_external to directory /,
         qr/Schema dump completed/,
     ],
     neg_regexes => {
@@ -393,7 +393,7 @@ else {
 rmtree($DUMP_PATH, 1, 1);
 
 do_dump_test(
-    classname => 'DBICTest::Schema::14',
+    classname => 'DBICTest::Schema::_skip_load_external',
     test_db_class => 'make_dbictest_db_clashing_monikers',
     error => qr/tables 'bar', 'bars' reduced to the same source moniker 'Bar'/,
 );
diff --git a/t/lib/DBICTest/Schema/13/Foo.pm b/t/lib/DBICTest/Schema/13/Foo.pm
deleted file mode 100644 (file)
index ca5fc9b..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-package DBICTest::Schema::13::Foo;
-our $skip_me = "bad mojo";
-1;
diff --git a/t/lib/DBICTest/Schema/14/Foo.pm b/t/lib/DBICTest/Schema/14/Foo.pm
deleted file mode 100644 (file)
index 6f3bf73..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-package DBICTest::Schema::14::Foo;
-our $skip_me = "bad mojo";
-1;
diff --git a/t/lib/DBICTest/Schema/_no_skip_load_external/Foo.pm b/t/lib/DBICTest/Schema/_no_skip_load_external/Foo.pm
new file mode 100644 (file)
index 0000000..5fb0fa7
--- /dev/null
@@ -0,0 +1,3 @@
+package DBICTest::Schema::_no_skip_load_external::Foo;
+our $skip_me = "bad mojo";
+1;
diff --git a/t/lib/DBICTest/Schema/_skip_load_external/Foo.pm b/t/lib/DBICTest/Schema/_skip_load_external/Foo.pm
new file mode 100644 (file)
index 0000000..fbf8e44
--- /dev/null
@@ -0,0 +1,3 @@
+package DBICTest::Schema::_skip_load_external::Foo;
+our $skip_me = "bad mojo";
+1;