Sat Jul 30 10:11:45 2022 UTC ()
lintpkgsrc: add automatic tests

Not sure whether this form of running tests is the idiomatic one, as
lintpkgsrc is not a Perl module but a Perl program, but it works.

The number of planned tests (5 for now) seems to be ignored, no idea
why.


(rillig)
diff -r1.39 -r1.40 pkgsrc/pkgtools/lintpkgsrc/Makefile
diff -r1.34 -r1.35 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
diff -r0 -r1.1 pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t

cvs diff -r1.39 -r1.40 pkgsrc/pkgtools/lintpkgsrc/Makefile (expand / switch to unified diff)

--- pkgsrc/pkgtools/lintpkgsrc/Makefile 2022/06/28 11:35:24 1.39
+++ pkgsrc/pkgtools/lintpkgsrc/Makefile 2022/07/30 10:11:45 1.40
@@ -1,50 +1,54 @@ @@ -1,50 +1,54 @@
1# $NetBSD: Makefile,v 1.39 2022/06/28 11:35:24 wiz Exp $ 1# $NetBSD: Makefile,v 1.40 2022/07/30 10:11:45 rillig Exp $
2 2
3PKGNAME= lintpkgsrc-4.98 3PKGNAME= lintpkgsrc-4.98
4PKGREVISION= 1 4PKGREVISION= 1
5CATEGORIES= pkgtools 5CATEGORIES= pkgtools
6 6
7MAINTAINER= pkgsrc-users@NetBSD.org 7MAINTAINER= pkgsrc-users@NetBSD.org
8HOMEPAGE= https://www.NetBSD.org/Documentation/pkgsrc/ 8HOMEPAGE= https://www.NetBSD.org/Documentation/pkgsrc/
9COMMENT= Sanity checks on the complete pkgsrc tree 9COMMENT= Sanity checks on the complete pkgsrc tree
10 10
11DEPENDS+= digest>=20010101:../../pkgtools/digest 11DEPENDS+= digest>=20010101:../../pkgtools/digest
12CONFLICTS+= pkglint<4.82 12CONFLICTS+= pkglint<4.82
13 13
14USE_TOOLS+= perl:run 14USE_TOOLS+= perl:run
15 15
16WRKSRC= ${WRKDIR} 16WRKSRC= ${WRKDIR}
17NO_BUILD= yes 
18USE_LANGUAGES= # none 17USE_LANGUAGES= # none
19AUTO_MKDIRS= yes 18AUTO_MKDIRS= yes
20 19
21SUBST_CLASSES+= lp 20SUBST_CLASSES+= lp
22SUBST_STAGE.lp= post-configure 21SUBST_STAGE.lp= post-configure
23SUBST_FILES.lp+= lintpkgsrc.0 lintpkgsrc.1 lintpkgsrc.pl 22SUBST_FILES.lp+= lintpkgsrc.0 lintpkgsrc.1 lintpkgsrc.pl
24.if defined(BATCH) 23SUBST_SED.lp+= -e 's;@PKGSRCDIR@;${BATCH:D/usr/pkgsrc:U${PKGSRCDIR}};g'
25SUBST_SED.lp+= -e 's;@PKGSRCDIR@;/usr/pkgsrc;g' 
26.else 
27SUBST_VARS.lp+= PKGSRCDIR 
28.endif 
29SUBST_VARS.lp+= MAKE 24SUBST_VARS.lp+= MAKE
30SUBST_VARS.lp+= PERL5 25SUBST_VARS.lp+= PERL5
31SUBST_VARS.lp+= PKG_SYSCONFDIR 26SUBST_VARS.lp+= PKG_SYSCONFDIR
32SUBST_VARS.lp+= PREFIX 27SUBST_VARS.lp+= PREFIX
33 28
34.include "../../mk/bsd.prefs.mk" 29.include "../../mk/bsd.prefs.mk"
35 30
36do-extract: 31do-extract:
37 cd ${FILESDIR} && cp lintpkgsrc.* ${WRKSRC}/ 32 cd ${FILESDIR} && cp -R lintpkgsrc.* t ${WRKSRC}/
 33
 34do-build:
 35 # Nothing
 36
 37do-test:
 38 ${RUN} cd ${WRKSRC}/t; \
 39 for test in ./*.t; do \
 40 perl "$$test"; \
 41 done
38 42
39do-install: 43do-install:
40 ${INSTALL_SCRIPT} ${WRKSRC}/lintpkgsrc.pl ${DESTDIR}${PREFIX}/bin/lintpkgsrc 44 ${INSTALL_SCRIPT} ${WRKSRC}/lintpkgsrc.pl ${DESTDIR}${PREFIX}/bin/lintpkgsrc
41.if !empty(MANINSTALL:Mcatinstall) 45.if !empty(MANINSTALL:Mcatinstall)
42. if defined(CATMAN_SECTION_SUFFIX) && !empty(CATMAN_SECTION_SUFFIX:M[Yy][Ee][Ss]) 46. if defined(CATMAN_SECTION_SUFFIX) && !empty(CATMAN_SECTION_SUFFIX:M[Yy][Ee][Ss])
43 ${INSTALL_MAN} ${WRKSRC}/lintpkgsrc.0 ${DESTDIR}${PREFIX}/${PKGMANDIR}/cat1/lintpkgsrc.1 47 ${INSTALL_MAN} ${WRKSRC}/lintpkgsrc.0 ${DESTDIR}${PREFIX}/${PKGMANDIR}/cat1/lintpkgsrc.1
44. else 48. else
45 ${INSTALL_MAN} ${WRKSRC}/lintpkgsrc.0 ${DESTDIR}${PREFIX}/${PKGMANDIR}/cat1 49 ${INSTALL_MAN} ${WRKSRC}/lintpkgsrc.0 ${DESTDIR}${PREFIX}/${PKGMANDIR}/cat1
46. endif 50. endif
47.endif 51.endif
48.if !empty(MANINSTALL:Mmaninstall) 52.if !empty(MANINSTALL:Mmaninstall)
49 ${INSTALL_MAN} ${WRKSRC}/lintpkgsrc.1 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man1 53 ${INSTALL_MAN} ${WRKSRC}/lintpkgsrc.1 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man1
50.endif 54.endif

cvs diff -r1.34 -r1.35 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl (expand / switch to unified diff)

--- pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl 2022/07/30 09:37:21 1.34
+++ pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl 2022/07/30 10:11:45 1.35
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1#!@PERL5@ 1#!@PERL5@
2 2
3# $NetBSD: lintpkgsrc.pl,v 1.34 2022/07/30 09:37:21 rillig Exp $ 3# $NetBSD: lintpkgsrc.pl,v 1.35 2022/07/30 10:11:45 rillig Exp $
4 4
5# Written by David Brownlee <abs@netbsd.org>. 5# Written by David Brownlee <abs@netbsd.org>.
6# 6#
7# Caveats: 7# Caveats:
8# The 'Makefile parsing' algorithm used to obtain package versions and 8# The 'Makefile parsing' algorithm used to obtain package versions and
9# DEPENDS information is geared towards speed rather than perfection, 9# DEPENDS information is geared towards speed rather than perfection,
10# though it has gotten somewhat better over time, it only parses the 10# though it has gotten somewhat better over time, it only parses the
11# simpler Makefile conditionals. 11# simpler Makefile conditionals.
12# 12#
13# TODO: Handle fun DEPENDS like avifile-devel with 13# TODO: Handle fun DEPENDS like avifile-devel with
14# {qt2-designer>=2.2.4,qt2-designer-kde>=2.3.1nb1} 14# {qt2-designer>=2.2.4,qt2-designer-kde>=2.3.1nb1}
15 15
16use locale; 16use locale;
@@ -292,27 +292,27 @@ sub listdir($$) { @@ -292,27 +292,27 @@ sub listdir($$) {
292 @list; 292 @list;
293} 293}
294 294
295sub canonicalize_pkgname($) { 295sub canonicalize_pkgname($) {
296 my ($pkgname) = @_; 296 my ($pkgname) = @_;
297 297
298 $pkgname =~ s,^py\d+(?:pth|)-,py-,; 298 $pkgname =~ s,^py\d+(?:pth|)-,py-,;
299 $pkgname =~ s,^ruby\d+-,ruby-,; 299 $pkgname =~ s,^ruby\d+-,ruby-,;
300 $pkgname =~ s,^php\d+-,php-,; 300 $pkgname =~ s,^php\d+-,php-,;
301 return $pkgname; 301 return $pkgname;
302} 302}
303 303
304sub convert_to_standard_pkgversion(@) { 304sub convert_to_standard_pkgversion(@) {
305 my ($elem, $underscore, @temp); 305 my ($elem, @temp);
306 306
307 # See pkg_install/lib/dewey.c. 307 # See pkg_install/lib/dewey.c.
308 # 'nb' has already been handled when we are here. 308 # 'nb' has already been handled when we are here.
309 foreach $elem (@_) { 309 foreach $elem (@_) {
310 if ($elem =~ /\d/) { 310 if ($elem =~ /\d/) {
311 push(@temp, $elem); 311 push(@temp, $elem);
312 } elsif ($elem eq "pl" || $elem eq "." || $elem eq "_") { 312 } elsif ($elem eq "pl" || $elem eq "." || $elem eq "_") {
313 push(@temp, 0); 313 push(@temp, 0);
314 } elsif ($elem eq "pre" || $elem eq "rc") { 314 } elsif ($elem eq "pre" || $elem eq "rc") {
315 push(@temp, -1); 315 push(@temp, -1);
316 } elsif ($elem eq "beta") { 316 } elsif ($elem eq "beta") {
317 push(@temp, -2); 317 push(@temp, -2);
318 } elsif ($elem eq "alpha") { 318 } elsif ($elem eq "alpha") {
@@ -1790,14 +1790,14 @@ sub main() { @@ -1790,14 +1790,14 @@ sub main() {
1790 print "$pkgsrcdir/$pkgdir\n"; 1790 print "$pkgsrcdir/$pkgdir\n";
1791 safe_chdir("$pkgsrcdir/$pkgdir"); 1791 safe_chdir("$pkgsrcdir/$pkgdir");
1792 system("$conf_make fetch-list | sh"); 1792 system("$conf_make fetch-list | sh");
1793 } 1793 }
1794 } 1794 }
1795 } 1795 }
1796 1796
1797 if ($opt{E}) { 1797 if ($opt{E}) {
1798 scan_pkgsrc_makefiles($pkgsrcdir); 1798 scan_pkgsrc_makefiles($pkgsrcdir);
1799 store_pkgsrc_makefiles($opt{E}); 1799 store_pkgsrc_makefiles($opt{E});
1800 } 1800 }
1801} 1801}
1802 1802
1803main(); 1803main() unless $ENV{'TESTING_LINTPKGSRC'} eq 'yes';

File Added: pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t
# $NetBSD: pkgversion.t,v 1.1 2022/07/30 10:11:45 rillig Exp $
use strict;
use warnings;
use Test;

BEGIN { plan tests => 5; }

$ENV{'TESTING_LINTPKGSRC'} = 'yes';
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'), '');