Beefy Boxes and Bandwidth Generously Provided by pair Networks chromatic writing perl on a camel
Keep It Simple, Stupid

boftx's scratchpad

by boftx (Hermit)
on Aug 15, 2013 at 04:43 UTC ( #1049511=scratchpad: print w/ replies, xml ) Need Help??

Here is what I've got so far to test the tmpdir stuff :)

#!perl -T use 5.008_008; use strict; use warnings FATAL => 'all'; use Test::More; use Try::Tiny; use File::Temp; use Cwd; use POSIX qw( getcwd ); plan tests => 4; # it is not possible to properly test this module if we can not reliab +ly # create and chdir to temp dirs. # NOTE! the value from cwd is tainted! #cwd() =~ /^(.+)/o; #my $cwd = $1 or die $!; my $cwd = POSIX::getcwd(); diag("original cwd: $cwd"); my $realtmp; { # inner scope for File::Temp to work in # all tests must be within this scope to prevent droping the tmp d +ir! my $tmpdir = File::Temp->newdir; # NOTE! the value from realpath is tainted! Cwd::realpath($tmpdir) =~ /^(.+)$/; die "Can't get realpath for $tmpdir" unless ( $realtmp = $1 ); diag("will chdir to $realtmp"); ok( -d $realtmp, 'tmpdir exists in scope' ); chdir $realtmp or BAIL_OUT("Can't chdir to tmpdir $realtmp: $!"); my $newcwd = cwd(); ok( $newcwd eq $realtmp, "Chdir to $realtmp" ); diag("New cwd: $newcwd"); # have to get out of the tmpdir for it to be removed chdir $cwd or BAIL_OUT("Can not restore original cwd: $!"); my $final_cwd = cwd(); diag("back in $final_cwd"); ok( $cwd eq $final_cwd, "chdir back to original cwd: $cwd" ); # the tmpdir and all files will disappear when we go out of this b +lock } ok( !( -d $realtmp ), 'tmpdir does not exist out of scope' ); diag("$realtmp was removed"); exit;
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2014-04-23 22:28 GMT
Find Nodes?
    Voting Booth?

    April first is:

    Results (556 votes), past polls