Support identity columns in PostgreSQL v10
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 22dump.t
index 54193d9..1f4e0db 100644 (file)
@@ -1,16 +1,20 @@
 use strict;
+use warnings;
 use Test::More;
+use Test::Exception;
+use Test::Warn;
 use lib qw(t/lib);
 use File::Path;
 use make_dbictest_db;
+use dbixcsl_test_dir qw/$tdir/;
+
+my $dump_path = "$tdir/dump";
 
-my $dump_path = './t/_dump';
 
 {
     package DBICTest::Schema::1;
     use base qw/ DBIx::Class::Schema::Loader /;
     __PACKAGE__->loader_options(
-        relationships => 1,
         dump_directory => $dump_path,
     );
 }
@@ -19,31 +23,72 @@ my $dump_path = './t/_dump';
     package DBICTest::Schema::2;
     use base qw/ DBIx::Class::Schema::Loader /;
     __PACKAGE__->loader_options(
-        relationships => 1,
         dump_directory => $dump_path,
-        dump_overwrite => 1,
+        really_erase_my_files => 1,
     );
 }
 
-plan tests => 4;
+rmtree($dump_path, 1, 1);
+
+lives_ok {
+    warnings_exist { DBICTest::Schema::1->connect($make_dbictest_db::dsn) }
+        [ qr|^Dumping manual schema|, qr|^Schema dump completed| ];
+} 'no death with dump_directory set' or diag "Dump failed: $@";
+
+is_deeply(
+    [ sort @{ DBICTest::Schema::1->loader->generated_classes } ],
+    [ sort 'DBICTest::Schema::1', map "DBICTest::Schema::1::Result::$_", qw(Foo Bar) ],
+    'generated_classes has schema and result classes'
+);
+
+DBICTest::Schema::1->_loader_invoked(undef);
+
+SKIP: {
+    skip "ActiveState perl produces additional warnings", 1
+        if ($^O eq 'MSWin32');
+
+    warnings_exist { DBICTest::Schema::1->connect($make_dbictest_db::dsn) }
+        [ qr|^Dumping manual schema|, qr|^Schema dump completed| ];
+
+    is_deeply(
+        [ sort @{ DBICTest::Schema::1->loader->generated_classes } ],
+        [ ],
+        'no classes generated on second dump'
+    );
+
+    rmtree($dump_path, 1, 1);
+}
 
-rmtree($dump_path, 1, 0711);
+lives_ok {
+    warnings_exist { DBICTest::Schema::2->connect($make_dbictest_db::dsn) }
+        [ qr|^Dumping manual schema|, qr|^Schema dump completed| ];
+} 'no death with dump_directory set (overwrite1)' or diag "Dump failed: $@";
 
-eval { DBICTest::Schema::1->connect($make_dbictest_db::dsn) };
-ok(!$@, 'no death with dump_directory set') or diag "Dump failed: $@";
+is_deeply(
+    [ sort @{ DBICTest::Schema::2->loader->generated_classes } ],
+    [ sort 'DBICTest::Schema::2', map "DBICTest::Schema::2::Result::$_", qw(Foo Bar) ],
+    'generated_classes has schema and result classes'
+);
 
-DBICTest::Schema::1->loader(undef);
-eval { DBICTest::Schema::1->connect($make_dbictest_db::dsn) };
-like($@, qr|DBICTest/Schema/1.pm exists, will not overwrite|,
-    'death when attempting to overwrite without option');
+DBICTest::Schema::2->_loader_invoked(undef);
 
-rmtree($dump_path, 1, 0711);
+lives_ok {
+    warnings_exist { DBICTest::Schema::2->connect($make_dbictest_db::dsn) }
+        [
+            qr/^Dumping manual schema/,
+            qr|^Deleting .+Schema/2.+ due to 'really_erase_my_files'|,
+            qr|^Deleting .+Schema/2/Result/Foo.+ due to 'really_erase_my_files'|,
+            qr|^Deleting .+Schema/2/Result/Bar.+ due to 'really_erase_my_files'|,
+            qr/^Schema dump completed/
+        ];
+} 'no death with dump_directory set (overwrite2)' or diag "Dump failed: $@";
 
-eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) };
-ok(!$@, 'no death with dump_directory set (overwrite1)') or diag "Dump failed: $@";
+is_deeply(
+    [ sort @{ DBICTest::Schema::2->loader->generated_classes } ],
+    [ sort 'DBICTest::Schema::2', map "DBICTest::Schema::2::Result::$_", qw(Foo Bar) ],
+    'all classes regenerated with really_erase_my_files',
+);
 
-DBICTest::Schema::2->loader(undef);
-eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) };
-ok(!$@, 'no death with dump_directory set (overwrite2)') or diag "Dump failed: $@";
+done_testing();
 
-END { rmtree($dump_path, 1, 0711); }
+END { rmtree($dump_path, 1, 1); }