Blame t/16-catch-errors.t

Packit d18d0a
# Copyright (c) 2009 by David Golden. All rights reserved.
Packit d18d0a
# Licensed under Apache License, Version 2.0 (the "License").
Packit d18d0a
# You may not use this file except in compliance with the License.
Packit d18d0a
# A copy of the License was distributed with this file or you may obtain a
Packit d18d0a
# copy of the License from http://www.apache.org/licenses/LICENSE-2.0
Packit d18d0a
Packit d18d0a
use strict;
Packit d18d0a
use warnings;
Packit d18d0a
use Test::More;
Packit d18d0a
use lib 't/lib';
Packit d18d0a
use Utils qw/next_fd sig_num/;
Packit d18d0a
use Capture::Tiny qw/capture tee/;
Packit d18d0a
use Config;
Packit d18d0a
Packit d18d0a
plan tests => 5;
Packit d18d0a
Packit d18d0a
local $ENV{PERL_CAPTURE_TINY_TIMEOUT} = 0; # no timeouts
Packit d18d0a
Packit d18d0a
my $builder = Test::More->builder;
Packit d18d0a
binmode($builder->failure_output, ':utf8') if $] >= 5.008;
Packit d18d0a
Packit d18d0a
my $fd = next_fd;
Packit d18d0a
$@ = "initial error";
Packit d18d0a
my ($out, $err) = capture { print "foo\n" };
Packit d18d0a
is( $@, 'initial error', "Initial \$\@ not lost during capture" );
Packit d18d0a
Packit d18d0a
Packit d18d0a
($out, $err) = capture {
Packit d18d0a
  eval {
Packit d18d0a
    tee {
Packit d18d0a
      local $|=1;
Packit d18d0a
      print STDOUT "foo\n";
Packit d18d0a
      print STDERR "bar\n";
Packit d18d0a
      die "Fatal error in capture\n";
Packit d18d0a
    }
Packit d18d0a
  };
Packit d18d0a
};
Packit d18d0a
my $error = $@;
Packit d18d0a
Packit d18d0a
is( $error, "Fatal error in capture\n", "\$\@ preserved after capture" );
Packit d18d0a
is( $out, "foo\n", "STDOUT still captured" );
Packit d18d0a
is( $err, "bar\n", "STDOUT still captured" );
Packit d18d0a
Packit d18d0a
is( next_fd, $fd, "no file descriptors leaked" );
Packit d18d0a
Packit d18d0a
exit 0;
Packit d18d0a