pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/lintpkgsrc/files lintpkgsrc: extract brace ex...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/ac8c99850275
branches:  trunk
changeset: 383175:ac8c99850275
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sun Aug 14 12:40:43 2022 +0000

description:
lintpkgsrc: extract brace expansion, document its various bugs

diffstat:

 pkgtools/lintpkgsrc/files/lintpkgsrc.pl |  36 +++++++++++++++++++-------------
 pkgtools/lintpkgsrc/files/t/glob.t      |  24 +++++++++++++++++++++-
 2 files changed, 44 insertions(+), 16 deletions(-)

diffs (95 lines):

diff -r 8497c1fad0a0 -r ac8c99850275 pkgtools/lintpkgsrc/files/lintpkgsrc.pl
--- a/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Sun Aug 14 12:13:03 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Sun Aug 14 12:40:43 2022 +0000
@@ -1,5 +1,5 @@
 #!@PERL5@
-# $NetBSD: lintpkgsrc.pl,v 1.91 2022/08/14 03:18:36 rillig Exp $
+# $NetBSD: lintpkgsrc.pl,v 1.92 2022/08/14 12:40:43 rillig Exp $
 
 # Written by David Brownlee <abs%netbsd.org@localhost>.
 #
@@ -246,6 +246,25 @@
            : $cmp >= 0;
 }
 
+sub expand_braces($str) {
+       my @todo = ($str);
+
+       my @expanded;
+       # FIXME: see test_expand_braces.
+       while ($str = shift @todo) {
+               # FIXME: see test_expand_braces.
+               if ($str =~ /(.*) \{ ([^{}]+) } (.*)/x) {
+                       # FIXME: see test_expand_braces.
+                       foreach (split(',', $2)) {
+                               push @todo, "$1$_$3";
+                       }
+               } else {
+                       push @expanded, $str;
+               }
+       }
+       @expanded;
+}
+
 # Return a copy of $value in which trivial variable expressions are replaced
 # with their variable values.
 sub expand_exprs($value, $vars) {
@@ -696,21 +715,8 @@
 #
 sub invalid_version($pkgmatch) {
        my ($fail, $ok);
-       my (@pkgmatches);
 
-       my @todo = ($pkgmatch);
-
-       # We handle {} here, everything else in package_globmatch
-       while ($pkgmatch = shift @todo) {
-               if ($pkgmatch =~ /(.*)\{([^{}]+)}(.*)/) {
-                       foreach (split(',', $2)) {
-                               push @todo, "$1$_$3";
-                       }
-               } else {
-                       push @pkgmatches, $pkgmatch;
-               }
-       }
-
+       my @pkgmatches = expand_braces($pkgmatch);
        foreach $pkgmatch (@pkgmatches) {
                my ($pkg, $badver) = package_globmatch($pkgmatch);
 
diff -r 8497c1fad0a0 -r ac8c99850275 pkgtools/lintpkgsrc/files/t/glob.t
--- a/pkgtools/lintpkgsrc/files/t/glob.t        Sun Aug 14 12:13:03 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/t/glob.t        Sun Aug 14 12:40:43 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: glob.t,v 1.8 2022/08/13 12:22:20 rillig Exp $
+# $NetBSD: glob.t,v 1.9 2022/08/14 12:40:43 rillig Exp $
 #
 # Tests for file globbing and matching.
 
@@ -58,4 +58,26 @@
        ok("a\nb" =~ $re, 1);
 }
 
+sub test_expand_braces() {
+       my @examples = (
+           [ '', ],
+           [ 'abc', 'abc' ],
+           [ '{a,b,c}', 'a', 'b', 'c' ],
+           # FIXME: '<>' is missing.
+           [ '<{opt,}>', '<opt>' ],
+           [ '<{,opt}>', '<>', '<opt>' ],
+           # FIXME: '0', '1', '2' are missing.
+           [ '{0,1,2}', ],
+           # FIXME: '0' is missing.
+           [ '{2,1,0}', '2', '1' ],
+       );
+
+       foreach my $example (@examples) {
+               my ($str, @expected) = @$example;
+               my @actual = expand_braces($str);
+               ok(join(' ', @actual), join(' ', @expected));
+       }
+}
+
 test_glob2regex();
+test_expand_braces();



Home | Main Index | Thread Index | Old Index