pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/pkgtools/lintpkgsrc lintpkgsrc: fix parsing of version...
details: https://anonhg.NetBSD.org/pkgsrc/rev/6c38d90a088e
branches: trunk
changeset: 382728:6c38d90a088e
user: rillig <rillig%pkgsrc.org@localhost>
date: Wed Aug 03 22:03:43 2022 +0000
description:
lintpkgsrc: fix parsing of version numbers that include letters
diffstat:
pkgtools/lintpkgsrc/Makefile | 3 +-
pkgtools/lintpkgsrc/files/lintpkgsrc.pl | 13 +++-
pkgtools/lintpkgsrc/files/t/pkgversion.t | 81 +++++++++++++++++++++++++++++++-
3 files changed, 90 insertions(+), 7 deletions(-)
diffs (160 lines):
diff -r 06fb74c0c602 -r 6c38d90a088e pkgtools/lintpkgsrc/Makefile
--- a/pkgtools/lintpkgsrc/Makefile Wed Aug 03 21:54:21 2022 +0000
+++ b/pkgtools/lintpkgsrc/Makefile Wed Aug 03 22:03:43 2022 +0000
@@ -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 @@
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
diff -r 06fb74c0c602 -r 6c38d90a088e pkgtools/lintpkgsrc/files/lintpkgsrc.pl
--- a/pkgtools/lintpkgsrc/files/lintpkgsrc.pl Wed Aug 03 21:54:21 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/lintpkgsrc.pl Wed Aug 03 22:03:43 2022 +0000
@@ -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 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 @@
}
}
}
- push(@temp, $nb);
@temp;
}
@@ -332,10 +331,14 @@
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;
diff -r 06fb74c0c602 -r 6c38d90a088e pkgtools/lintpkgsrc/files/t/pkgversion.t
--- a/pkgtools/lintpkgsrc/files/t/pkgversion.t Wed Aug 03 21:54:21 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/t/pkgversion.t Wed Aug 03 22:03:43 2022 +0000
@@ -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('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