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 16:15:49 UTC 2022

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

Log Message:
lintpkgsrc: test parsing of package makefiles


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 pkgsrc/pkgtools/lintpkgsrc/Makefile
cvs rdiff -u -r1.42 -r1.43 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
cvs rdiff -u -r0 -r1.1 pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t \
    pkgsrc/pkgtools/lintpkgsrc/files/t/parse_makefile.t
cvs rdiff -u -r1.2 -r1.3 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.43 pkgsrc/pkgtools/lintpkgsrc/Makefile:1.44
--- pkgsrc/pkgtools/lintpkgsrc/Makefile:1.43    Sat Jul 30 16:20:18 2022
+++ pkgsrc/pkgtools/lintpkgsrc/Makefile Wed Aug  3 16:15:49 2022
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.43 2022/07/30 16:20:18 rillig Exp $
+# $NetBSD: Makefile,v 1.44 2022/08/03 16:15:49 rillig Exp $
 
 PKGNAME=       lintpkgsrc-4.99
 CATEGORIES=    pkgtools
@@ -9,6 +9,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
 CONFLICTS+=    pkglint<4.82
 
 USE_TOOLS+=    perl:run
@@ -37,6 +38,7 @@ do-build:
 do-test:
        ${RUN} cd ${WRKSRC}/t;                                          \
        for test in ./*.t; do                                           \
+               echo "Testing $${test#./}";                             \
                perl "$$test";                                          \
        done
 

Index: pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
diff -u pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.42 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.43
--- pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.42 Sat Jul 30 18:20:23 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl      Wed Aug  3 16:15:49 2022
@@ -1,6 +1,6 @@
 #!@PERL5@
 
-# $NetBSD: lintpkgsrc.pl,v 1.42 2022/07/30 18:20:23 rillig Exp $
+# $NetBSD: lintpkgsrc.pl,v 1.43 2022/08/03 16:15:49 rillig Exp $
 
 # Written by David Brownlee <abs%netbsd.org@localhost>.
 #
@@ -361,6 +361,8 @@ sub pkgversioncmp($$$) {
        eval "$cmp $test 0";
 }
 
+# Return a copy of $line in which trivial variable expressions are replaced
+# with the variable values.
 sub parse_expand_vars($$) {
        my ($line, $vars) = @_;
 
@@ -1807,4 +1809,11 @@ sub main() {
        }
 }
 
+if (caller()) {
+       # To allow easy testing of the code.
+       # TODO: reduce the use of global variables, or make them accessible
+       #  to the tests.
+       $default_vars = {};
+}
+
 main() unless caller();

Index: pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t
diff -u pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.2 pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.3
--- pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.2 Sat Jul 30 17:06:29 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t     Wed Aug  3 16:15:49 2022
@@ -1,4 +1,5 @@
-# $NetBSD: pkgversion.t,v 1.2 2022/07/30 17:06:29 rillig Exp $
+# $NetBSD: pkgversion.t,v 1.3 2022/08/03 16:15:49 rillig Exp $
+
 use strict;
 use warnings;
 use Test;

Added files:

Index: pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t
diff -u /dev/null pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t:1.1
--- /dev/null   Wed Aug  3 16:15:49 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t   Wed Aug  3 16:15:49 2022
@@ -0,0 +1,47 @@
+# $NetBSD: glob.t,v 1.1 2022/08/03 16:15:49 rillig Exp $
+
+use strict;
+use warnings;
+use Test;
+
+BEGIN { plan tests => 12; }
+
+require('../lintpkgsrc.pl');
+
+sub test_glob2regex() {
+
+       ok(glob2regex('*'), '^.*$');
+
+       ok(glob2regex('?'), '^.$');
+
+       # The '' means that the regular expression equals the glob.
+       ok(glob2regex('[a-z]'), '');
+
+       # The '' means that the regular expression equals the glob.
+       ok(glob2regex('[a-z0-9]'), '');
+
+       # The '' means that the regular expression equals the glob.
+       ok(glob2regex('[a-z0-9_]'), '');
+
+       ok(glob2regex('*.[ch]'), '^.*\.[ch]$');
+
+       ok(glob2regex('{one,two}'), '^(one|two)$');
+
+       ok(glob2regex('{{thi,fou}r,fif}teen'), '^((thi|fou)r|fif)teen$');
+
+       # There is an unbalanced '}' at the very end.
+       ok(glob2regex('{{thi,fou}r,fif}teen}'), undef);
+
+       # XXX: Why is '+' turned into '.'?
+       ok(glob2regex('a+b|c'), '^a.b\|c$');
+
+       # XXX: Typo in the code, the case '\\+' is unreachable.
+       # Escaping the backslash works nevertheless.
+       ok(glob2regex('a\[b*'), '^a\[b.*$');
+
+       # XXX: Depending on the exact implementation, the '\n' may be
+       # interpreted as a newline, a literal 'n' or a literal '\' 'n'.
+       ok(glob2regex('a\n*'), '^a\n.*$');
+}
+
+test_glob2regex();
Index: pkgsrc/pkgtools/lintpkgsrc/files/t/parse_makefile.t
diff -u /dev/null pkgsrc/pkgtools/lintpkgsrc/files/t/parse_makefile.t:1.1
--- /dev/null   Wed Aug  3 16:15:49 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/t/parse_makefile.t Wed Aug  3 16:15:49 2022
@@ -0,0 +1,56 @@
+# $NetBSD: parse_makefile.t,v 1.1 2022/08/03 16:15:49 rillig Exp $
+
+use strict;
+use warnings;
+use File::Slurp;
+use File::Temp;
+use Test;
+
+BEGIN { plan tests => 6; }
+
+require('../lintpkgsrc.pl');
+
+sub test_parse_expand_vars() {
+       my %vars = (
+           CFLAGS      => '${CFLAGS_OPT} ${CFLAGS_WARN} ${CFLAGS_ERR}',
+           CFLAGS_WARN => '${CFLAGS_WARN_ALL}',
+           CFLAGS_OPT  => '-Os',
+           CFLAGS_ERR  => '${CFLAGS_WARN_ALL:M*error=*}',
+       );
+
+       my $cflags = parse_expand_vars('<${CFLAGS}>', \%vars);
+
+       ok($cflags, '<-Os M_a_G_i_C_uNdEfInEd ${CFLAGS_WARN_ALL:M*error=*}>')
+}
+
+sub test_parse_makefile_vars() {
+       my $dir = File::Temp->newdir();
+       my $file = "$dir/filename.mk";
+
+       write_file($file,
+           "# comment\n",
+           "VAR=\tvalue\n",
+           "COMMENT=\tvalue#comment\n",
+           "MULTI=\tone\\\n",
+           "\ttwo\\\n",
+           "three#comment\n"
+       );
+
+       my $vars = parse_makefile_vars($file, undef);
+
+       ok(
+           join(', ', sort keys %$vars),
+           '.CURDIR, BSD_PKG_MK, COMMENT, MULTI, VAR');
+       ok($vars->{BSD_PKG_MK}, 'YES');
+
+       # FIXME: must be 'value'
+       ok($vars->{COMMENT}, 'valu');
+
+       # FIXME: must be 'one two three'
+       ok($vars->{MULTI}, "on\ttwthree#comment");
+
+       ok($vars->{VAR}, 'value');
+}
+
+test_parse_expand_vars();
+test_parse_makefile_vars();



Home | Main Index | Thread Index | Old Index