Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 6 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Commits on Nov 26, 2013
@deeelwy Fixed sort block returning undef bug.
When I fixed the unequal number of digits bug in lookup_by_versionstring(), I
completely changed the algorithm. This algorthm assumed that perl was okay with
sort blocks returning undef, my Perl setup tested fine, but according to CPAN
Testers the warning was expaned in a later version of Perl, and the warning is
even a fatal error on some Perl setups the CPAN Testers tested fetchware on.

So, this patches fixes that by discarding any files from @versionstrings that
have an empty versionstring, so sort no longer sees any undefs to warn or die
over.
4f76698
@deeelwy Added additional tests for lookup_by_versionstring().
They test for unequal number of version numbers:
6.3.9
6.3
6
5.3.9
5.3
5.0
134b86b
@deeelwy Added SKIP block to skip new's tests if there is no terminal accordin…
…g to -t.

This fixes some CPAN Testers FAILs due to STDIN not being a proper terminal,
which borks all of the Term::ReadLine->new('fetchware test') calls.
adc2840
@deeelwy Fixed POD typo regarding verify_method. 4386ee2
@deeelwy Fixed weird t/bin-fetchware-upgrade.t CPAN Testers bug with verify_me…
…thod.

Added verify_method 'md5'; to make_test_dist()'s Fetchwarefile template only use
md5 for verification instead of trying gpg, then sha1, andthen finally trying
md5, which is what will actually work. I know it will work, so I should say so.
bae8b11
@deeelwy v1.007
    - Fixed a bunch of CPAN Testers FAILs. Including:
        - Weird t/bin-fetchware-upgrade.t test-dist fail bug.
        - Added SKIP block unless -t to t/bin-fetchware-new.t testing.
        - Fixed sort block returning undef bug, and added extra tests too.
5f60ce9
Showing with 81 additions and 20 deletions.
  1. +6 −0 Changes
  2. +1 −1 dist.ini
  3. +48 −18 lib/App/Fetchware.pm
  4. +3 −0 lib/Test/Fetchware.pm
  5. +15 −1 t/App-Fetchware-lookup.t
  6. +8 −0 t/bin-fetchware-new.t
