Repository navigation
Expand file tree
/
Copy pathslave.t
More file actions
55 lines (44 loc) · 1.29 KB
/
Copy pathslave.t
File metadata and controls
55 lines (44 loc) · 1.29 KB
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
54
55
#!perl
use strict;
use warnings;
use Test::More tests => 8;
use IO::Pty;
require POSIX;
# Test slave() returns a valid tty
{
my $pty = IO::Pty->new;
ok( defined $pty, "IO::Pty created" );
my $slave = $pty->slave;
ok( defined $slave, "slave() returns a handle" );
ok( POSIX::isatty($slave), "slave is a tty" );
}
# Test close_slave() and slave re-opening
{
my $pty = IO::Pty->new;
my $slave1 = $pty->slave;
my $fileno1 = fileno($slave1);
ok( defined $fileno1, "first slave has a fileno" );
$pty->close_slave();
# After close_slave, calling slave() should re-open it
my $slave2 = $pty->slave;
ok( defined $slave2, "slave() works after close_slave()" );
ok( POSIX::isatty($slave2), "re-opened slave is a tty" );
}
# Test that calling slave() twice returns the same object
{
my $pty = IO::Pty->new;
my $slave1 = $pty->slave;
my $slave2 = $pty->slave;
is( fileno($slave1), fileno($slave2),
"slave() returns same handle when not closed" );
}
# Test that slave() after close_slave() gets a fresh handle
{
my $pty = IO::Pty->new;
my $slave1 = $pty->slave;
my $fn1 = fileno($slave1);
$pty->close_slave();
my $slave2 = $pty->slave;
ok( defined fileno($slave2),
"re-opened slave has a valid fileno" );
}