Skip some POSIX tests when the thing they are testing is unimplemented
[p5sagit/p5-mst-13.2.git] / ext / POSIX / t / termios.t
1 #!perl -T
2
3 BEGIN {
4     if ($ENV{PERL_CORE}) {
5         chdir 't';
6         @INC = '../lib';
7     }
8
9     use Config;
10     use Test::More;
11     plan skip_all => "POSIX is unavailable" 
12         if $Config{'extensions'} !~ m!\bPOSIX\b!;
13 }
14 use strict;
15 use POSIX;
16 BEGIN {
17     plan skip_all => "POSIX::Termios not implemented" 
18         if  !eval "POSIX::Termios->new;1"
19         and $@=~/not implemented/;
20 }
21
22
23 my @getters = qw(getcflag getiflag getispeed getlflag getoflag getospeed);
24
25 plan tests => 3 + 2 * (3 + NCCS() + @getters);
26
27 my $r;
28
29 # create a new object
30 my $termios = eval { POSIX::Termios->new };
31 is( $@, '', "calling POSIX::Termios->new" );
32 ok( defined $termios, "\tchecking if the object is defined" );
33 isa_ok( $termios, "POSIX::Termios", "\tchecking the type of the object" );
34
35 # testing getattr()
36
37 SKIP: {
38     -t STDIN or skip("STDIN not a tty", 2);
39     $r = eval { $termios->getattr(0) };
40     is( $@, '', "calling getattr(0)" );
41     ok( defined $r, "\tchecking if the returned value is defined: $r" );
42 }
43
44 SKIP: {
45     -t STDOUT or skip("STDOUT not a tty", 2);
46     $r = eval { $termios->getattr(1) };
47     is( $@, '', "calling getattr(1)" );
48     ok( defined $r, "\tchecking if the returned value is defined: $r" );
49 }
50
51 SKIP: {
52     -t STDERR or skip("STDERR not a tty", 2);
53     $r = eval { $termios->getattr(2) };
54     is( $@, '', "calling getattr(2)" );
55     ok( defined $r, "\tchecking if the returned value is defined: $r" );
56 }
57
58 # testing getcc()
59 for my $i (0..NCCS()-1) {
60     $r = eval { $termios->getcc($i) };
61     is( $@, '', "calling getcc($i)" );
62     ok( defined $r, "\tchecking if the returned value is defined: $r" );
63 }
64
65 # testing getcflag()
66 for my $method (@getters) {
67     $r = eval { $termios->$method() };
68     is( $@, '', "calling $method()" );
69     ok( defined $r, "\tchecking if the returned value is defined: $r" );
70 }
71