PERL
23
abs2rel bug
Guest on 18th May 2022 01:20:15 AM
#!/usr/bin/perl -lw
use strict;
=for comment
Given
directory /dir/base
file /dir/dest/subdir/file
cwd /dir/dest
then
abs2rel 'subdir/file', '../base'
should yield
../dest/subdir/file
but it yields
../../subdir/file
instead.
=cut
use sigtrap
qw(die normal
-signals
);
use Cwd;
use File::Basename;
use File::Path;
use File::Spec::Functions '/^/';
my $top = catdir tmpdir, "abs2rel-bug-$$";
mkpath $top;
my $dest_top = catdir $top, 'dest';
mkpath $dest_top;
my $path = catfile 'subdir', 'file';
mkpath dirname $path;
my $base = '../base';
mkpath $base;
my $result = abs2rel $path, $base;
sub show {
}
show 'perl' => $];
show 'file::spec' => $File::Spec::VERSION;
show 'cwd' => cwd;
show 'base' => $base;
show 'base exists' => -d $base ? 'yes' : 'no, my bug';
show 'dest path' => $path;
show 'abs2rel result' => $result;
show 'result exists' => -f $result ? 'yes' : 'no, File::Spec bug';
END {
}