X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F22dump.t;h=7ead7a786ad56cdea464b0b5c0373a9f3490c059;hb=f8c2ca5eac1d4782c1d5be369c9bd0dcf680cb9d;hp=0b3a2f8d4addd3d969fa40466cd583d1a44d1cf3;hpb=c213fd3d7802c6d46dceae4e371476de14c43c56;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/t/22dump.t b/t/22dump.t index 0b3a2f8..7ead7a7 100644 --- a/t/22dump.t +++ b/t/22dump.t @@ -1,5 +1,8 @@ use strict; +use warnings; use Test::More; +use Test::Exception; +use Test::Warn; use lib qw(t/lib); use File::Path; use make_dbictest_db; @@ -7,10 +10,6 @@ use dbixcsl_test_dir qw/$tdir/; my $dump_path = "$tdir/dump"; -local $SIG{__WARN__} = sub { - warn $_[0] unless $_[0] =~ - /really_erase_my_files|Dumping manual schema|Schema dump completed/; -}; { package DBICTest::Schema::1; @@ -29,42 +28,67 @@ local $SIG{__WARN__} = sub { ); } -plan tests => 5; - rmtree($dump_path, 1, 1); -eval { DBICTest::Schema::1->connect($make_dbictest_db::dsn) }; -ok(!$@, 'no death with dump_directory set') or diag "Dump failed: $@"; +lives_ok { + warnings_exist { DBICTest::Schema::1->connect($make_dbictest_db::dsn) } + [ qr|^Dumping manual schema|, qr|^Schema dump completed| ]; +} 'no death with dump_directory set' or diag "Dump failed: $@"; + +is_deeply( + [ sort @{ DBICTest::Schema::1->loader->generated_classes } ], + [ sort 'DBICTest::Schema::1', map "DBICTest::Schema::1::Result::$_", qw(Foo Bar) ], + 'generated_classes has schema and result classes' +); DBICTest::Schema::1->_loader_invoked(undef); SKIP: { - my @warnings_regexes = ( - qr|Dumping manual schema|, - qr|Schema dump completed|, - ); - - skip "ActiveState perl produces additional warnings", scalar @warnings_regexes + skip "ActiveState perl produces additional warnings", 1 if ($^O eq 'MSWin32'); - my @warn_output; - { - local $SIG{__WARN__} = sub { push(@warn_output, @_) }; - DBICTest::Schema::1->connect($make_dbictest_db::dsn); - } + warnings_exist { DBICTest::Schema::1->connect($make_dbictest_db::dsn) } + [ qr|^Dumping manual schema|, qr|^Schema dump completed| ]; - like(shift @warn_output, $_) foreach (@warnings_regexes); + is_deeply( + [ sort @{ DBICTest::Schema::1->loader->generated_classes } ], + [ ], + 'no classes generated on second dump' + ); rmtree($dump_path, 1, 1); } -eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) }; -ok(!$@, 'no death with dump_directory set (overwrite1)') - or diag "Dump failed: $@"; +lives_ok { + warnings_exist { DBICTest::Schema::2->connect($make_dbictest_db::dsn) } + [ qr|^Dumping manual schema|, qr|^Schema dump completed| ]; +} 'no death with dump_directory set (overwrite1)' or diag "Dump failed: $@"; + +is_deeply( + [ sort @{ DBICTest::Schema::2->loader->generated_classes } ], + [ sort 'DBICTest::Schema::2', map "DBICTest::Schema::2::Result::$_", qw(Foo Bar) ], + 'generated_classes has schema and result classes' +); DBICTest::Schema::2->_loader_invoked(undef); -eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) }; -ok(!$@, 'no death with dump_directory set (overwrite2)') - or diag "Dump failed: $@"; + +lives_ok { + warnings_exist { DBICTest::Schema::2->connect($make_dbictest_db::dsn) } + [ + qr/^Dumping manual schema/, + qr|^Deleting .+Schema/2.+ due to 'really_erase_my_files'|, + qr|^Deleting .+Schema/2/Result/Foo.+ due to 'really_erase_my_files'|, + qr|^Deleting .+Schema/2/Result/Bar.+ due to 'really_erase_my_files'|, + qr/^Schema dump completed/ + ]; +} 'no death with dump_directory set (overwrite2)' or diag "Dump failed: $@"; + +is_deeply( + [ sort @{ DBICTest::Schema::2->loader->generated_classes } ], + [ sort 'DBICTest::Schema::2', map "DBICTest::Schema::2::Result::$_", qw(Foo Bar) ], + 'all classes regenerated with really_erase_my_files', +); + +done_testing(); END { rmtree($dump_path, 1, 1); }