This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Refactor ext/POSIX/t/termios.t
[perl5.git] / ext / POSIX / t / termios.t
CommitLineData
674d0cd9 1#!perl -Tw
6e32c255 2
6e32c255 3use strict;
674d0cd9
NC
4use Config;
5use Test::More;
6
60e845e3 7BEGIN {
674d0cd9
NC
8 plan skip_all => "POSIX is unavailable"
9 if $Config{extensions} !~ m!\bPOSIX\b!;
60e845e3
YO
10}
11
674d0cd9 12use POSIX ':termios_h';
6e32c255 13
674d0cd9
NC
14plan skip_all => $@
15 if !eval "POSIX::Termios->new; 1" && $@ =~ /termios not implemented/;
6e32c255 16
6e32c255
AT
17
18# create a new object
19my $termios = eval { POSIX::Termios->new };
20is( $@, '', "calling POSIX::Termios->new" );
6e32c255
AT
21isa_ok( $termios, "POSIX::Termios", "\tchecking the type of the object" );
22
23# testing getattr()
674d0cd9
NC
24foreach my $name (qw(STDIN STDOUT STDERR)) {
25 my $handle = $::{$name};
26 SKIP: {
27 skip("$name not a tty", 2) unless -t $handle;
28 my $fileno = fileno $handle;
29 my $r = eval { $termios->getattr($fileno) };
30 is($@, '', "calling getattr($fileno) for $name");
31 isnt($r, undef, "returned value ($r) is defined");
32 }
6e32c255
AT
33}
34
35# testing getcc()
674d0cd9
NC
36for my $i (0..NCCS-1) {
37 my $r = eval { $termios->getcc($i) };
6e32c255 38 is( $@, '', "calling getcc($i)" );
674d0cd9 39 like($r, qr/\A-?[0-9]+\z/, 'returns an integer');
6e32c255
AT
40}
41
674d0cd9
NC
42for my $method (qw(getcflag getiflag getispeed getlflag getoflag getospeed)) {
43 my $r = eval { $termios->$method() };
6e32c255 44 is( $@, '', "calling $method()" );
674d0cd9 45 like($r, qr/\A-?[0-9]+\z/, 'returns an integer');
6e32c255
AT
46}
47
674d0cd9 48done_testing();