add self to credits
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 22dump.t
1 use strict;
2 use warnings;
3 use Test::More;
4 use Test::Exception;
5 use Test::Warn;
6 use lib qw(t/lib);
7 use File::Path;
8 use make_dbictest_db;
9 use dbixcsl_test_dir qw/$tdir/;
10
11 my $dump_path = "$tdir/dump";
12
13
14 {
15     package DBICTest::Schema::1;
16     use base qw/ DBIx::Class::Schema::Loader /;
17     __PACKAGE__->loader_options(
18         dump_directory => $dump_path,
19     );
20 }
21
22 {
23     package DBICTest::Schema::2;
24     use base qw/ DBIx::Class::Schema::Loader /;
25     __PACKAGE__->loader_options(
26         dump_directory => $dump_path,
27         really_erase_my_files => 1,
28     );
29 }
30
31 rmtree($dump_path, 1, 1);
32
33 lives_ok {
34     warnings_exist { DBICTest::Schema::1->connect($make_dbictest_db::dsn) }
35         [ qr|^Dumping manual schema|, qr|^Schema dump completed| ];
36 } 'no death with dump_directory set' or diag "Dump failed: $@";
37
38 is_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
44 DBICTest::Schema::1->_loader_invoked(undef);
45
46 SKIP: {
47     skip "ActiveState perl produces additional warnings", 1
48         if ($^O eq 'MSWin32');
49
50     warnings_exist { DBICTest::Schema::1->connect($make_dbictest_db::dsn) }
51         [ qr|^Dumping manual schema|, qr|^Schema dump completed| ];
52
53     is_deeply(
54         [ sort @{ DBICTest::Schema::1->loader->generated_classes } ],
55         [ ],
56         'no classes generated on second dump'
57     );
58
59     rmtree($dump_path, 1, 1);
60 }
61
62 lives_ok {
63     warnings_exist { DBICTest::Schema::2->connect($make_dbictest_db::dsn) }
64         [ qr|^Dumping manual schema|, qr|^Schema dump completed| ];
65 } 'no death with dump_directory set (overwrite1)' or diag "Dump failed: $@";
66
67 is_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
73 DBICTest::Schema::2->_loader_invoked(undef);
74
75 lives_ok {
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         ];
84 } 'no death with dump_directory set (overwrite2)' or diag "Dump failed: $@";
85
86 is_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
92 done_testing();
93
94 END { rmtree($dump_path, 1, 1); }