File: fd_leak.t

package info (click to toggle)
libipc-run3-perl 0.036-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 152 kB
  • ctags: 82
  • sloc: perl: 1,016
file content (53 lines) | stat: -rw-r--r-- 1,005 bytes parent folder | download | duplicates (6)
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
52
53
#!perl -w

use Test::More;

use IPC::Run3;
use strict;

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;