Skip to content

Commit

Permalink
lintpkgsrc: test versioned packages, minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rillig committed Jul 30, 2022
1 parent 57ffca2 commit d1b9876
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
21 changes: 14 additions & 7 deletions pkgtools/lintpkgsrc/files/lintpkgsrc.pl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!@PERL5@

# $NetBSD: lintpkgsrc.pl,v 1.39 2022/07/30 16:26:14 rillig Exp $
# $NetBSD: lintpkgsrc.pl,v 1.40 2022/07/30 17:06:29 rillig Exp $

# Written by David Brownlee <abs@netbsd.org>.
#
Expand All @@ -22,7 +22,8 @@
use IPC::Open3;
use Cwd 'realpath', 'getcwd';

# PkgVer is a unique package + version.
# PkgVer is a PKGBASE + PKGVERSION, including some of the variables that
# have been extracted from the package Makefile.
#
package PkgVer;

Expand Down Expand Up @@ -87,7 +88,8 @@ ($)
}
}

# Pkgs is all versions of a given package (eg: apache-1.x and apache-2.x)
# Pkgs collects all versions of a given PKGBASE, e.g. apache-1.3.27 and
# apache-2.0.46.
#
package Pkgs;

Expand All @@ -106,6 +108,8 @@ ($@)
return $self;
}

# Returns all available versions of the package, in decreasing
# alphabetical(!) order.
sub versions($) {
my $self = shift;

Expand All @@ -117,16 +121,19 @@ ($)
$self->{_pkg};
}

# Returns all available versioned packages of this PKGBASE, in decreasing
# alphabetical(!) order.
sub pkgver($@) {
my $self = shift;

my $pkgvers = $self->{_pkgver};
if (@_) {
if ($self->{_pkgver}{$_[0]}) {
return ($self->{_pkgver}{$_[0]});
if ($pkgvers->{$_[0]}) {
return ($pkgvers->{$_[0]});
}
return;
}
return sort { $b->ver() cmp $a->ver() } values %{$self->{_pkgver}};
return sort { $b->ver cmp $a->ver } values %{$pkgvers};
}

sub latestver($) {
Expand Down Expand Up @@ -1787,4 +1794,4 @@ ()
}
}

main() unless defined $ENV{'TESTING_LINTPKGSRC'};
main() unless caller();
23 changes: 20 additions & 3 deletions pkgtools/lintpkgsrc/files/t/packages.t
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# $NetBSD: packages.t,v 1.1 2022/07/30 16:20:18 rillig Exp $
# $NetBSD: packages.t,v 1.2 2022/07/30 17:06:29 rillig Exp $

use strict;
use warnings;
use Capture::Tiny 'capture';
use Test;

BEGIN { plan tests => 1; }
BEGIN { plan tests => 8; }

$ENV{'TESTING_LINTPKGSRC'} = 'yes';
require('../lintpkgsrc.pl');

sub test_package_variables() {
Expand All @@ -18,6 +17,24 @@ sub test_package_variables() {

ok($pkgbase_1_0->var('NAME'), 'value');
ok($pkgbase_1_0->var('undefined'), undef);

my $pkgbase_2_0 = $pkglist->add('pkgbase', '2.0');
my $pkgbase_1_5 = $pkglist->add('pkgbase', '1.5');
my $pkgbase_1_10 = $pkglist->add('pkgbase', '1.10');

$pkgbase_2_0->var('COMMENT', 'Version 2 of the package');

ok($pkglist->pkgs('unknown-pkgbase'), undef);

# The versions are sorted in decreasing alphabetical order.
my $versions = join(', ', $pkglist->pkgs('pkgbase')->versions());
ok($versions, '2.0, 1.5, 1.10, 1.0');

# The versioned packages are sorted in decreasing alphabetical order.
my @pkgvers = $pkglist->pkgver('pkgbase');
ok(join(', ', map { $_->ver } @pkgvers), '2.0, 1.5, 1.10, 1.0');
ok($pkgvers[0], $pkgbase_2_0);
ok($pkgvers[3], $pkgbase_1_0);
}

# Demonstrate how the package data is stored in the cache file.
Expand Down
3 changes: 1 addition & 2 deletions pkgtools/lintpkgsrc/files/t/pkgversion.t
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# $NetBSD: pkgversion.t,v 1.1 2022/07/30 10:11:45 rillig Exp $
# $NetBSD: pkgversion.t,v 1.2 2022/07/30 17:06:29 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'), '');
Expand Down

0 comments on commit d1b9876

Please sign in to comment.