CC: | steve.purkis [...] db.com |
Subject: | [patch] symlink target is as expected tests |
Test::File seems a sensible place for these to go. Might want to rename
them to 'symlink_target_is' and 'symlink_target_abs_is' in keeping with
the module...
(ok, so this isn't *quite* a patch, but close enough, and I'm out of
time unfortunately).
sub link_ok {
my ($from, $to, $name) = @_;
my $link = readlink( $from );
my $link_err = defined( $link ) ? '' : $!; # $! doesn't always get reset
if (defined( $link ) && defined( $to ) && $link eq $to) {
$Test->ok( 1, $name );
} else {
$Test->ok( 0, $name );
$link ||= 'undefined';
$Test->diag(" link: $from");
$Test->diag(" got: $link");
$Test->diag(" expected: $to");
$Test->diag(" readlink() error: $link_err") if ($link_err);
}
}
sub link_abs_ok {
my ($from, $from_base, $to, $to_base, $name) = @_;
my $link = readlink( $from );
my $link_err = defined( $link ) ? '' : $!; # $! doesn't always get reset
my $link_abs = abs_path( rel2abs($link, $from_base) );
my $to_abs = abs_path( rel2abs($to, $to_base) );
if (defined( $link_abs ) && defined( $to_abs ) && $link_abs eq $to_abs) {
$Test->ok( 1, $name );
} else {
$Test->ok( 0, $name );
$link ||= 'undefined';
$link_abs ||= 'undefined';
$to_abs ||= 'undefined';
$Test->diag(" link: $from");
$Test->diag(" got: $link");
$Test->diag(" (abs): $link_abs");
$Test->diag(" expected: $to");
$Test->diag(" (abs): $to_abs");
$Test->diag(" readlink() error: $link_err") if ($link_err);
}
}