Skip to content

Commit

Permalink
Merge pull request #1 from djerius/cwd_abs_below_root
Browse files Browse the repository at this point in the history
fix cwd to absolute path when current directory is not at root, make perl 5.26 compliant
  • Loading branch information
tsucchi authored May 8, 2017
2 parents 7daf895 + 8282122 commit 74ea125
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 7 deletions.
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use lib '.';
use inc::Module::Install;

name 'Test-Mock-Net-FTP';
Expand Down
5 changes: 5 additions & 0 deletions lib/Test/Mock/Net/FTP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ sub mock_default_cwd {
$dirs = "";
}

# if an absolute path, start at root
elsif ( $dirs =~ m|^/| ) {
$self->{mock_cwd} = rootdir();
}

my $backup_cwd = $self->_mock_cwd;
for my $dir ( splitdir($dirs) ) {
$self->_mock_cwd_each($dir);
Expand Down
37 changes: 30 additions & 7 deletions t/003_cwd.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/perl -w
use Test::More;
use Test::Mock::Net::FTP;
use lib '.';
use t::Util;
use strict;
use warnings;
Expand Down Expand Up @@ -100,18 +101,40 @@ subtest 'chdir to up another dir', sub {
done_testing();
};

subtest 'using absolute path', sub {
my $ftp = prepare_ftp();
subtest 'absolute path', sub {

ok( $ftp->cwd('/ftproot/dir1/dir2') );
is( $ftp->pwd, '/ftproot/dir1/dir2' );
is( abs2rel($ftp->mock_pwd), 'tmp/ftpserver/dir1/dir2' );
subtest 'starting at root' => sub {
my $ftp = prepare_ftp();

ok( $ftp->cwd('/ftproot/dir1/dir2') );
is( $ftp->pwd, '/ftproot/dir1/dir2' );
is( abs2rel($ftp->mock_pwd), 'tmp/ftpserver/dir1/dir2' );

$ftp->quit();
done_testing();
};


subtest 'starting below root', sub {

my $ftp = prepare_ftp();

ok( $ftp->cwd('dir1/dir2') );
is( $ftp->pwd, '/ftproot/dir1/dir2' );

ok( $ftp->cwd('/ftproot/dir1/dir2') );
is( $ftp->pwd, '/ftproot/dir1/dir2' );

is( abs2rel($ftp->mock_pwd), 'tmp/ftpserver/dir1/dir2' );

$ftp->quit();
done_testing();
};

$ftp->quit();
done_testing();
};



subtest 'invalid path', sub {
my $ftp = prepare_ftp();

Expand Down
1 change: 1 addition & 0 deletions t/004_put.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use strict;
use warnings;
use Test::More;
use File::Spec::Functions qw(catfile catdir rootdir);
use lib '.';
use t::Util;
use Test::Mock::Net::FTP;
use Cwd;
Expand Down
1 change: 1 addition & 0 deletions t/005_get.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use Test::More;

use File::Copy;
use File::Spec::Functions qw(catfile);
use lib '.';
use t::Util;
use Test::Mock::Net::FTP;
use Cwd;
Expand Down
1 change: 1 addition & 0 deletions t/006_intercept_put.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use strict;
use warnings;
use Test::More;
use File::Spec::Functions qw(catfile);
use lib '.';
use t::Util;
use Test::Mock::Net::FTP qw(intercept);

Expand Down
1 change: 1 addition & 0 deletions t/007_intercept_get.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use File::Path qw(remove_tree make_path);
use File::Copy;
use File::Spec::Functions qw(catfile catdir);
use Cwd qw(chdir getcwd);
use lib '.';
use t::Util;
use Test::Mock::Net::FTP qw(intercept);
use Net::FTP;
Expand Down
1 change: 1 addition & 0 deletions t/008_override.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use lib '.';
use t::Util;
use Test::More;

Expand Down
1 change: 1 addition & 0 deletions t/009_ls.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use File::Copy;
use File::Spec::Functions qw(catfile);

use Test::More;
use lib '.';
use t::Util;
use Test::Mock::Net::FTP;

Expand Down
1 change: 1 addition & 0 deletions t/010_dir.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use File::Path qw(remove_tree make_path);
use File::Copy;
use File::Spec::Functions qw(catfile catdir);
use Test::More;
use lib '.';
use t::Util;
use Test::Mock::Net::FTP;

Expand Down
1 change: 1 addition & 0 deletions t/011_misc_methods.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use strict;
use warnings;

use Test::More;
use lib '.';
use t::Util;
use Test::Mock::Net::FTP;
use File::Spec::Functions qw(catfile);
Expand Down
1 change: 1 addition & 0 deletions t/012_rename.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use strict;
use warnings;
use Test::More;
use File::Spec::Functions qw(catfile);
use lib '.';
use t::Util;
use Test::Mock::Net::FTP;

Expand Down
1 change: 1 addition & 0 deletions t/013_delete.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use strict;
use warnings;
use Test::More;
use File::Spec::Functions qw(catfile);
use lib '.';
use t::Util;
use Test::Mock::Net::FTP;

Expand Down
1 change: 1 addition & 0 deletions t/014_mkdir_and_rmdir.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use warnings;
use Test::More;
use File::Path qw(remove_tree);
use File::Spec::Functions qw(catdir);
use lib '.';
use t::Util;
use Test::Mock::Net::FTP;

Expand Down
1 change: 1 addition & 0 deletions t/015_append.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use strict;
use warnings;
use Test::More;
use File::Spec::Functions qw(catfile catdir rootdir);
use lib '.';
use t::Util;
use Test::Mock::Net::FTP;
use Cwd;
Expand Down
1 change: 1 addition & 0 deletions t/016_clear_message.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use lib '.';
use t::Util;
use Test::More;

Expand Down
1 change: 1 addition & 0 deletions t/017_command_history.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use lib '.';
use t::Util;
use Test::More;

Expand Down
1 change: 1 addition & 0 deletions t/018_default_implementation.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use lib '.';
use t::Util;
use Test::More;

Expand Down

0 comments on commit 74ea125

Please sign in to comment.