5 use lib File::Spec->catfile('t', 'lib');
9 my @platforms = qw(Cygwin Epoc Mac OS2 Unix VMS Win32);
10 my $tests_per_platform = 10;
14 my $vms_unix_mode = 0;
15 my $vms_real_root = 0;
19 if (eval 'require VMS::Feature') {
20 $vms_unix_rpt = VMS::Feature::current("filename_unix_report");
21 $vms_efs = VMS::Feature::current("efs_charset");
23 my $unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
24 my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || '';
25 $vms_unix_rpt = $unix_rpt =~ /^[ET1]/i;
26 $vms_efs = $efs_charset =~ /^[ET1]/i;
29 # Traditional VMS mode only if VMS is not in UNIX compatible mode.
30 $vms_unix_mode = ($vms_efs && $vms_unix_rpt);
32 # If we are in UNIX mode, we may or may not have a real root.
34 my $rootdir = File::Spec->rootdir;
35 $vms_real_root = 1 if ($rootdir eq '/');
41 plan tests => 1 + @platforms * $tests_per_platform;
44 Mac => 'Macintosh HD',
50 Mac => 'Mounted Volume',
58 foreach my $platform (@platforms) {
59 my $module = "File::Spec::$platform";
63 eval "require $module; 1";
65 skip "Can't load $module", $tests_per_platform
68 my $v = $volumes{$platform} || '';
69 my $other_v = $other_vols{$platform} || '';
71 # Fake out the environment on MacOS and Win32
75 local *{"File::Spec::Mac::rootdir"} = sub { "Macintosh HD:" };
76 local *{"File::Spec::Win32::_cwd"} = sub { "C:\\foo" };
81 my ($file, $base, $result);
83 $base = $module->catpath($v, $module->catdir('', 'foo'), '');
84 $base = $module->catdir($module->rootdir, 'foo');
86 is $module->file_name_is_absolute($base), 1, "$base is absolute on $platform";
89 my @result = $module->splitdir('');
90 is @result, 0, "$platform->splitdir('') -> ()";
92 # canonpath() -> undef
93 $result = $module->canonpath();
94 is $result, undef, "$platform->canonpath() -> undef";
96 # canonpath(undef) -> undef
97 $result = $module->canonpath(undef);
98 is $result, undef, "$platform->canonpath(undef) -> undef";
100 # abs2rel('A:/foo/bar', 'A:/foo') -> 'bar'
101 $file = $module->catpath($v, $module->catdir($module->rootdir, 'foo', 'bar'), 'file');
102 $base = $module->catpath($v, $module->catdir($module->rootdir, 'foo'), '');
103 $result = $module->catfile('bar', 'file');
105 if ($vms_unix_mode and $platform eq 'VMS') {
107 # If VMS is in UNIX mode, so is the result, but having the volume
108 # parameter present forces the abs2rel into VMS mode.
109 $result = VMS::Filespec::vmsify($result);
112 # If we have a real root, then we are dealing with absolute directories
113 $result =~ s/\[\./\[/ if $vms_real_root;
116 is $module->abs2rel($file, $base), $result, "$platform->abs2rel($file, $base)";
119 # abs2rel('A:/foo/bar', 'B:/foo') -> 'A:/foo/bar'
120 $base = $module->catpath($other_v, $module->catdir($module->rootdir, 'foo'), '');
121 $result = volumes_differ($module, $file, $base) ? $file : $module->catfile('bar', 'file');
122 is $module->abs2rel($file, $base), $result, "$platform->abs2rel($file, $base)";
125 # abs2rel('A:/foo/bar', '/foo') -> 'A:/foo/bar'
126 $base = $module->catpath('', $module->catdir($module->rootdir, 'foo'), '');
127 $result = volumes_differ($module, $file, $base) ? $file : $module->catfile('bar', 'file');
128 is $module->abs2rel($file, $base), $result, "$platform->abs2rel($file, $base)";
131 # abs2rel('/foo/bar/file', 'A:/foo') -> '/foo/bar'
132 $file = $module->catpath('', $module->catdir($module->rootdir, 'foo', 'bar'), 'file');
133 $base = $module->catpath($v, $module->catdir($module->rootdir, 'foo'), '');
134 $result = volumes_differ($module, $file, $base) ? $module->rel2abs($file) : $module->catfile('bar', 'file');
136 if ($vms_unix_mode and $platform eq 'VMS') {
138 # If VMS is in UNIX mode, so is the result, but having the volume
139 # parameter present forces the abs2rel into VMS mode.
140 $result = VMS::Filespec::vmsify($result);
143 is $module->abs2rel($file, $base), $result, "$platform->abs2rel($file, $base)";
146 # abs2rel('/foo/bar', 'B:/foo') -> '/foo/bar'
147 $base = $module->catpath($other_v, $module->catdir($module->rootdir, 'foo'), '');
148 $result = volumes_differ($module, $file, $base) ? $module->rel2abs($file) : $module->catfile('bar', 'file');
150 if ($vms_unix_mode and $platform eq 'VMS') {
152 # If VMS is in UNIX mode, so is the result, but having the volume
153 # parameter present forces the abs2rel into VMS mode.
154 $result = VMS::Filespec::vmsify($result);
157 is $module->abs2rel($file, $base), $result, "$platform->abs2rel($file, $base)";
160 # abs2rel('/foo/bar', '/foo') -> 'bar'
161 $base = $module->catpath('', $module->catdir($module->rootdir, 'foo'), '');
162 $result = $module->catfile('bar', 'file');
164 is $module->abs2rel($file, $base), $result, "$platform->abs2rel($file, $base)";
169 my ($module, $one, $two) = @_;
170 my ($one_v) = $module->splitpath( $module->rel2abs($one) );
171 my ($two_v) = $module->splitpath( $module->rel2abs($two) );
172 return $one_v ne $two_v;