File: fd_leak.t

package info (click to toggle)
libipc-run3-perl 0.049-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 200 kB
  • sloc: perl: 1,179; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,082 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!perl
use strict;
use warnings;

use Test::More;

use IPC::Run3;

my ( $in, $out, $err ) = @_;

sub leaky
{
    my ($what) = @_;

    my $before_fd = IPC::Run3::_max_fd();
    my $desc = join ",", map {
      defined $_ ? ref $_ ? ( $_ == \undef ) ? "\\undef"
                                             : ref $_
                          : "'$_'"
                 : 'undef';
    } @$what;

    run3 [$^X, '-e1' ], @$what;

    my $after_fd = IPC::Run3::_max_fd();

    # on a sane system we'd expect == below,
    # but apparently Darwin 7.2 is stranger than fiction
    ok($after_fd <= $before_fd, "run3 [...],$desc");
}

my @tests = (
    [],
    [ \undef               ],
    [ \$in                 ],
    [ $0                   ],
    [ undef,  \$out        ],
    [ undef,  undef, \$err ],
    [ undef,  \$out, \$err ],
    [ \undef, \$out, \$err ],
    [ \$in,   \$out, \$err ],
    [ $0,     \$out, \$err ],
);

plan tests => 1+@tests;

## Force run3() to open some temp files.
run3 [$^X, '-e1' ], \$in, \$out, \$err;
ok(1, "open some temp files");

leaky($_) for @tests;