[perl #57320] touch /tmp/t && make test => fails t/perl/Parrot_IO.t ?

James Keenan via RT parrotbug-followup at parrotcode.org
Mon Dec 8 02:11:25 UTC 2008


On Sun Dec 07 16:39:39 2008, jkeen at verizon.net wrote:

> 
> This requires more study.
> 

I've been trying to wrap my brain around this.  It seems to me that
there are objectionable features in *both* lib/Parrot/IO/Directory.pm
and t/perl/Parrot_IO.t.

1. lib/Parrot/IO/Directory.pm:  Unsophisticated use of
File::Spec->tmpdir() in tmp_directory():

  sub tmp_directory {
    my $self = shift;

    return $self->directory_with_path( File::Spec->catdir(
File::Spec->tmpdir, @_ ) );
  }

I say 'unsophisticated' because File::Spec->tmpdir() is only guaranteed
to return "the a string representation of the first writable directory
from a list of possible temporary directories" (with the current
directory as a fall back).  I suspect that in most cases the "first
writable directory" will be '/tmp' -- which leads into Eric's original
point about the danger of simplistically named directories and files
underneath '/tmp'.

2.  t/perl/Parrot_IO.t:  Similarly unsophisticated use of
File::Spec->tmpdir() and File::Spec->rootdir().

tmpdir() is used in this subroutine:

  sub tmp_dir_path {
    return catdir( tmpdir, @_ );
  }

... which is used throughout the test file, particularly here:

  sub tmp_file_path {
    my $file;

    if ( @_ == 1 ) {
        $file = catfile( tmp_dir_path(), shift );
    }
    else {
        $file = pop(@_);
        $file = catfile( tmp_dir_path(@_), $file );
    }

    return $file;
  }

... which is also found throughout the test file.

File::Spec->rootdir() is used at two points:

  my $r = Parrot::IO::Path->new( rootdir() );
  ok( !$r->parent_path(), 'root has no parent_path' );

... and:

  $r = Parrot::IO::Directory->new(rootdir);
  ok( $r, 'new' );
  isa_ok( $r, 'Parrot::IO::Directory' );
  ok( !$r->parent(), 'root has no parent' );

File::Spec is mainly oriented toward providing us with *names* of
directories and files -- whether it makes sense to create or write in
those directories or not.  But, as Coke suggested, what we really ought
to be concerned with are the safely writable temporary directories and
files provided by File::Temp.

Whether that is what we ought to be aiming for depends on a prior
question:  What do we use the Parrot::IO::* classes for in the first place?


More information about the parrot-dev mailing list