Update Firebird ODBC driver download URL
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 22dump.t
CommitLineData
fa994d3c 1use strict;
f8c2ca5e 2use warnings;
fa994d3c 3use Test::More;
c38ec663 4use Test::Exception;
5use Test::Warn;
fa994d3c 6use lib qw(t/lib);
3e3c3fc7 7use File::Path;
fa994d3c 8use make_dbictest_db;
c213fd3d 9use dbixcsl_test_dir qw/$tdir/;
fa994d3c 10
c213fd3d 11my $dump_path = "$tdir/dump";
3e3c3fc7 12
fdd8ff16 13
3e3c3fc7 14{
15 package DBICTest::Schema::1;
16 use base qw/ DBIx::Class::Schema::Loader /;
17 __PACKAGE__->loader_options(
3e3c3fc7 18 dump_directory => $dump_path,
19 );
20}
21
fa994d3c 22{
3e3c3fc7 23 package DBICTest::Schema::2;
fa994d3c 24 use base qw/ DBIx::Class::Schema::Loader /;
25 __PACKAGE__->loader_options(
3e3c3fc7 26 dump_directory => $dump_path,
28b4691d 27 really_erase_my_files => 1,
fa994d3c 28 );
fa994d3c 29}
30
520107ef 31rmtree($dump_path, 1, 1);
3e3c3fc7 32
c38ec663 33lives_ok {
494e0205 34 warnings_exist { DBICTest::Schema::1->connect($make_dbictest_db::dsn) }
35 [ qr|^Dumping manual schema|, qr|^Schema dump completed| ];
c38ec663 36} 'no death with dump_directory set' or diag "Dump failed: $@";
3e3c3fc7 37
9f98bd82 38is_deeply(
39 [ sort @{ DBICTest::Schema::1->loader->generated_classes } ],
40 [ sort 'DBICTest::Schema::1', map "DBICTest::Schema::1::Result::$_", qw(Foo Bar) ],
41 'generated_classes has schema and result classes'
42);
43
59cfa251 44DBICTest::Schema::1->_loader_invoked(undef);
9395f33a 45
e682950b 46SKIP: {
494e0205 47 skip "ActiveState perl produces additional warnings", 1
48 if ($^O eq 'MSWin32');
9395f33a 49
494e0205 50 warnings_exist { DBICTest::Schema::1->connect($make_dbictest_db::dsn) }
51 [ qr|^Dumping manual schema|, qr|^Schema dump completed| ];
e682950b 52
494e0205 53 is_deeply(
54 [ sort @{ DBICTest::Schema::1->loader->generated_classes } ],
55 [ ],
56 'no classes generated on second dump'
57 );
9f98bd82 58
494e0205 59 rmtree($dump_path, 1, 1);
e682950b 60}
3e3c3fc7 61
c38ec663 62lives_ok {
494e0205 63 warnings_exist { DBICTest::Schema::2->connect($make_dbictest_db::dsn) }
64 [ qr|^Dumping manual schema|, qr|^Schema dump completed| ];
c38ec663 65} 'no death with dump_directory set (overwrite1)' or diag "Dump failed: $@";
3e3c3fc7 66
9f98bd82 67is_deeply(
68 [ sort @{ DBICTest::Schema::2->loader->generated_classes } ],
69 [ sort 'DBICTest::Schema::2', map "DBICTest::Schema::2::Result::$_", qw(Foo Bar) ],
70 'generated_classes has schema and result classes'
71);
72
59cfa251 73DBICTest::Schema::2->_loader_invoked(undef);
c38ec663 74
75lives_ok {
494e0205 76 warnings_exist { DBICTest::Schema::2->connect($make_dbictest_db::dsn) }
77 [
78 qr/^Dumping manual schema/,
79 qr|^Deleting .+Schema/2.+ due to 'really_erase_my_files'|,
80 qr|^Deleting .+Schema/2/Result/Foo.+ due to 'really_erase_my_files'|,
81 qr|^Deleting .+Schema/2/Result/Bar.+ due to 'really_erase_my_files'|,
82 qr/^Schema dump completed/
83 ];
c38ec663 84} 'no death with dump_directory set (overwrite2)' or diag "Dump failed: $@";
fa994d3c 85
9f98bd82 86is_deeply(
87 [ sort @{ DBICTest::Schema::2->loader->generated_classes } ],
88 [ sort 'DBICTest::Schema::2', map "DBICTest::Schema::2::Result::$_", qw(Foo Bar) ],
89 'all classes regenerated with really_erase_my_files',
90);
91
2ee3bb7a 92done_testing();
93
7e9ee6a4 94END { rmtree($dump_path, 1, 1); }