dump code now skips+warns instead of dies when dump_overwrite not set [from nilsonsfj]
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 22dump.t
CommitLineData
fa994d3c 1use strict;
2use Test::More;
02356864 3use Test::Warn;
fa994d3c 4use lib qw(t/lib);
3e3c3fc7 5use File::Path;
fa994d3c 6use make_dbictest_db;
7
3e3c3fc7 8my $dump_path = './t/_dump';
9
10{
11 package DBICTest::Schema::1;
12 use base qw/ DBIx::Class::Schema::Loader /;
13 __PACKAGE__->loader_options(
14 relationships => 1,
15 dump_directory => $dump_path,
16 );
17}
18
fa994d3c 19{
3e3c3fc7 20 package DBICTest::Schema::2;
fa994d3c 21 use base qw/ DBIx::Class::Schema::Loader /;
22 __PACKAGE__->loader_options(
23 relationships => 1,
3e3c3fc7 24 dump_directory => $dump_path,
fa994d3c 25 dump_overwrite => 1,
26 );
fa994d3c 27}
28
3e3c3fc7 29plan tests => 4;
30
31rmtree($dump_path, 1, 0711);
32
33eval { DBICTest::Schema::1->connect($make_dbictest_db::dsn) };
34ok(!$@, 'no death with dump_directory set') or diag "Dump failed: $@";
35
36DBICTest::Schema::1->loader(undef);
02356864 37warnings_like { DBICTest::Schema::1->connect($make_dbictest_db::dsn) }
38 [
39 qr|Dumping manual schema|,
40 (qr|DBICTest/Schema/1.*?.pm exists, will not overwrite|) x 3,
41 qr|Schema dump completed|
42 ],
43 'warn and skip when attempting to overwrite without option';
3e3c3fc7 44
45rmtree($dump_path, 1, 0711);
46
47eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) };
02356864 48ok(!$@, 'no death with dump_directory set (overwrite1)')
49 or diag "Dump failed: $@";
3e3c3fc7 50
51DBICTest::Schema::2->loader(undef);
52eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) };
02356864 53ok(!$@, 'no death with dump_directory set (overwrite2)')
54 or diag "Dump failed: $@";
fa994d3c 55
02356864 56END { rmtree($dump_path, 1, 1); }