App-Fetchware
view release on metacpan or search on metacpan
lib/Test/Fetchware.pm view on Meta::CPAN
# Create a temp dir to create or test-dist-1.$opts{ver_num} directory in.
# Must be done before original_cwd() is used to set $opts{destination_directory},
# because original_cwd() is undef until create_tempdir() sets it.
my $temp_dir = create_tempdir();
mkdir($dist_name) or die <<EOD;
fetchware: Run-time error. Fetchware failed to create the directory
[$dist_name] in the current directory of [$temp_dir]. The OS error was
[$!].
EOD
my %test_dist_files = (
'./Fetchwarefile' => $opts{fetchwarefile},
$configure_path => $opts{configure},
catfile($dist_name, 'Makefile') => $opts{makefile},
);
for my $file_to_create (keys %test_dist_files) {
open(my $fh, '>', $file_to_create) or die <<EOD;
fetchware: Run-time error. Fetchware failed to open
[$file_to_create] for writing to create the Configure script that
test-dist needs to work properly. The OS error was [$!].
EOD
print $fh $test_dist_files{$file_to_create};
close $fh;
}
# chmod() ./configure, so it can be executed.
chmod(0755, $configure_path) or die <<EOC;
fetchware: run-time error. fetchware failed to chmod [$configure_path] to add
execute permissions, which ./configure needs. Os error [$!].
EOC
# Create a tar archive of all of the files needed for test-dist.
Archive::Tar->create_archive("$test_dist_filename", COMPRESS_GZIP,
keys %test_dist_files) or die <<EOD;
fetchware: Run-time error. Fetchware failed to create the test-dist archive for
testing [$test_dist_filename] The error was [@{[Archive::Tar->error()]}].
EOD
# Cd back to original_cwd() and delete $temp_dir.
cleanup_tempdir();
return rel2abs($test_dist_filename);
}
sub md5sum_file {
my $archive_to_md5 = shift;
open(my $package_fh, '<', $archive_to_md5)
or die <<EOD;
App-Fetchware: run-time error. Fetchware failed to open the file it downloaded
while trying to read it in order to check its MD5 sum. The file was
[$archive_to_md5]. OS error [$!]. See perldoc App::Fetchware.
EOD
my $digest = Digest::MD5->new();
# Digest requires the filehandle to have binmode set.
binmode $package_fh;
my $calculated_digest;
eval {
# Add the file for digesting.
$digest->addfile($package_fh);
# Actually digest it.
$calculated_digest = $digest->hexdigest();
};
if ($@) {
die <<EOD;
App-Fetchware: run-time error. Digest::MD5 croak()ed an error [$@].
See perldoc App::Fetchware.
EOD
}
close $package_fh or die <<EOD;
App-Fetchware: run-time error Fetchware failed to close the file
[$archive_to_md5] after opening it for reading. See perldoc App::Fetchware.
EOD
my $md5sum_file = rel2abs($archive_to_md5);
$md5sum_file = "$md5sum_file.md5";
open(my $md5_fh, '>', $md5sum_file) or die <<EOD;
fetchware: run-time error. Failed to open [$md5sum_file] while calculating a
md5sum. Os error [$!].
EOD
print $md5_fh "$calculated_digest @{[file($archive_to_md5)->basename()]}";
close $md5_fh or die <<EOD;
App-Fetchware: run-time error Fetchware failed to close the file
[$md5sum_file] after opening it for reading. See perldoc App::Fetchware.
EOD
return $md5sum_file;
}
sub expected_filename_listing {
my $expected_filename_listing = <<'EOC';
array_each(
array_each(any(
re(qr/Announcement2.\d.(html|txt)/),
re(qr/CHANGES_2\.\d(\.\d+)?/),
re(qr/CURRENT(-|_)IS(-|_)\d\.\d+?\.\d+/),
re(qr/
HEADER.html
|
KEYS
|
README.html
|
binaries
|
docs
|
flood
/x),
re(qr/httpd-2\.\d\.\d+?-win32-src\.zip(\.asc)?/),
( run in 0.613 second using v1.01-cache-2.11-cpan-39bf76dae61 )