Restructure handling of the test scratch-dir, move all activity
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 22dump.t
CommitLineData
fa994d3c 1use strict;
2use Test::More;
3use lib qw(t/lib);
3e3c3fc7 4use File::Path;
fa994d3c 5use make_dbictest_db;
c213fd3d 6use dbixcsl_test_dir qw/$tdir/;
fa994d3c 7
c213fd3d 8my $dump_path = "$tdir/dump";
3e3c3fc7 9
fdd8ff16 10local $SIG{__WARN__} = sub {
11 warn $_[0] unless $_[0] =~
12 /really_erase_my_files|Dumping manual schema|Schema dump completed/;
13};
14
3e3c3fc7 15{
16 package DBICTest::Schema::1;
17 use base qw/ DBIx::Class::Schema::Loader /;
18 __PACKAGE__->loader_options(
3e3c3fc7 19 dump_directory => $dump_path,
20 );
21}
22
fa994d3c 23{
3e3c3fc7 24 package DBICTest::Schema::2;
fa994d3c 25 use base qw/ DBIx::Class::Schema::Loader /;
26 __PACKAGE__->loader_options(
3e3c3fc7 27 dump_directory => $dump_path,
28b4691d 28 really_erase_my_files => 1,
fa994d3c 29 );
fa994d3c 30}
31
7cab3ab7 32plan tests => 5;
3e3c3fc7 33
520107ef 34rmtree($dump_path, 1, 1);
3e3c3fc7 35
36eval { DBICTest::Schema::1->connect($make_dbictest_db::dsn) };
37ok(!$@, 'no death with dump_directory set') or diag "Dump failed: $@";
38
59cfa251 39DBICTest::Schema::1->_loader_invoked(undef);
9395f33a 40
e682950b 41SKIP: {
2ffd6b4c 42 my @warnings_regexes = (
43 qr|Dumping manual schema|,
44 qr|Schema dump completed|,
45 );
46
47 skip "ActiveState perl produces additional warnings", scalar @warnings_regexes
e682950b 48 if ($^O eq 'MSWin32');
9395f33a 49
e682950b 50 my @warn_output;
51 {
52 local $SIG{__WARN__} = sub { push(@warn_output, @_) };
53 DBICTest::Schema::1->connect($make_dbictest_db::dsn);
54 }
3e3c3fc7 55
e682950b 56 like(shift @warn_output, $_) foreach (@warnings_regexes);
57
58 rmtree($dump_path, 1, 1);
59}
3e3c3fc7 60
61eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) };
02356864 62ok(!$@, 'no death with dump_directory set (overwrite1)')
63 or diag "Dump failed: $@";
3e3c3fc7 64
59cfa251 65DBICTest::Schema::2->_loader_invoked(undef);
3e3c3fc7 66eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) };
02356864 67ok(!$@, 'no death with dump_directory set (overwrite2)')
68 or diag "Dump failed: $@";
fa994d3c 69
7e9ee6a4 70END { rmtree($dump_path, 1, 1); }