This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Ensure temp directories are cleaned up.
[perl5.git] / dist / PathTools / t / cwd_enoent.t
CommitLineData
d2e38af7
Z
1use warnings;
2use strict;
3
4use Config;
5use Errno qw(ENOENT);
6use File::Temp qw(tempdir);
7use Test::More;
8
9e783da9
Z
9if($^O eq "cygwin") {
10 # This test skipping should be removed when the Cygwin bug is fixed.
11 plan skip_all => "getcwd() fails to fail on Cygwin [perl #132733]";
12}
13
d2e38af7
Z
14my $tmp = tempdir(CLEANUP => 1);
15unless(mkdir("$tmp/testdir") && chdir("$tmp/testdir") && rmdir("$tmp/testdir")){
16 plan skip_all => "can't be in non-existent directory";
17}
18
19plan tests => 8;
d2e38af7
Z
20require Cwd;
21
22foreach my $type (qw(regular perl)) {
23 SKIP: {
24 skip "_perl_abs_path() not expected to work", 4
25 if $type eq "perl" &&
26 !(($Config{prefix} =~ m/\//) && $^O ne "cygwin");
02bf4969
TK
27
28 skip "getcwd() doesn't fail on non-existent directories on this platform", 4
29 if $type eq 'regular' && $^O eq 'dragonfly';
30
d2e38af7
Z
31 no warnings "redefine";
32 local *Cwd::abs_path = \&Cwd::_perl_abs_path if $type eq "perl";
33 local *Cwd::getcwd = \&Cwd::_perl_getcwd if $type eq "perl";
34 my($res, $eno);
35 $! = 0;
36 $res = Cwd::getcwd();
37 $eno = 0+$!;
38 is $res, undef, "$type getcwd result on non-existent directory";
39 is $eno, ENOENT, "$type getcwd errno on non-existent directory";
40 $! = 0;
41 $res = Cwd::abs_path(".");
42 $eno = 0+$!;
43 is $res, undef, "$type abs_path result on non-existent directory";
44 is $eno, ENOENT, "$type abs_path errno on non-existent directory";
45 }
46}
47
48chdir $tmp or die "$tmp: $!";
49
e8d0f503
JK
50END { chdir $tmp; }
51
d2e38af7 521;