0.04001, dump_overwrite -> really_erase_my_files
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 22dump.t
1 use strict;
2 use Test::More;
3 use lib qw(t/lib);
4 use File::Path;
5 use make_dbictest_db;
6
7 my $dump_path = './t/_dump';
8
9 {
10     package DBICTest::Schema::1;
11     use base qw/ DBIx::Class::Schema::Loader /;
12     __PACKAGE__->loader_options(
13         dump_directory => $dump_path,
14     );
15 }
16
17 {
18     package DBICTest::Schema::2;
19     use base qw/ DBIx::Class::Schema::Loader /;
20     __PACKAGE__->loader_options(
21         dump_directory => $dump_path,
22         really_erase_my_files => 1,
23     );
24 }
25
26 plan tests => 5;
27
28 rmtree($dump_path, 1, 1);
29
30 eval { DBICTest::Schema::1->connect($make_dbictest_db::dsn) };
31 ok(!$@, 'no death with dump_directory set') or diag "Dump failed: $@";
32
33 DBICTest::Schema::1->_loader_invoked(undef);
34
35 SKIP: {
36   skip "ActiveState perl produces additional warnings", 5
37     if ($^O eq 'MSWin32');
38
39   my @warn_output;
40   {
41       local $SIG{__WARN__} = sub { push(@warn_output, @_) };
42       DBICTest::Schema::1->connect($make_dbictest_db::dsn);
43   }
44   my @warnings_regexes = (
45       qr|Dumping manual schema|,
46       qr|Schema dump completed|,
47   );
48
49   like(shift @warn_output, $_) foreach (@warnings_regexes);
50
51   rmtree($dump_path, 1, 1);
52 }
53
54 eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) };
55 ok(!$@, 'no death with dump_directory set (overwrite1)')
56     or diag "Dump failed: $@";
57
58 DBICTest::Schema::2->_loader_invoked(undef);
59 eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) };
60 ok(!$@, 'no death with dump_directory set (overwrite2)')
61     or diag "Dump failed: $@";
62
63 END { rmtree($dump_path, 1, 1); }