Codebase list libcapture-tiny-perl / a36a69a
check for file descriptor leaks David Golden 15 years ago
5 changed file(s) with 33 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
66 use strict;
77 use warnings;
88 use Test::More;
9 use t::lib::Utils qw/next_fd/;
910 use t::lib::Tests qw/capture_tests capture_count/;
1011
11 plan tests => capture_count();
12 plan tests => 1 + capture_count();
13
14 my $fd = next_fd;
1215
1316 capture_tests();
1417
18 is( next_fd, $fd, "no file descriptors leaked" );
66 use strict;
77 use warnings;
88 use Test::More;
9 use t::lib::Utils qw/next_fd/;
910 use t::lib::Tests qw/tee_tests tee_count/;
1011
1112 use Config;
1314 plan skip_all => "requires working fork()";
1415 }
1516
16 plan tests => tee_count();
17 plan tests => 1 + tee_count();
18
19 my $fd = next_fd;
1720
1821 tee_tests();
22
23 is( next_fd, $fd, "no file descriptors leaked" );
66 use strict;
77 use warnings;
88 use Test::More;
9 use t::lib::Utils qw/next_fd/;
910 use t::lib::Tests qw/capture_merged_tests capture_merged_count/;
1011
11 plan tests => capture_merged_count();
12 plan tests => 1 + capture_merged_count();
13
14 my $fd = next_fd;
1215
1316 capture_merged_tests();
1417
18 is( next_fd, $fd, "no file descriptors leaked" );
19
66 use strict;
77 use warnings;
88 use Test::More;
9 use t::lib::Utils qw/next_fd/;
910 use t::lib::Tests qw/ tee_merged_tests tee_merged_count /;
1011
1112 use Config;
1314 plan skip_all => "requires working fork()";
1415 }
1516
16 plan tests => tee_merged_count;
17 plan tests => 1 + tee_merged_count;
18
19 my $fd = next_fd;
20
1721 tee_merged_tests();
1822
23 is( next_fd, $fd, "no file descriptors leaked" );
24
00 package t::lib::Utils;
11 use strict;
22 use warnings;
3 use File::Spec;
34
45 require Exporter;
56 our @ISA = 'Exporter';
6 our @EXPORT = qw/save_std restore_std/;
7 our @EXPORT = qw/save_std restore_std next_fd/;
78
89 sub _open {
910 open $_[0], $_[1] or die "Error from open( " . join(q{, }, @_) . "): $!";
2728 }
2829 }
2930
31 sub next_fd {
32 open my $fh, ">", File::Spec->devnull;
33 my $fileno = fileno $fh;
34 close $fh;
35 return $fileno;
36 }
37
3038 1;