Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test previously unexercised branches.

  • Loading branch information...
commit 11512e39e6ada88d126646e332e853191575c684 1 parent dee2930
@jkeenan authored
Showing with 77 additions and 46 deletions.
  1. +77 −46 t/006_refresh_list.t
View
123 t/006_refresh_list.t
@@ -8,13 +8,82 @@ use Carp;
use File::Path qw( make_path );
use File::Spec;
use File::Temp qw( tempfile tempdir );
-use Test::More qw(no_plan); # tests => 26;
-#use Data::Dumper;$Data::Dumper::Indent=1;
+use Test::More tests => 30;
-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.
$tdir = tempdir();
$id_dir = File::Spec->catdir($tdir, qw/authors id/);
@@ -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";
ok( ( -f $fulldistro ), "$fulldistro created" );
}
+ return ($tdir, $author_dir);
+}
- # Create object and get primary list
- $self = CPAN::Mini::Visit::Simple->new({
- 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();
-
+sub create_one_new_distro_version {
+ my ($author_dir) = @_;
# Bump up the version number of one distro in the minicpan
my $remove = q{Epsilon-Zeta-0.03.tar.gz};
my $removed_file = File::Spec->catfile($author_dir, $remove);
@@ -61,35 +123,4 @@ my ( @source_list, $old_primary_list_ref, $refreshed_list_ref );
say $FH q{};
close $FH or croak "Unable to close handle to $update after writing";
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" );
-# }
}
Please sign in to comment.
Something went wrong with that request. Please try again.