Skip to content

Commit

Permalink
Test previously unexercised branches.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeenan committed Feb 22, 2010
1 parent dee2930 commit 11512e3
Showing 1 changed file with 77 additions and 46 deletions.
123 changes: 77 additions & 46 deletions t/006_refresh_list.t
Expand Up @@ -8,13 +8,82 @@ use Carp;
use File::Path qw( make_path ); use File::Path qw( make_path );
use File::Spec; use File::Spec;
use File::Temp qw( tempfile tempdir ); use File::Temp qw( tempfile tempdir );
use Test::More qw(no_plan); # tests => 26; use Test::More tests => 30;
#use Data::Dumper;$Data::Dumper::Indent=1;


my ( $self, @list, $tdir, $id_dir, $author_dir ); {
my ( @source_list, $old_primary_list_ref, $refreshed_list_ref ); my ($tdir, $author_dir) = create_minicpan_for_testing();

# Create object and get primary list
my $self = CPAN::Mini::Visit::Simple->new({
minicpan => $tdir,
});
isa_ok ($self, 'CPAN::Mini::Visit::Simple');

ok( $self->identify_distros(),
"identify_distros() returned true value" );

my $old_primary_list_ref = $self->get_list_ref();

create_one_new_distro_version($author_dir);

# We have now changed what is in our minicpan repository.
# We need to refresh what is in $old_primary_list_ref.
# (Since we did not use 'start_dir' or 'pattern' to create the old primary
# list, we will not provide those arguments to refresh_list().

my $refreshed_list_ref = $self->refresh_list( {
derived_list => $old_primary_list_ref,
} );

my $expected_list_ref = {
map { my $path = qq|$author_dir/$_|; $path => 1 } qw(
Alpha-Beta-0.01.tar.gz
Gamma-Delta-0.02.tar.gz
Epsilon-Zeta-0.04.tar.gz
)
};
is_deeply(
{ map { $_ => 1 } @{$refreshed_list_ref} },
$expected_list_ref,
"Got expected refreshed list"
);
}

{
my ($tdir, $author_dir) = create_minicpan_for_testing();
my $self = CPAN::Mini::Visit::Simple->new({ minicpan => $tdir });
isa_ok ($self, 'CPAN::Mini::Visit::Simple');
ok( $self->identify_distros(),
"identify_distros() returned true value" );
my $old_primary_list_ref = $self->get_list_ref();
create_one_new_distro_version($author_dir);
my $refreshed_list_ref;
eval {
$refreshed_list_ref = $self->refresh_list( { } );
};
like($@, qr/Need 'derived_list' whose value is list of distributions needing refreshment/,
"Got expected error message due to absence of 'derived_list' argument");
}


{ {
my ($tdir, $author_dir) = create_minicpan_for_testing();
my $self = CPAN::Mini::Visit::Simple->new({ minicpan => $tdir });
isa_ok ($self, 'CPAN::Mini::Visit::Simple');
ok( $self->identify_distros(),
"identify_distros() returned true value" );
my $old_primary_list_ref = $self->get_list_ref();
create_one_new_distro_version($author_dir);
my $refreshed_list_ref;
eval {
$refreshed_list_ref = $self->refresh_list( { derived_list => {} } );
};
like($@, qr/Value of 'derived_list' must be array reference/,
"Got expected error message due to bad 'derived_list' argument");
}

sub create_minicpan_for_testing {
my ( $tdir, $id_dir, $author_dir );
my ( @source_list );
# Prepare the test by creating a minicpan in a temporary directory. # Prepare the test by creating a minicpan in a temporary directory.
$tdir = tempdir(); $tdir = tempdir();
$id_dir = File::Spec->catdir($tdir, qw/authors id/); $id_dir = File::Spec->catdir($tdir, qw/authors id/);
Expand All @@ -37,18 +106,11 @@ my ( @source_list, $old_primary_list_ref, $refreshed_list_ref );
close $FH or croak "Unable to close handle to $distro after writing"; close $FH or croak "Unable to close handle to $distro after writing";
ok( ( -f $fulldistro ), "$fulldistro created" ); ok( ( -f $fulldistro ), "$fulldistro created" );
} }
return ($tdir, $author_dir);
}


# Create object and get primary list sub create_one_new_distro_version {
$self = CPAN::Mini::Visit::Simple->new({ my ($author_dir) = @_;
minicpan => $tdir,
});
isa_ok ($self, 'CPAN::Mini::Visit::Simple');

ok( $self->identify_distros(),
"identify_distros() returned true value" );

$old_primary_list_ref = $self->get_list_ref();

# Bump up the version number of one distro in the minicpan # Bump up the version number of one distro in the minicpan
my $remove = q{Epsilon-Zeta-0.03.tar.gz}; my $remove = q{Epsilon-Zeta-0.03.tar.gz};
my $removed_file = File::Spec->catfile($author_dir, $remove); my $removed_file = File::Spec->catfile($author_dir, $remove);
Expand All @@ -61,35 +123,4 @@ my ( @source_list, $old_primary_list_ref, $refreshed_list_ref );
say $FH q{}; say $FH q{};
close $FH or croak "Unable to close handle to $update after writing"; close $FH or croak "Unable to close handle to $update after writing";
ok( ( -f $updated_file ), "$updated_file created" ); ok( ( -f $updated_file ), "$updated_file created" );

# We have now changed what is in our minicpan repository.
# We need to refresh what is in $old_primary_list_ref.
# (Since we did not use 'start_dir' or 'pattern' to create the old primary
# list, we will not provide those arguments to refresh_list().

$refreshed_list_ref = $self->refresh_list( {
derived_list => $old_primary_list_ref,
} );

my $expected_list_ref = {
map { my $path = qq|$author_dir/$_|; $path => 1 } qw(
Alpha-Beta-0.01.tar.gz
Gamma-Delta-0.02.tar.gz
Epsilon-Zeta-0.04.tar.gz
)
};
is_deeply(
{ map { $_ => 1 } @{$refreshed_list_ref} },
$expected_list_ref,
"Got expected refreshed list"
);

# TODO: {
# local $TODO = "Code not written";
#
# eval { $self->identify_distros_from_derived_list( { list => $refreshed_list_ref } ) };
# is($@, q{}, "No error code found");
# ok( $self->identify_distros_from_derived_list( { list => $refreshed_list_ref } ),
# "identify_distros_from_derived_list() returned true value" );
# }
} }

0 comments on commit 11512e3

Please sign in to comment.