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