File: handle.t

package info (click to toggle)
libfile-slurp-perl 9999.32-2.1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 412 kB
  • sloc: perl: 650; makefile: 39
file content (46 lines) | stat: -rw-r--r-- 967 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;

use File::Slurp qw(read_file write_file);

use IO::Handle ();
use Socket;
use Symbol;
use Test::More;

my @pipe_data = (
    '',
    'abc',
    'abc' x 100,
    'abc' x 1000,
);

plan tests => scalar(@pipe_data);

foreach my $data ( @pipe_data ) {
    my $size = length( $data );
    my $read_fh = gensym;
    my $write_fh = gensym;
    my $value;
    my $error;
    { # catch block
        local $@;
        $error = $@ || 'Error' unless eval {
            $value = socketpair($read_fh, $write_fh, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
            1;
        }; # try
    }
    SKIP: {
        skip "Can't use socketpair", 1 unless $value;
        if (fork()) {
            $write_fh->close();
            my $res = read_file($read_fh);
            is($res, $data, "read_file: socketpair of $size bytes");
        }
        else {
            $read_fh->close();
            write_file($write_fh, $data);
            exit();
        }
    };
}