Enable warnings in File::* (was: B::Terse and warnings)
[p5sagit/p5-mst-13.2.git] / t / lib / cwd.t
CommitLineData
ed4a5f99 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
7
8use Config;
9use Cwd;
10use strict;
11use warnings;
12
d19fbd04 13print "1..10\n";
ed4a5f99 14
15# check imports
16print +(defined(&cwd) &&
17 defined(&getcwd) &&
18 defined(&fastcwd) &&
19 defined(&fastgetcwd) ?
20 "" : "not "), "ok 1\n";
21print +(!defined(&chdir) &&
22 !defined(&abs_path) &&
23 !defined(&fast_abs_path) ?
24 "" : "not "), "ok 2\n";
25
ed4a5f99 26mkdir "pteerslt", 0777;
27mkdir "pteerslt/path", 0777;
28mkdir "pteerslt/path/to", 0777;
29mkdir "pteerslt/path/to/a", 0777;
30mkdir "pteerslt/path/to/a/dir", 0777;
31Cwd::chdir "pteerslt/path/to/a/dir";
32my $cwd = cwd;
33my $getcwd = getcwd;
34my $fastcwd = fastcwd;
35my $fastgetcwd = fastgetcwd;
36my $want = "t/pteerslt/path/to/a/dir";
d19fbd04 37print +($cwd =~ m|$want$| ? "" : "not "), "ok 3\n";
38print +($getcwd =~ m|$want$| ? "" : "not "), "ok 4\n";
39print +($fastcwd =~ m|$want$| ? "" : "not "), "ok 5\n";
40print +($fastgetcwd =~ m|$want$| ? "" : "not "), "ok 6\n";
ed4a5f99 41
42# Cwd::chdir should also update $ENV{PWD}
d19fbd04 43print +($ENV{PWD} =~ m|$want$| ? "" : "not "), "ok 7\n";
ed4a5f99 44Cwd::chdir ".."; rmdir "dir";
45Cwd::chdir ".."; rmdir "a";
46Cwd::chdir ".."; rmdir "to";
47Cwd::chdir ".."; rmdir "path";
48Cwd::chdir ".."; rmdir "pteerslt";
d19fbd04 49print +($ENV{PWD} =~ m|\bt$| ? "" : "not "), "ok 8\n";
ed4a5f99 50
51if ($Config{d_symlink}) {
52 my @dirs = split " " => $Config{libpth};
53 my $target = pop @dirs;
54 symlink $target => "linktest";
55 mkdir "pteerslt";
56 chdir "pteerslt";
57 my $rel = "../../t/linktest";
58
59 my $abs_path = Cwd::abs_path($rel);
60 my $fast_abs_path = Cwd::fast_abs_path($rel);
d19fbd04 61 print +($abs_path eq $target ? "" : "not "), "ok 9\n";
62 print +($fast_abs_path eq $target ? "" : "not "), "ok 10\n";
ed4a5f99 63
64 chdir "..";
65 rmdir "pteerslt";
66 unlink "linktest";
67} else {
d19fbd04 68 print "ok 9 # Skip: no symlink\n";
69 print "ok 10 # Skip: no symlink\n";
ed4a5f99 70}