Stop permanently enabling autoflush on the debug filehandle
[dbsrgits/DBIx-Class.git] / t / storage / debug.t
index 514b43b..77f7e42 100644 (file)
@@ -4,9 +4,9 @@ no warnings 'once';
 
 use Test::More;
 use Test::Exception;
+use Try::Tiny;
 use lib qw(t/lib);
 use DBICTest;
-use DBIC::SqlMakerTest;
 use Path::Class qw/file/;
 
 BEGIN { delete @ENV{qw(DBIC_TRACE DBIC_TRACE_PROFILE DBICTEST_SQLITE_USE_FILE)} }
@@ -23,7 +23,6 @@ $schema->storage->debugobj(DBIx::Class::Storage::Statistics->new);
 
 ok ( $schema->storage->debug(1), 'debug' );
 $schema->storage->debugfh($lfn->openw);
-$schema->storage->debugfh->autoflush(1);
 $schema->resultset('CD')->count;
 
 my @loglines = $lfn->slurp;
@@ -54,12 +53,21 @@ END {
 }
 
 open(STDERRCOPY, '>&STDERR');
-close(STDERR);
-dies_ok {
+
+# STDERR will be closed, no T::B diag in blocks
+my $exception = try {
+  close(STDERR);
   $schema->resultset('CD')->search({})->count;
-} 'Died on closed FH';
+} catch {
+  $_
+} finally {
+  # restore STDERR
+  open(STDERR, '>&STDERRCOPY');
+};
+
+like $exception, qr/\QDuplication of STDERR for debug output failed (perhaps your STDERR is closed?)/;
+
 
-open(STDERR, '>&STDERRCOPY');
 
 # test debugcb and debugobj protocol
 {