Restructure handling of the test scratch-dir, move all activity
[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 use dbixcsl_test_dir qw/$tdir/;
7
8 my $dump_path = "$tdir/dump";
9
10 local $SIG{__WARN__} = sub {
11     warn $_[0] unless $_[0] =~
12         /really_erase_my_files|Dumping manual schema|Schema dump completed/;
13 };
14
15 {
16     package DBICTest::Schema::1;
17     use base qw/ DBIx::Class::Schema::Loader /;
18     __PACKAGE__->loader_options(
19         dump_directory => $dump_path,
20     );
21 }
22
23 {
24     package DBICTest::Schema::2;
25     use base qw/ DBIx::Class::Schema::Loader /;
26     __PACKAGE__->loader_options(
27         dump_directory => $dump_path,
28         really_erase_my_files => 1,
29     );
30 }
31
32 plan tests => 5;
33
34 rmtree($dump_path, 1, 1);
35
36 eval { DBICTest::Schema::1->connect($make_dbictest_db::dsn) };
37 ok(!$@, 'no death with dump_directory set') or diag "Dump failed: $@";
38
39 DBICTest::Schema::1->_loader_invoked(undef);
40
41 SKIP: {
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
48     if ($^O eq 'MSWin32');
49
50   my @warn_output;
51   {
52       local $SIG{__WARN__} = sub { push(@warn_output, @_) };
53       DBICTest::Schema::1->connect($make_dbictest_db::dsn);
54   }
55
56   like(shift @warn_output, $_) foreach (@warnings_regexes);
57
58   rmtree($dump_path, 1, 1);
59 }
60
61 eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) };
62 ok(!$@, 'no death with dump_directory set (overwrite1)')
63     or diag "Dump failed: $@";
64
65 DBICTest::Schema::2->_loader_invoked(undef);
66 eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) };
67 ok(!$@, 'no death with dump_directory set (overwrite2)')
68     or diag "Dump failed: $@";
69
70 END { rmtree($dump_path, 1, 1); }