Commit | Line | Data |
ed4a5f99 |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | @INC = '../lib'; |
6 | } |
7 | |
8 | use Config; |
9 | use Cwd; |
10 | use strict; |
11 | use warnings; |
12 | |
da3f15f4 |
13 | print "1..14\n"; |
ed4a5f99 |
14 | |
15 | # check imports |
16 | print +(defined(&cwd) && |
17 | defined(&getcwd) && |
18 | defined(&fastcwd) && |
19 | defined(&fastgetcwd) ? |
20 | "" : "not "), "ok 1\n"; |
21 | print +(!defined(&chdir) && |
22 | !defined(&abs_path) && |
23 | !defined(&fast_abs_path) ? |
24 | "" : "not "), "ok 2\n"; |
25 | |
da3f15f4 |
26 | # Must find an external pwd (or equivalent) command. |
27 | |
28 | my $pwd_cmd = |
29 | ($^O eq "Win32") ? "cd" : (grep { -x && -f } map { "$_/pwd" } |
30 | split m/$Config{path_sep}/, $ENV{PATH})[0]; |
31 | |
32 | if (defined $pwd_cmd) { |
33 | chomp(my $start = `$pwd_cmd`); |
34 | if ($?) { |
35 | for (3..6) { |
36 | print "ok $_ # Skip: '$pwd_cmd' failed\n"; |
37 | } |
38 | } else { |
39 | my $cwd = cwd; |
40 | my $getcwd = getcwd; |
41 | my $fastcwd = fastcwd; |
42 | my $fastgetcwd = fastgetcwd; |
43 | print +($cwd eq $start ? "" : "not "), "ok 3\n"; |
44 | print +($getcwd eq $start ? "" : "not "), "ok 4\n"; |
45 | print +($fastcwd eq $start ? "" : "not "), "ok 5\n"; |
46 | print +($fastgetcwd eq $start ? "" : "not "), "ok 6\n"; |
47 | } |
48 | } else { |
49 | for (3..6) { |
50 | print "ok $_ # Skip: no pwd command found\n"; |
51 | } |
52 | } |
53 | |
ed4a5f99 |
54 | mkdir "pteerslt", 0777; |
55 | mkdir "pteerslt/path", 0777; |
56 | mkdir "pteerslt/path/to", 0777; |
57 | mkdir "pteerslt/path/to/a", 0777; |
58 | mkdir "pteerslt/path/to/a/dir", 0777; |
59 | Cwd::chdir "pteerslt/path/to/a/dir"; |
60 | my $cwd = cwd; |
61 | my $getcwd = getcwd; |
62 | my $fastcwd = fastcwd; |
63 | my $fastgetcwd = fastgetcwd; |
64 | my $want = "t/pteerslt/path/to/a/dir"; |
da3f15f4 |
65 | print +($cwd =~ m|$want$| ? "" : "not "), "ok 7\n"; |
66 | print +($getcwd =~ m|$want$| ? "" : "not "), "ok 8\n"; |
67 | print +($fastcwd =~ m|$want$| ? "" : "not "), "ok 9\n"; |
68 | print +($fastgetcwd =~ m|$want$| ? "" : "not "), "ok 10\n"; |
ed4a5f99 |
69 | |
70 | # Cwd::chdir should also update $ENV{PWD} |
da3f15f4 |
71 | print +($ENV{PWD} =~ m|$want$| ? "" : "not "), "ok 11\n"; |
ed4a5f99 |
72 | Cwd::chdir ".."; rmdir "dir"; |
73 | Cwd::chdir ".."; rmdir "a"; |
74 | Cwd::chdir ".."; rmdir "to"; |
75 | Cwd::chdir ".."; rmdir "path"; |
76 | Cwd::chdir ".."; rmdir "pteerslt"; |
da3f15f4 |
77 | print +($ENV{PWD} =~ m|\bt$| ? "" : "not "), "ok 12\n"; |
ed4a5f99 |
78 | |
79 | if ($Config{d_symlink}) { |
80 | my @dirs = split " " => $Config{libpth}; |
81 | my $target = pop @dirs; |
82 | symlink $target => "linktest"; |
83 | mkdir "pteerslt"; |
84 | chdir "pteerslt"; |
85 | my $rel = "../../t/linktest"; |
86 | |
87 | my $abs_path = Cwd::abs_path($rel); |
88 | my $fast_abs_path = Cwd::fast_abs_path($rel); |
da3f15f4 |
89 | print +($abs_path eq $target ? "" : "not "), "ok 13\n"; |
90 | print +($fast_abs_path eq $target ? "" : "not "), "ok 14\n"; |
ed4a5f99 |
91 | |
92 | chdir ".."; |
93 | rmdir "pteerslt"; |
94 | unlink "linktest"; |
95 | } else { |
da3f15f4 |
96 | print "ok 13 # skipped\n"; |
97 | print "ok 14 # skipped\n"; |
ed4a5f99 |
98 | } |