Skip to content

Commit

Permalink
lintpkgsrc: test code for storing package data
Browse files Browse the repository at this point in the history
  • Loading branch information
rillig committed Jul 30, 2022
1 parent 17f4dea commit 444502e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkgtools/lintpkgsrc/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.42 2022/07/30 14:55:51 rillig Exp $
# $NetBSD: Makefile,v 1.43 2022/07/30 16:20:18 rillig Exp $

PKGNAME= lintpkgsrc-4.99
CATEGORIES= pkgtools
Expand All @@ -8,6 +8,7 @@ HOMEPAGE= https://www.NetBSD.org/docs/pkgsrc/
COMMENT= Sanity checks on the complete pkgsrc tree

DEPENDS+= digest>=20010101:../../pkgtools/digest
TEST_DEPENDS+= p5-Capture-Tiny>=0:../../devel/p5-Capture-Tiny
CONFLICTS+= pkglint<4.82

USE_TOOLS+= perl:run
Expand Down
44 changes: 44 additions & 0 deletions pkgtools/lintpkgsrc/files/t/packages.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# $NetBSD: packages.t,v 1.1 2022/07/30 16:20:18 rillig Exp $

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

BEGIN { plan tests => 1; }

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

sub test_package_variables() {
my $pkglist = PkgList->new();
my $pkgbase_1_0 = $pkglist->add('pkgbase', '1.0');

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

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

# Demonstrate how the package data is stored in the cache file.
sub test_store_order() {
my $pkglist = PkgList->new();

my $pkgbase_1_0 = $pkglist->add('pkgbase', '1.0');
my $pkgbase_1_3nb4 = $pkglist->add('pkgbase', '1.3nb4');
my $pkgbase_1_15 = $pkglist->add('pkgbase', '1.15');

my $stdout = capture {
$pkglist->store();
};

# XXX: 1.3nb4 should be sorted before 1.15.
# On the other hand, this is just an internal cache file format.
ok($stdout, ''
. "package\tpkgbase\t1.0\n"
. "package\tpkgbase\t1.15\n"
. "package\tpkgbase\t1.3nb4\n");
}

test_package_variables();
test_store_order();

0 comments on commit 444502e

Please sign in to comment.