Overhaul of test warning handling - mask off as little as possible
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 22dump.t
index 0b3a2f8..cc92d9d 100644 (file)
@@ -1,5 +1,7 @@
 use strict;
 use Test::More;
+use Test::Exception;
+use Test::Warn;
 use lib qw(t/lib);
 use File::Path;
 use make_dbictest_db;
@@ -7,10 +9,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 +27,43 @@ local $SIG{__WARN__} = sub {
     );
 }
 
-plan tests => 5;
+plan tests => 7;
 
 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: $@";
 
 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);
-  }
-
-  like(shift @warn_output, $_) foreach (@warnings_regexes);
+  warnings_exist { DBICTest::Schema::1->connect($make_dbictest_db::dsn) }
+    [ qr|^Dumping manual schema|, qr|^Schema dump completed| ];
 
   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: $@";
 
 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: $@";
 
 END { rmtree($dump_path, 1, 1); }