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