This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
8f3a1fb1fb3eeb7e217f26f53d09bf6264f916c0
[perl5.git] / dist / PathTools / t / cwd_enoent.t
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
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
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;
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");
27
28         skip "getcwd() doesn't fail on non-existent directories on this platform", 4
29             if $type eq 'regular' && $^O eq 'dragonfly';
30
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
50 END { chdir $tmp; }
51
52 1;