pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/pkgtools/lintpkgsrc



Module Name:    pkgsrc
Committed By:   rillig
Date:           Wed Aug  3 22:03:43 UTC 2022

Modified Files:
        pkgsrc/pkgtools/lintpkgsrc: Makefile
        pkgsrc/pkgtools/lintpkgsrc/files: lintpkgsrc.pl
        pkgsrc/pkgtools/lintpkgsrc/files/t: pkgversion.t

Log Message:
lintpkgsrc: fix parsing of version numbers that include letters


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 pkgsrc/pkgtools/lintpkgsrc/Makefile
cvs rdiff -u -r1.50 -r1.51 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
cvs rdiff -u -r1.7 -r1.8 pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/pkgtools/lintpkgsrc/Makefile
diff -u pkgsrc/pkgtools/lintpkgsrc/Makefile:1.44 pkgsrc/pkgtools/lintpkgsrc/Makefile:1.45
--- pkgsrc/pkgtools/lintpkgsrc/Makefile:1.44    Wed Aug  3 16:15:49 2022
+++ pkgsrc/pkgtools/lintpkgsrc/Makefile Wed Aug  3 22:03:43 2022
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.44 2022/08/03 16:15:49 rillig Exp $
+# $NetBSD: Makefile,v 1.45 2022/08/03 22:03:43 rillig Exp $
 
 PKGNAME=       lintpkgsrc-4.99
 CATEGORIES=    pkgtools
@@ -10,6 +10,7 @@ COMMENT=      Sanity checks on the complete p
 DEPENDS+=      digest>=20010101:../../pkgtools/digest
 TEST_DEPENDS+= p5-Capture-Tiny>=0:../../devel/p5-Capture-Tiny
 TEST_DEPENDS+= p5-File-Slurp>=0:../../devel/p5-File-Slurp
+TEST_DEPENDS+= p5-IO-Null>=0:../../devel/p5-IO-Null
 CONFLICTS+=    pkglint<4.82
 
 USE_TOOLS+=    perl:run

Index: pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
diff -u pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.50 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.51
--- pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.50 Wed Aug  3 20:50:43 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl      Wed Aug  3 22:03:43 2022
@@ -1,6 +1,6 @@
 #!@PERL5@
 
-# $NetBSD: lintpkgsrc.pl,v 1.50 2022/08/03 20:50:43 rillig Exp $
+# $NetBSD: lintpkgsrc.pl,v 1.51 2022/08/03 22:03:43 rillig Exp $
 
 # Written by David Brownlee <abs%netbsd.org@localhost>.
 #
