1N/A#!/usr/bin/perl -w
1N/A
1N/Ause strict;
1N/Ause Test::More;
1N/Ause File::Spec;
1N/Alocal $|=1;
1N/A
1N/Amy @platforms = qw(Cygwin Epoc Mac OS2 Unix VMS Win32);
1N/Amy $tests_per_platform = 7;
1N/A
1N/Aplan tests => 1 + @platforms * $tests_per_platform;
1N/A
1N/Amy %volumes = (
1N/A Mac => 'Macintosh HD',
1N/A OS2 => 'A:',
1N/A Win32 => 'A:',
1N/A VMS => 'v',
1N/A );
1N/Amy %other_vols = (
1N/A Mac => 'Mounted Volume',
1N/A OS2 => 'B:',
1N/A Win32 => 'B:',
1N/A VMS => 'w',
1N/A );
1N/A
1N/Aok 1, "Loaded";
1N/A
1N/Aforeach my $platform (@platforms) {
1N/A my $module = "File::Spec::$platform";
1N/A
1N/A SKIP:
1N/A {
1N/A eval "require $module; 1";
1N/A
1N/A skip "Can't load $module", $tests_per_platform
1N/A if $@;
1N/A
1N/A my $v = $volumes{$platform} || '';
1N/A my $other_v = $other_vols{$platform} || '';
1N/A
1N/A # Fake out the rootdir on MacOS
1N/A no strict 'refs';
1N/A my $save_w = $^W;
1N/A $^W = 0;
1N/A local *{"File::Spec::Mac::rootdir"} = sub { "Macintosh HD:" };
1N/A $^W = $save_w;
1N/A use strict 'refs';
1N/A
1N/A my ($file, $base, $result);
1N/A
1N/A $base = $module->catpath($v, $module->catdir('', 'foo'), '');
1N/A $base = $module->catdir($module->rootdir, 'foo');
1N/A
1N/A is $module->file_name_is_absolute($base), 1, "$base is absolute on $platform";
1N/A
1N/A
1N/A # abs2rel('A:/foo/bar', 'A:/foo') -> 'bar'
1N/A $file = $module->catpath($v, $module->catdir($module->rootdir, 'foo', 'bar'), 'file');
1N/A $base = $module->catpath($v, $module->catdir($module->rootdir, 'foo'), '');
1N/A $result = $module->catfile('bar', 'file');
1N/A is $module->abs2rel($file, $base), $result, "$platform->abs2rel($file, $base)";
1N/A
1N/A # abs2rel('A:/foo/bar', 'B:/foo') -> 'A:/foo/bar'
1N/A $base = $module->catpath($other_v, $module->catdir($module->rootdir, 'foo'), '');
1N/A $result = volumes_differ($module, $file, $base) ? $file : $module->catfile('bar', 'file');
1N/A is $module->abs2rel($file, $base), $result, "$platform->abs2rel($file, $base)";
1N/A
1N/A # abs2rel('A:/foo/bar', '/foo') -> 'A:/foo/bar'
1N/A $base = $module->catpath('', $module->catdir($module->rootdir, 'foo'), '');
1N/A $result = volumes_differ($module, $file, $base) ? $file : $module->catfile('bar', 'file');
1N/A is $module->abs2rel($file, $base), $result, "$platform->abs2rel($file, $base)";
1N/A
1N/A # abs2rel('/foo/bar', 'A:/foo') -> '/foo/bar'
1N/A $file = $module->catpath('', $module->catdir($module->rootdir, 'foo', 'bar'), 'file');
1N/A $base = $module->catpath($v, $module->catdir($module->rootdir, 'foo'), '');
1N/A $result = volumes_differ($module, $file, $base) ? $file : $module->catfile('bar', 'file');
1N/A is $module->abs2rel($file, $base), $result, "$platform->abs2rel($file, $base)";
1N/A
1N/A # abs2rel('/foo/bar', 'B:/foo') -> '/foo/bar'
1N/A $base = $module->catpath($other_v, $module->catdir($module->rootdir, 'foo'), '');
1N/A $result = volumes_differ($module, $file, $base) ? $file : $module->catfile('bar', 'file');
1N/A is $module->abs2rel($file, $base), $result, "$platform->abs2rel($file, $base)";
1N/A
1N/A # abs2rel('/foo/bar', '/foo') -> 'bar'
1N/A $base = $module->catpath('', $module->catdir($module->rootdir, 'foo'), '');
1N/A $result = $module->catfile('bar', 'file');
1N/A is $module->abs2rel($file, $base), $result, "$platform->abs2rel($file, $base)";
1N/A }
1N/A}
1N/A
1N/Asub volumes_differ {
1N/A my ($module, $one, $two) = @_;
1N/A my ($one_v) = $module->splitpath( $module->rel2abs($one) );
1N/A my ($two_v) = $module->splitpath( $module->rel2abs($two) );
1N/A return $one_v ne $two_v;
1N/A}