Permalink
Browse files

Better handling of 'start_dir' in constructor and associated tests.

  • Loading branch information...
1 parent 008f2ee commit 74bbc8b2cc1a39e1b40136d675e77288efaacdf8 @jkeenan committed Feb 19, 2010
Showing with 53 additions and 11 deletions.
  1. +1 −0 Makefile.PL
  2. +3 −0 lib/CPAN/Mini/Visit/Simple.pm
  3. +49 −11 t/001_new.t
View
@@ -11,6 +11,7 @@ WriteMakefile(
PREREQ_PM => {
'CPAN::Mini' => 0,
'File::Find' => 0,
+ 'File::Path' => 2.06,
'File::Temp' => 0.14,
'Path::Class' => 0,
'Scalar::Util' => 0,
@@ -45,6 +45,9 @@ sub new {
if ( defined $args->{start_dir} ) {
croak "Directory $args->{start_dir} not found"
unless (-d $args->{start_dir} );
+ croak "Directory $args->{start_dir} must be subdirectory of $data{id_dir}"
+ unless ( $args->{start_dir} =~ m/$data{id_dir}/ );
+ $data{start_dir} = $args->{start_dir};;
}
else {
$data{start_dir} = $data{minicpan};
View
@@ -3,18 +3,19 @@
# t/001_new.t - check module loading and create testing directory
use Carp;
+use File::Path qw( make_path );
use File::Temp qw( tempdir );
use Path::Class qw( dir );
use Test::More qw(no_plan); # tests => 3;
BEGIN { use_ok( 'CPAN::Mini::Visit::Simple' ); }
-my $self;
+my ( $self, $phony_minicpan, $tdir, $id_dir );
$self = CPAN::Mini::Visit::Simple->new({});
isa_ok ($self, 'CPAN::Mini::Visit::Simple');
-my $phony_minicpan = '/foo/bar';
+$phony_minicpan = '/foo/bar';
eval {
$self = CPAN::Mini::Visit::Simple->new({
minicpan => $phony_minicpan,
@@ -23,15 +24,17 @@ eval {
like($@, qr/Directory $phony_minicpan not found/,
"Got expected error message for non-existent minicpan directory" );
-my $tdir = tempdir();
-my $id_dir = dir($tdir, qw/authors id/);
-eval {
- $self = CPAN::Mini::Visit::Simple->new({
- minicpan => $tdir,
- });
-};
-like($@, qr/Absence of $id_dir implies no valid minicpan/,
- "Got expected error message for malformed minicpan repository" );
+{
+ $tdir = tempdir();
+ $id_dir = dir($tdir, qw/authors id/);
+ eval {
+ $self = CPAN::Mini::Visit::Simple->new({
+ minicpan => $tdir,
+ });
+ };
+ like($@, qr/Absence of $id_dir implies no valid minicpan/,
+ "Got expected error message for malformed minicpan repository" );
+}
eval {
$self = CPAN::Mini::Visit::Simple->new({
@@ -57,3 +60,38 @@ eval {
like($@, qr/Directory $phony_minicpan not found/,
"Got expected error message for bad 'start_dir' value" );
+{
+ $tdir = tempdir();
+ ok( -d $tdir, "tempdir directory created for testing" );
+ $id_dir = dir($tdir, qw/authors id/);
+ make_path($id_dir, { mode => 0711 });
+ ok( -d $id_dir, "'authors/id' directory created for testing" );
+ my $phony_start_dir = dir($tdir, qw/foo bar/);
+ make_path($phony_start_dir, { mode => 0711 });
+ ok( -d $phony_start_dir, "'start_dir' directory created for testing" );
+ eval {
+ $self = CPAN::Mini::Visit::Simple->new({
+ minicpan => $tdir,
+ start_dir => $phony_start_dir,
+ });
+ };
+ like($@, qr/Directory $phony_start_dir must be subdirectory of $id_dir/,
+ "Got expected error message for 'start_dir' that is not subdir of authors/id/" );
+}
+
+{
+ $tdir = tempdir();
+ ok( -d $tdir, "tempdir directory created for testing" );
+ $id_dir = dir($tdir, qw/authors id/);
+ make_path($id_dir, { mode => 0711 });
+ ok( -d $id_dir, "'authors/id' directory created for testing" );
+ my $start_dir = dir($id_dir, qw/foo bar/);
+ make_path($start_dir, { mode => 0711 });
+ ok( -d $start_dir, "'start_dir' directory created for testing" );
+ $self = CPAN::Mini::Visit::Simple->new({
+ minicpan => $tdir,
+ start_dir => $start_dir,
+ });
+ isa_ok ($self, 'CPAN::Mini::Visit::Simple');
+}
+

0 comments on commit 74bbc8b

Please sign in to comment.