Skip to content

Commit

Permalink
Update the tests and comments for search_blead_dir().
Browse files Browse the repository at this point in the history
  • Loading branch information
gugod committed Oct 24, 2019
1 parent 3af21e2 commit f35d809
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
18 changes: 8 additions & 10 deletions lib/App/perlbrew.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1341,25 +1341,23 @@ sub do_extract_tarball {
}
# Search for directories inside a extracted tarball downloaded as perl "blead"
# Use a Schwartzian Transform in case there are lots of dirs that
# look like "perl-$SHA1", which is what's inside blead.tar.gz,
# so we stat each one only once, ordering (descending )the directories per mtime
# Expects as parameters:
# - the path to the extracted "blead" tarball
# - an array reference, that will be used to cache all contents from the read directory
# Returns the most recent directory which name matches the expected one.
# This pattern has to what's inside the extracted tarball from: https://github.com/Perl/perl5/tarball/blead
# Parameters:
# - $build_dir: A directory for building perls. It is supposed to have "blead" subdir inside.
# Returs:
# - A path to the extracted "blead" tarball. This should be a subdir inside "${build_dir}/blead"
sub search_blead_dir {
my ($build_dir, $contents_ref) = @_;
my ($build_dir) = @_;
my $blead_dir = $build_dir->child("blead");
return unless -d $blead_dir;
local *DIRH;
opendir DIRH, $blead_dir or die "Couldn't open ${blead_dir}: $!";
@{$contents_ref} = grep { !/^\./ && -d $blead_dir->child($_) } readdir DIRH;
my @contents = grep { !/^\./ && -d $blead_dir->child($_) } readdir DIRH;
closedir DIRH or warn "Couldn't close ${blead_dir}: $!";
my @candidates = grep { m/^Perl-perl5-[0-9a-f]{4,40}$/ } @{$contents_ref};
my @candidates = grep { m/^Perl-perl5-[0-9a-f]{4,40}$/ } @contents;
@candidates = map { $_->[0] }
sort { $b->[1] <=> $a->[1] } # descending
Expand Down
20 changes: 8 additions & 12 deletions t/get_blead_perl.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use warnings;
use strict;
use Test::More tests => 6;
use Test::More tests => 2;
use App::perlbrew;
use Test::TempDir::Tiny 0.016;

Expand All @@ -9,19 +9,15 @@ mkdir("$dir/build");
mkdir("$dir/build/blead");
touch( "$dir/build/blead", 'OYFTV_51234' );
touch( "$dir/build/blead", 'Hwefwo8124' );
touch( "$dir/build/blead", 'perl-blead-hsf743r' );
my $blead = 'perl-blead-e7e8ce8';
touch( "$dir/build/blead", 'Perl-perl5-hsf743r' );
my $blead = 'Perl-perl5-e7e8ce8';
mkdir("$dir/build/blead/$blead");

my @content;
my $found_dir = App::perlbrew::search_blead_dir( App::Perlbrew::Path->new ("$dir/build"), \@content );
is( $found_dir, undef, 'no candidate directory is found' );
is( scalar(@content), 1, 'there are only directories on content cache' );
is( $content[0], 'blead', 'have the expected directory in the content cache' );
$found_dir = App::perlbrew::search_blead_dir( App::Perlbrew::Path->new ("$dir/build/blead"), \@content );
is( $found_dir, $blead, 'the expected directory is found' );
is( scalar(@content), 1, 'there are only directories on content cache' );
is( $content[0], $blead, 'have the expected directory in the content cache' );
my $found_dir = App::perlbrew::search_blead_dir( App::Perlbrew::Path->new ("$dir/build"));
is( $found_dir, "$dir/build/blead/$blead", 'Found the correct directory' );

$found_dir = App::perlbrew::search_blead_dir( App::Perlbrew::Path->new ("$dir/build/blead") );
is( $found_dir, undef, 'Nothing is found.' );

# creating files to make sure search_blead_dir only considers directories
sub touch {
Expand Down

0 comments on commit f35d809

Please sign in to comment.