use Scalar::Util qw(looks_like_number);
my @path_consts = qw(
- _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON _PC_MAX_INPUT
- _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX _PC_PIPE_BUF _PC_VDISABLE
+ _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_NAME_MAX
+ _PC_NO_TRUNC _PC_PATH_MAX
+);
+
+my @path_consts_terminal = qw(
+ _PC_MAX_CANON _PC_MAX_INPUT _PC_VDISABLE
+);
+
+my @path_consts_fifo = qw(
+ _PC_PIPE_BUF
);
my @sys_consts = qw(
_SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
);
-plan tests => 2 * 3 * @path_consts + 3 * @sys_consts;
+plan tests => 2 * 3 * @path_consts +
+ 3 * @path_consts_terminal +
+ 2 * 3 * @path_consts_fifo +
+ 3 * @sys_consts;
+
+my $curdir = File::Spec->curdir;
my $r;
-# testing fpathconf()
+# testing fpathconf() on a non-terminal file
SKIP: {
- my $fd = POSIX::open(File::Spec->curdir, O_RDONLY)
- or skip "can't open current directory", 3 * @path_consts;
+ my $fd = POSIX::open($curdir, O_RDONLY)
+ or skip "could not open current directory ($!)", 3 * @path_consts;
for my $constant (@path_consts) {
- $r = eval { pathconf( File::Spec->curdir, eval "$constant()" ) };
- is( $@, '', "calling pathconf($constant)" );
+ $r = eval { fpathconf( $fd, eval "$constant()" ) };
+ is( $@, '', "calling fpathconf($fd, $constant) " );
ok( defined $r, "\tchecking that the returned value is defined: $r" );
ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
}
+
+ POSIX::close($fd);
}
-# testing pathconf()
+# testing pathconf() on a non-terminal file
for my $constant (@path_consts) {
- $r = eval { pathconf( File::Spec->rootdir, eval "$constant()" ) };
- is( $@, '', "calling pathconf($constant)" );
+ $r = eval { pathconf( $curdir, eval "$constant()" ) };
+ is( $@, '', qq[calling pathconf("$curdir", $constant)] );
ok( defined $r, "\tchecking that the returned value is defined: $r" );
ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
}
+SKIP: {
+ -c "/dev/tty"
+ or skip("/dev/tty not a character file", 3 * @path_consts_terminal);
+
+ # testing pathconf() on a terminal file
+ for my $constant (@path_consts_terminal) {
+ $r = eval { pathconf( "/dev/tty", eval "$constant()" ) };
+ is( $@, '', qq[calling pathconf("/dev/tty", $constant)] );
+ ok( defined $r, "\tchecking that the returned value is defined: $r" );
+ ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
+ }
+}
+
+my $fifo = "fifo$$";
+
+SKIP: {
+ mkfifo($fifo, 0666)
+ or skip("could not create fifo $fifo ($!)", 2 * 3 * @path_consts_fifo);
+
+ SKIP: {
+ my $fd = POSIX::open($fifo, O_RDWR)
+ or skip("could not open $fifo ($!)", 3 * @path_consts_fifo);
+
+ for my $constant (@path_consts_fifo) {
+ $r = eval { fpathconf( $fd, eval "$constant()" ) };
+ is( $@, '', "calling fpathconf($fd, $constant) " );
+ ok( defined $r, "\tchecking that the returned value is defined: $r" );
+ ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
+ }
+
+ POSIX::close($fd);
+ }
+
+ SKIP: {
+ # testing pathconf() on a fifo file
+ for my $constant (@path_consts_fifo) {
+ $r = eval { pathconf( $fifo, eval "$constant()" ) };
+ is( $@, '', qq[calling pathconf($fifo, $constant)] );
+ ok( defined $r, "\tchecking that the returned value is defined: $r" );
+ ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
+ }
+ }
+}
+
+unlink($fifo);
+
# testing sysconf()
for my $constant (@sys_consts) {
$r = eval { sysconf( eval "$constant()" ) };
isa_ok( $termios, "POSIX::Termios", "\tchecking the type of the object" );
# testing getattr()
-for my $i (0..2) {
- $r = eval { $termios->getattr($i) };
- is( $@, '', "calling getattr($i)" );
+
+SKIP: {
+ -t STDIN or skip("STDIN not a tty", 2);
+ $r = eval { $termios->getattr(0) };
+ is( $@, '', "calling getattr(0)" );
+ ok( defined $r, "\tchecking if the returned value is defined: $r" );
+}
+
+SKIP: {
+ -t STDOUT or skip("STDOUT not a tty", 2);
+ $r = eval { $termios->getattr(1) };
+ is( $@, '', "calling getattr(1)" );
+ ok( defined $r, "\tchecking if the returned value is defined: $r" );
+}
+
+SKIP: {
+ -t STDERR or skip("STDERR not a tty", 2);
+ $r = eval { $termios->getattr(2) };
+ is( $@, '', "calling getattr(2)" );
ok( defined $r, "\tchecking if the returned value is defined: $r" );
}