check for file descriptor leaks
David Golden
15 years ago
6 | 6 |
use strict;
|
7 | 7 |
use warnings;
|
8 | 8 |
use Test::More;
|
|
9 |
use t::lib::Utils qw/next_fd/;
|
9 | 10 |
use t::lib::Tests qw/capture_tests capture_count/;
|
10 | 11 |
|
11 | |
plan tests => capture_count();
|
|
12 |
plan tests => 1 + capture_count();
|
|
13 |
|
|
14 |
my $fd = next_fd;
|
12 | 15 |
|
13 | 16 |
capture_tests();
|
14 | 17 |
|
|
18 |
is( next_fd, $fd, "no file descriptors leaked" );
|
6 | 6 |
use strict;
|
7 | 7 |
use warnings;
|
8 | 8 |
use Test::More;
|
|
9 |
use t::lib::Utils qw/next_fd/;
|
9 | 10 |
use t::lib::Tests qw/tee_tests tee_count/;
|
10 | 11 |
|
11 | 12 |
use Config;
|
|
13 | 14 |
plan skip_all => "requires working fork()";
|
14 | 15 |
}
|
15 | 16 |
|
16 | |
plan tests => tee_count();
|
|
17 |
plan tests => 1 + tee_count();
|
|
18 |
|
|
19 |
my $fd = next_fd;
|
17 | 20 |
|
18 | 21 |
tee_tests();
|
|
22 |
|
|
23 |
is( next_fd, $fd, "no file descriptors leaked" );
|
6 | 6 |
use strict;
|
7 | 7 |
use warnings;
|
8 | 8 |
use Test::More;
|
|
9 |
use t::lib::Utils qw/next_fd/;
|
9 | 10 |
use t::lib::Tests qw/capture_merged_tests capture_merged_count/;
|
10 | 11 |
|
11 | |
plan tests => capture_merged_count();
|
|
12 |
plan tests => 1 + capture_merged_count();
|
|
13 |
|
|
14 |
my $fd = next_fd;
|
12 | 15 |
|
13 | 16 |
capture_merged_tests();
|
14 | 17 |
|
|
18 |
is( next_fd, $fd, "no file descriptors leaked" );
|
|
19 |
|
6 | 6 |
use strict;
|
7 | 7 |
use warnings;
|
8 | 8 |
use Test::More;
|
|
9 |
use t::lib::Utils qw/next_fd/;
|
9 | 10 |
use t::lib::Tests qw/ tee_merged_tests tee_merged_count /;
|
10 | 11 |
|
11 | 12 |
use Config;
|
|
13 | 14 |
plan skip_all => "requires working fork()";
|
14 | 15 |
}
|
15 | 16 |
|
16 | |
plan tests => tee_merged_count;
|
|
17 |
plan tests => 1 + tee_merged_count;
|
|
18 |
|
|
19 |
my $fd = next_fd;
|
|
20 |
|
17 | 21 |
tee_merged_tests();
|
18 | 22 |
|
|
23 |
is( next_fd, $fd, "no file descriptors leaked" );
|
|
24 |
|
0 | 0 |
package t::lib::Utils;
|
1 | 1 |
use strict;
|
2 | 2 |
use warnings;
|
|
3 |
use File::Spec;
|
3 | 4 |
|
4 | 5 |
require Exporter;
|
5 | 6 |
our @ISA = 'Exporter';
|
6 | |
our @EXPORT = qw/save_std restore_std/;
|
|
7 |
our @EXPORT = qw/save_std restore_std next_fd/;
|
7 | 8 |
|
8 | 9 |
sub _open {
|
9 | 10 |
open $_[0], $_[1] or die "Error from open( " . join(q{, }, @_) . "): $!";
|
|
27 | 28 |
}
|
28 | 29 |
}
|
29 | 30 |
|
|
31 |
sub next_fd {
|
|
32 |
open my $fh, ">", File::Spec->devnull;
|
|
33 |
my $fileno = fileno $fh;
|
|
34 |
close $fh;
|
|
35 |
return $fileno;
|
|
36 |
}
|
|
37 |
|
30 | 38 |
1;
|