File: diagnostics.t

package info (click to toggle)
libio-stream-perl 2.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 332 kB
  • sloc: perl: 775; makefile: 7
file content (35 lines) | stat: -rw-r--r-- 1,874 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
use warnings;
use strict;
use lib 't';
use share;

plan tests => 19;

throws_ok { IO::Stream->new()                                   } qr/usage:/;
throws_ok { IO::Stream->new(undef)                              } qr/usage:/;
throws_ok { IO::Stream->new(1)                                  } qr/usage:/;
throws_ok { IO::Stream->new({})                                 } qr/usage:/;
throws_ok { IO::Stream->new({'cb'=>undef,fh=>1})                } qr/usage:/;
throws_ok { IO::Stream->new({'cb'=>sub{}})                      } qr/usage:/;
throws_ok { IO::Stream->new({'cb'=>sub{},fh=>undef})            } qr/usage:/;
throws_ok { IO::Stream->new({'cb'=>sub{},host=>undef})          } qr/usage:/;
throws_ok { IO::Stream->new({'cb'=>sub{},host=>1})              } qr/usage:/;
throws_ok { IO::Stream->new({'cb'=>sub{},host=>1,port=>undef})  } qr/usage:/;
throws_ok { IO::Stream->new({'cb'=>sub{},fh=>1,host=>1})        } qr/usage:/;

my ($io, $fh, $tmp);

socketpair $fh, $tmp, AF_UNIX, SOCK_STREAM, PF_UNSPEC or die "socketpair: $!";
lives_ok  { $io=IO::Stream->new({cb=>sub{},fh=>$fh}) };
throws_ok { IO::Stream->new({cb=>sub{},fh=>$fh})                } qr/same fh/;
throws_ok { IO::Stream->new({cb=>sub{},fh=>$fh})                } qr/same fh/;
close $fh;
throws_ok { IO::Stream->new({cb=>sub{},fh=>$fh})                } qr/descriptor/;
socketpair $fh, $tmp, AF_UNIX, SOCK_STREAM, PF_UNSPEC or die "socketpair: $!";
throws_ok { IO::Stream->new({cb=>sub{},fh=>$fh})                } qr/same fh/;
$io->close();   # will close current $fh because they've same fileno()!
throws_ok { IO::Stream->new({cb=>sub{},fh=>$fh})                } qr/descriptor/;
socketpair $fh, $tmp, AF_UNIX, SOCK_STREAM, PF_UNSPEC or die "socketpair: $!";
lives_ok  { IO::Stream->new({'cb'=>sub{},fh=>$fh})->close() };
throws_ok { IO::Stream->new({'cb'=>sub{},fh=>$fh})              } qr/descriptor/;