@@ -300,10 +300,10 @@ sub canonicalize_pkgname($) {
 sub split_pkgversion($) {
        my ($pkgversion) = @_;
 
-       # See pkg_install/lib/dewey.c.
+       # See pkgtools/pkg_install/files/lib/dewey.c.
        my (@temp);
-       my $nb = ($pkgversion =~ s/^(.*)nb(\d+)$/$1/) ? +$2 : 0;
-       foreach my $elem (split(/(\D+)/, lc($pkgversion))) {
+       push(@temp, ($pkgversion =~ s/nb(\d+)//) ? +$1 : 0);
+       foreach my $elem (split(/(pl|pre|rc|beta|alpha|\D)/, lc($pkgversion))) {
                if ($elem =~ /\d/) {
                        push(@temp, +$elem);
                } elsif ($elem eq "pl" || $elem eq "." || $elem eq "_") {
@@ -323,7 +323,6 @@ sub split_pkgversion($) {
                        }
                }
        }
-       push(@temp, $nb);
        @temp;
 }
 
@@ -332,10 +331,14 @@ sub pkgversioncmp($$$) {
 
        my @a = split_pkgversion($va);
        my @b = split_pkgversion($vb);
+       my $nb_a = shift(@a);
+       my $nb_b = shift(@b);
+
        my $cmp = 0;
        while ($cmp == 0 && (@a || @b)) {
                $cmp = (shift @a || 0) <=> (shift @b || 0);
        }
+       $cmp ||= $nb_a <=> $nb_b;
 
        if ($op eq '<') {
                $cmp < 0;

Index: pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t
diff -u pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.7 pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.8
--- pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.7 Wed Aug  3 20:50:43 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t     Wed Aug  3 22:03:43 2022
@@ -1,7 +1,8 @@
-# $NetBSD: pkgversion.t,v 1.7 2022/08/03 20:50:43 rillig Exp $
+# $NetBSD: pkgversion.t,v 1.8 2022/08/03 22:03:43 rillig Exp $
 
 use strict;
 use warnings;
+use IO::Null;
 use Test;
 
 BEGIN { plan tests => 6, onfail => sub { die } }
@@ -17,3 +18,81 @@ ok(pkgversioncmp('3.4nb13', '>', '3.4nb5
 ok(pkgversioncmp('1.1ab', '>', '1.1aa'), 1);
 ok(pkgversioncmp('1.1ab', '<=', '1.1.1.2'), 1);
 ok(pkgversioncmp('1.1ab', '>=', '1.1.1.2'), 1);
+
+ok(pkgversioncmp('1nb1', '<', '1.0.0.0.0.0.0.1'), 1);
+ok(pkgversioncmp('1.0', '<', '1nb1'), 1);
+
+# See pkgtools/pkglint/files/pkgver/vercmp_test.go.
+my @split_version_tests = (
+    [ "5.0", [ [ 5, 0, 0 ], 0 ] ],
+    [ "5.0nb5", [ [ 5, 0, 0 ], 5 ] ],
+    [ "0.0.1-SNAP", [ [ 0, 0, 0, 0, 1, 0, 19, 0, 14, 0, 1, 0, 16 ], 0 ] ],
+    [ "1.0alpha3", [ [ 1, 0, 0, -3, 3 ], 0 ] ],
+    [ "1_0alpha3", [ [ 1, 0, 0, -3, 3 ], 0 ] ],
+    [ "2.5beta", [ [ 2, 0, 5, -2 ], 0 ] ],
+    [ "20151110", [ [ 20151110 ], 0 ] ],
+    [ "0", [ [ 0 ], 0 ] ],
+    [ "nb1", [ [], 1 ] ],
+    [ "1.0.1a", [ [ 1, 0, 0, 0, 1, 0, 1 ], 0 ] ],
+    [ "1.1.1dnb2", [ [ 1, 0, 1, 0, 1, 0, 4 ], 2 ] ],
+    [ "1.0.1z", [ [ 1, 0, 0, 0, 1, 0, 26 ], 0 ] ],
+    [ "0pre20160620", [ [ 0, -1, 20160620 ], 0 ] ],
+    [ "3.5.DEV1710", [ [ 3, 0, 5, 0, 0, 4, 0, 5, 0, 22, 1710 ], 0 ] ],
+);
+
+foreach my $test (@split_version_tests) {
+       my ($version, $expected) = @$test;
+       my @actual = split_pkgversion($version);
+       my @expected = ($expected->[1]);
+       push(@expected, @{$expected->[0]});
+       ok("$version: " . join(',', @actual), "$version: " . join(',', @expected));
+}
+
+# See pkgtools/pkglint/files/pkgver/vercmp_test.go.
+my $versions = [
+    [ "0pre20160620" ],
+    [ "0" ],
+    [ "nb1" ],
+    [ "0.0.1-SNAPSHOT" ],
+    [ "1.0alpha" ],
+    [ "1.0alpha3" ],
+    [ "1", "1.0", "1.0.0" ],
+    [ "1.0nb1" ],
+    [ "1.0nb2", "1_0nb2" ],
+    [ "1.0.aa" ],
+    [ "1.0.a1" ],
+    [ "1.0.k" ],
+    [ "1.0.1a" ],
+    [ "1.0.1z" ],
+    [ "1.0.11", "1.0k" ],
+    [ "2.0pre", "2.0rc" ],
+    [ "2.0", "2.0pl" ],
+    [ "2.0.1nb4" ],
+    [ "2.0.1nb17" ],
+    [ "2.5beta" ],
+    [ "5.0" ],
+    [ "5.0nb5" ],
+    [ "5.5", "5.005" ],
+    [ "2021.06.17", "2021.6.17" ],
+    [ "2021.12.01", "2021.12.1" ],
+    [ "20151110" ],
+];
+
+my $prev = $Test::TESTOUT;
+$Test::TESTOUT = IO::Null->new;
+for (my $i = 0; $i < $#{$versions}; $i++) {
+       for (my $j = 0; $j < $#{$versions}; $j++) {
+               foreach my $vi (@{$versions->[$i]}) {
+                       foreach my $vj (@{$versions->[$j]}) {
+                               my $actual = pkgversioncmp($vi, '<', $vj) ? '<'
+                                   : pkgversioncmp($vi, '<=', $vj) ? '=='
+                                   : '>';
+                               my $expected = $i < $j ? '<'
+                                   : $i == $j ? '=='
+                                   : '>';
+                               ok("$vi $actual $vj", "$vi $expected $vj");
+                       }
+               }
+       }
+}
+$Test::TESTOUT = $prev;



Home | Main Index | Thread Index | Old Index