Commit | Line | Data |
---|---|---|
d2e38af7 Z |
1 | use warnings; |
2 | use strict; | |
3 | ||
4 | use Config; | |
5 | use Errno qw(ENOENT); | |
6 | use File::Temp qw(tempdir); | |
7 | use Test::More; | |
8 | ||
9e783da9 Z |
9 | if($^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 |
14 | my $tmp = tempdir(CLEANUP => 1); |
15 | unless(mkdir("$tmp/testdir") && chdir("$tmp/testdir") && rmdir("$tmp/testdir")){ | |
16 | plan skip_all => "can't be in non-existent directory"; | |
17 | } | |
18 | ||
19 | plan tests => 8; | |
d2e38af7 Z |
20 | require Cwd; |
21 | ||
22 | foreach 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 | ||
48 | chdir $tmp or die "$tmp: $!"; | |
49 | ||
e8d0f503 JK |
50 | END { chdir $tmp; } |
51 | ||
d2e38af7 | 52 | 1; |