pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/pkgtools/lintpkgsrc lintpkgsrc: test parsing of packag...
details: https://anonhg.NetBSD.org/pkgsrc/rev/f04568ebebba
branches: trunk
changeset: 382702:f04568ebebba
user: rillig <rillig%pkgsrc.org@localhost>
date: Wed Aug 03 16:15:49 2022 +0000
description:
lintpkgsrc: test parsing of package makefiles
diffstat:
pkgtools/lintpkgsrc/Makefile | 4 +-
pkgtools/lintpkgsrc/files/lintpkgsrc.pl | 11 +++++-
pkgtools/lintpkgsrc/files/t/glob.t | 47 +++++++++++++++++++++++
pkgtools/lintpkgsrc/files/t/parse_makefile.t | 56 ++++++++++++++++++++++++++++
pkgtools/lintpkgsrc/files/t/pkgversion.t | 3 +-
5 files changed, 118 insertions(+), 3 deletions(-)
diffs (178 lines):
diff -r a41f47647b7a -r f04568ebebba pkgtools/lintpkgsrc/Makefile
--- a/pkgtools/lintpkgsrc/Makefile Wed Aug 03 16:15:46 2022 +0000
+++ b/pkgtools/lintpkgsrc/Makefile Wed Aug 03 16:15:49 2022 +0000
@@ -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 @@
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-test:
${RUN} cd ${WRKSRC}/t; \
for test in ./*.t; do \
+ echo "Testing $${test#./}"; \
perl "$$test"; \
done
diff -r a41f47647b7a -r f04568ebebba pkgtools/lintpkgsrc/files/lintpkgsrc.pl
--- a/pkgtools/lintpkgsrc/files/lintpkgsrc.pl Wed Aug 03 16:15:46 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/lintpkgsrc.pl Wed Aug 03 16:15:49 2022 +0000
@@ -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 @@
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 @@
}
}
+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();
diff -r a41f47647b7a -r f04568ebebba pkgtools/lintpkgsrc/files/t/glob.t
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/lintpkgsrc/files/t/glob.t Wed Aug 03 16:15:49 2022 +0000
@@ -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();
diff -r a41f47647b7a -r f04568ebebba pkgtools/lintpkgsrc/files/t/parse_makefile.t
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/lintpkgsrc/files/t/parse_makefile.t Wed Aug 03 16:15:49 2022 +0000
@@ -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();
diff -r a41f47647b7a -r f04568ebebba pkgtools/lintpkgsrc/files/t/pkgversion.t
--- a/pkgtools/lintpkgsrc/files/t/pkgversion.t Wed Aug 03 16:15:46 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/t/pkgversion.t Wed Aug 03 16:15:49 2022 +0000
@@ -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;
Home |
Main Index |
Thread Index |
Old Index