Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-File CPAN distribution.

Report information
The Basics
Id: 37677
Status: resolved
Priority: 0/
Queue: Test-File

People
Owner: Nobody in particular
Requestors: spurkis [...] cpan.org
Cc: steve.purkis [...] db.com
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.25
Fixed in: (no value)



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); } }
On Mon Jul 14 11:45:32 2008, SPURKIS wrote: Show quoted text
> 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...
I can add a subroutine for symlink_target is, but I'm not sure what your other subroutine is doing. Can you tell me more about what you are trying to do? Also, if you want to add more subroutines, look at the ones already in the module and follow their example. That makes less work for me :)
On Mon Jul 14 19:12:15 2008, BDFOY wrote: Show quoted text
> On Mon Jul 14 11:45:32 2008, SPURKIS wrote:
> > 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...
> > I can add a subroutine for symlink_target is, but I'm not sure what > your other subroutine is doing. Can you tell me more about what you > are trying to do?
Sure: the use case for the second one is to compare the absolute paths of 2 links' targets. This is handy if the links are relative, and you want to make sure they point to the same file when resolved. Only 1 link is passed in; it is assumed the user has already done a readlink on the 2nd, or come up with it some other way. Feels rather hack-ish in retrospect: if I was doing it again I'd split it into 2 funcs: 1. symlink_targets_match(link1, link2, msg) Just pass in 2 links and calculate the abs paths from them (it should also be possible to calc the 'base' dirs rather than having to pass them in too). 2. symlink_abs_target_is(link1, abs_path, msg) Resolve symlink abs path & compare to one given Also, note that I've missed off this from the cut-n-paste: use Cwd qw( abs_path ); use File::Spec::Functions qw( catdir catfile rel2abs rootdir ); Show quoted text
> Also, if you want to add more subroutines, look at the ones already > in the module and follow their example. That makes less work for me > :)
Point taken - normally I would, and I'd put together tests too and bundle it all in a nice patch that was easy to apply. But I'm really out of time on this one, and I figured something was better than nothing. Look at it as a feature request rather than a patch ;-)