pkgsrc-Changes archive

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

CVS commit: pkgsrc/pkgtools/lintpkgsrc/files



Module Name:    pkgsrc
Committed By:   rillig
Date:           Thu Aug  4 05:45:15 UTC 2022

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

Log Message:
lintpkgsrc: allow uppercase 'nb' in version numbers

Just for symmetry with the pkg_install implementation; in practice the
'nb' is always lowercase.

Merge most test cases into the versions table, leave a few as simple
examples.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
cvs rdiff -u -r1.8 -r1.9 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/files/lintpkgsrc.pl
diff -u pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.51 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.52
--- pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.51 Wed Aug  3 22:03:43 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl      Thu Aug  4 05:45:15 2022
@@ -1,6 +1,6 @@
 #!@PERL5@
 
-# $NetBSD: lintpkgsrc.pl,v 1.51 2022/08/03 22:03:43 rillig Exp $
+# $NetBSD: lintpkgsrc.pl,v 1.52 2022/08/04 05:45:15 rillig Exp $
 
 # Written by David Brownlee <abs%netbsd.org@localhost>.
 #
@@ -300,10 +300,12 @@ sub canonicalize_pkgname($) {
 sub split_pkgversion($) {
        my ($pkgversion) = @_;
 
+       $pkgversion = lc($pkgversion);
+
        # See pkgtools/pkg_install/files/lib/dewey.c.
        my (@temp);
        push(@temp, ($pkgversion =~ s/nb(\d+)//) ? +$1 : 0);
-       foreach my $elem (split(/(pl|pre|rc|beta|alpha|\D)/, lc($pkgversion))) {
+       foreach my $elem (split(/(pl|pre|rc|beta|alpha|\D)/, $pkgversion)) {
                if ($elem =~ /\d/) {
                        push(@temp, +$elem);
                } elsif ($elem eq "pl" || $elem eq "." || $elem eq "_") {
@@ -314,13 +316,9 @@ sub split_pkgversion($) {
                        push(@temp, -2);
                } elsif ($elem eq "alpha") {
                        push(@temp, -3);
-               } else {
-                       foreach my $ch (split(//, $elem)) {
-                               if ('a' le $ch && $ch le 'z') {
-                                       push(@temp, 0);
-                                       push(@temp, ord($ch) - ord('a') + 1);
-                               }
-                       }
+               } elsif ('a' le $elem && $elem le 'z') {
+                       push(@temp, 0);
+                       push(@temp, ord($elem) - ord('a') + 1);
                }
        }
        @temp;
@@ -329,10 +327,8 @@ sub split_pkgversion($) {
 sub pkgversioncmp($$$) {
        my ($va, $op, $vb) = @_;
 
-       my @a = split_pkgversion($va);
-       my @b = split_pkgversion($vb);
-       my $nb_a = shift(@a);
-       my $nb_b = shift(@b);
+       my ($nb_a, @a) = split_pkgversion($va);
+       my ($nb_b, @b) = split_pkgversion($vb);
 
        my $cmp = 0;
        while ($cmp == 0 && (@a || @b)) {

Index: pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t
diff -u pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.8 pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.9
--- pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.8 Wed Aug  3 22:03:43 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t     Thu Aug  4 05:45:15 2022
@@ -1,26 +1,16 @@
-# $NetBSD: pkgversion.t,v 1.8 2022/08/03 22:03:43 rillig Exp $
+# $NetBSD: pkgversion.t,v 1.9 2022/08/04 05:45:15 rillig Exp $
 
 use strict;
 use warnings;
 use IO::Null;
 use Test;
 
-BEGIN { plan tests => 6, onfail => sub { die } }
+BEGIN { plan tests => 1781, onfail => sub { die } }
 
 require('../lintpkgsrc.pl');
 
 ok(pkgversioncmp('3.4', '<', '3.4'), '');
 ok(pkgversioncmp('3.4', '<=', '3.4'), 1);
-ok(pkgversioncmp('3.4', '>=', '3.4.0.0.0'), 1);
-ok(pkgversioncmp('3.4nb13', '>=', '3.4'), 1);
-ok(pkgversioncmp('3.4nb13', '<', '3.4'), '');
-ok(pkgversioncmp('3.4nb13', '>', '3.4nb5'), 1);
-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 = (
@@ -42,27 +32,33 @@ my @split_version_tests = (
 
 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));
+       my $actual_str = "$version: " . join(',', @actual);
+       my $expected_str = "$version: " . join(',', @expected);
+       ok($actual_str, $expected_str);
 }
 
 # See pkgtools/pkglint/files/pkgver/vercmp_test.go.
-my $versions = [
+my @versions = (
     [ "0pre20160620" ],
     [ "0" ],
-    [ "nb1" ],
+    [ "0nb1", "0NB1", "0Nb1", "0nb00001" ],
     [ "0.0.1-SNAPSHOT" ],
     [ "1.0alpha" ],
     [ "1.0alpha3" ],
     [ "1", "1.0", "1.0.0" ],
-    [ "1.0nb1" ],
+    [ "1.0nb1", "1nb1" ],
     [ "1.0nb2", "1_0nb2" ],
+    [ "1.0.0.0.0.0.0.1" ],
     [ "1.0.aa" ],
     [ "1.0.a1" ],
     [ "1.0.k" ],
     [ "1.0.1a" ],
+    [ "1.0.1.2", "1.0ab" ],
     [ "1.0.1z" ],
     [ "1.0.11", "1.0k" ],
     [ "2.0pre", "2.0rc" ],
@@ -76,14 +72,14 @@ my $versions = [
     [ "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]}) {
+$Test::TESTOUT = IO::Null->new; # suppress the 'ok' output.
+foreach my $i (0 .. $#versions) {
+       foreach my $j (0 .. $#versions) {
+               foreach my $vi (@{$versions[$i]}) {
+                       foreach my $vj (@{$versions[$j]}) {
                                my $actual = pkgversioncmp($vi, '<', $vj) ? '<'
                                    : pkgversioncmp($vi, '<=', $vj) ? '=='
                                    : '>';
@@ -96,3 +92,5 @@ for (my $i = 0; $i < $#{$versions}; $i++
        }
 }
 $Test::TESTOUT = $prev;
+
+ok('done', 'done');



Home | Main Index | Thread Index | Old Index