View
6 Changes
@@ -2,6 +2,12 @@ Revison History for App::Fetchware
{{$NEXT}}
+1.007 2013-11-25 23:53:58 America/New_York
+ - Fixed a bunch of CPAN Testers FAILs. Including:
+ - Weird t/bin-fetchware-upgrade.t test-dist fail bug.
+ - Added SKIP block unless -t to t/bin-fetchware-new.t testing.
+ - Fixed sort block returning undef bug, and added extra tests too.
+
1.006 2013-11-25 02:59:52 America/New_York
- Fixed Test::Expect CPAN Testers FAILs by switching from use to requires.
View
2 dist.ini
@@ -4,7 +4,7 @@ license = Perl_5
copyright_holder = David Yingling
copyright_year = 2013
-version = 1.006
+version = 1.007
; Change bugtracker to github
[MetaResources]
View
66 lib/App/Fetchware.pm
@@ -1105,6 +1105,11 @@ input, $filename_listing) on C</\D+/>, which will return a list of version
numbers. Then, the cleverly splitted filename is pushed on to the input array,
and then the array is sorted based on this new value using a custom sort block.
+lookup_by_versionstring() also discards any entries from $filename_listing that
+do not have a version number in them, because without version numbers that entry
+can not be sorted properly. And if it is left in, it could confuse fetchware
+into figuring out the correct download path.
+
Also note, that both $filename_listing and lookup_by_versionstring()'s return
value, $sorted_filename_listing, B<must> both be arrayrefs of arrays. That is a
scallar pointing to an array of arrays.
@@ -1117,28 +1122,53 @@ sub lookup_by_versionstring {
# Implement versionstring algorithm.
my @versionstrings;
for (my $i = 0; $i <= $#{$file_listing}; $i++) {
- # Split each filename on *non digits*
- # And add that as an arrayref to @versionstrings;
- # And store the index $i, so that we can actually sort $file_listing
- # later on after sorting @versionstrings.
- push @versionstrings, [$i,
- # Use grep to strip leading empty strings (eg: '').
- (grep {$_ ne ''} split(/\D+/, $file_listing->[$i][0]))]
+ # Split the filename on "Not a numbers", so remove all "not
+ # numbers", but keep a list of things that actually are numbers.
+ my @iversionstring = split(/\D+/, $file_listing->[$i][0]);
+
+ # Use grep to strip leading empty strings (eg: '').
+ @iversionstring = grep {$_ ne ''} @iversionstring;
+
+ if (@iversionstring == 0) {
+ vmsg <<EOM;
+ # Let the usr know we're skipping this filename, but only if they
+ # really want to know (They turned on verbose output.).
+File [$file_listing->[$i][0]] has no version number in it. Ignoring.
+EOM
+ # And also skip adding this @iversionstring to @versionstrings,
+ # because this @iversionstring is empty, and how do I sort an empty
+ # array? Return undef--nope causes "value undef in sort fatal errors
+ # and warnings." Return 0--nope causes a file with no version number
+ # at beginning of listing to stay at listing, and cause fetchware to
+ # fail picking the right version. Return -1--nope, because that's
+ # hackish and lame. Instead, just not include them in the lookup
+ # listing, and if that means that the lookup listing is empty throw
+ # an exception.
+ next;
+ }
+ # Add $i's version string to @versionstrings.
+ push @versionstrings, [$i, @iversionstring];
# And the sort below sorts them into highest number first order.
}
+ die <<EOD if @versionstrings == 0;
+App-Fetchware: The lookup_url your provided [@{[config('lookup_url')]}] does not
+have any filenames with detectable version numbers in them. Fetchware's
+'versionstring' lookup algorithm depends on files having version numbers in them
+such as [httpd-2.2.22.tar.gz] notice the [2.2.22] version number. Fetchware
+failed to find any of those in the lookup_url you provided. Consider a different
+lookup_url or try switching to the default 'timestamp' lookup algorithm adding
+the "lookup_method" configuration option to your Fetchwarefile.
+EOD
+
+ # LIMITATION: The sort block below can not have any undef values in its
+ # input. If there are any, then perl will give a warning about a value being
+ # undef in a sort, if you are not lucky, then it will actually trigger a
+ # fatal error. There are CPAN Testers reports with this problem, so it really
+ # can happen. But you do not have to worry about this, because the for loop
+ # above that creates @versionstrings
@versionstrings = sort {
- # Return undef for filenames that don't have numbers in them, because
- # without those numbers I can't actually sort them. It's really awesome
- # and convienient that perl's sort does not explode or throw an
- # exception when your custom sort subroutine returns undef instead of
- # -1, 0, or 1, because without those numbers I can't actually sort them.
- # It's really awesome and convienient that perl's sort does not explode
- # or throw an exception when your custom sort subroutine returns undef
- # instead of -1, 0, or 1.
- return if $#{$a} < 2;
- return if $#{$b} < 2;
# Figure out whoose ($b or $a) is larger and set $last_index to it.
my $last_index;
if ($#{$b} > $#{$a}) {
@@ -3593,7 +3623,7 @@ cannot be verified. The availabel options are:
=item sha1 - Uses the SHA-1 hash function to verify the integrity of the download. This is much less secure than gpg.
-=item sha1 - Uses the MD5 hash function to verify the integrity of the download. This is much less secure than gpg.
+=item md5 - Uses the MD5 hash function to verify the integrity of the download. This is much less secure than gpg.
=back
View
3 lib/Test/Fetchware.pm
@@ -363,6 +363,9 @@ program '$file_name';
# Need to filter out the cruft.
filter '$file_name';
+# Just use MD5 to verify it.
+verify_method 'md5';
+
EOF
,
View
16 t/App-Fetchware-lookup.t
@@ -334,6 +334,12 @@ subtest 'test lookup_by_versionstring()' => sub {
['v7.0.42', '32151651145545'],
['v7.0.41', '25454546348484'],
['v7.6.12', '75434843484844'],
+ ['v6', '17777777777777'],
+ ['v6.2.9', '18888888888888'],
+ ['v6.3', '19999999999999'],
+ ['v5.0', '1777777777777'],
+ ['v5.2.9', '1888888888888'],
+ ['v5.3', '1999999999999'],
];
my $expected_more_digits_than_higher_one = [
@@ -344,7 +350,15 @@ subtest 'test lookup_by_versionstring()' => sub {
['v7.6.12', '75434843484844'],
['v7.0.53', '45454675374874'],
['v7.0.42', '32151651145545'],
- ['v7.0.41', '25454546348484']
+ ['v7.0.41', '25454546348484'],
+ # Test for unequal # of version numbers too.
+ ['v6.3', '19999999999999'],
+ ['v6.2.9', '18888888888888'],
+ ['v6', '17777777777777'],
+ # Test the same thing as above, but with a .0 on the end.
+ ['v5.3', '1999999999999'],
+ ['v5.2.9', '1888888888888'],
+ ['v5.0', '1777777777777'],
];
my $sorted_file_listing =
View
8 t/bin-fetchware-new.t
@@ -37,6 +37,12 @@ BEGIN {
}
+SKIP: {
+ # Must be 1 less than the number of tests in the Test::More use line above.
+ my $how_many = 16;
+ skip 'Not on a terminal', $how_many unless -t;
+
+
subtest 'test opening_message() success' => sub {
print_ok(sub {opening_message()},
<<EOM, 'test opening_message() success.');
@@ -724,6 +730,8 @@ note("$fetchwarefile");
##BROKEN## expect_quit();
##BROKEN##};
+} # #End of gigantic skip block.
+
# Remove this or comment it out, and specify the number of tests, because doing
# so is more robust than using this, but this is better than no_plan.
#done_testing()

No commit comments for this range

Something went wrong with that request. Please try again.