From: Vincent Pit Date: Sat, 5 Feb 2011 18:42:04 +0000 (+0100) Subject: In Gentoo, 1.0 is greater than 1 X-Git-Tag: v0.12~14 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git;a=commitdiff_plain;h=7bee20385150f2ebb608178ecdce3851cdc4f54f In Gentoo, 1.0 is greater than 1 See also http://dev.gentoo.org/~ulm/pms/4/pms.html#x1-28008r2 for a complete Gentoo version comparison algorithm. Thanks Torsten Veller for bringing this to my attention. --- diff --git a/lib/CPANPLUS/Dist/Gentoo/Version.pm b/lib/CPANPLUS/Dist/Gentoo/Version.pm index 8d70ee6..e1f7674 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Version.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Version.pm @@ -126,12 +126,15 @@ sub _spaceship { my @a = @{ $v1->version }; my @b = @{ $v2->version }; - while (@a or @b) { - my $x = shift(@a) || 0; - my $y = shift(@b) || 0; + while (@a and @b) { + my $x = shift @a; + my $y = shift @b; my $c = $x <=> $y; return $c if $c; } + + return 1 if @a; + return -1 if @b; } { diff --git a/t/20-version.t b/t/20-version.t index 51bbf05..14ea329 100644 --- a/t/20-version.t +++ b/t/20-version.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 3 + (2 + 2 * 3) * (50 + 4 * 7); +use Test::More tests => 3 + (2 + 2 * 3) * (52 + 4 * 7); use CPANPLUS::Dist::Gentoo::Version; @@ -24,18 +24,20 @@ my @tests = ( [ 0, 1 => -1 ], [ 1, 1 => 0 ], - [ '1.0', 1 => 0 ], + [ '1.0', 1 => 1 ], # Yes, 1.0 > 1. Deal with it + [ '1.0', '1.0' => 0 ], [ '1.1', 1 => 1 ], [ '1.1', '1.0' => 1 ], - [ 1, '1.0' => 0 ], - [ 1, '1.1' => -1 ], [ '1.0', '1.1' => -1 ], + [ '1.0.0', 1 => 1 ], # Ditto + [ '1.0.0', '1.0' => 1 ], # Tritto + [ '1.0.0', '1.0.0' => 0 ], [ '1.0.1', '1.1' => -1 ], [ '1.0.1', '1.0.0' => 1 ], [ '1a', 1 => 1 ], [ '1.0a', 1 => 1 ], - [ '1.0', '1a' => -1 ], + [ '1.0', '1a' => 1 ], # Same [ '1a', '1b' => -1 ], [ '1.1a', '1.0b' => 1 ],