[SCM] Debian package checker branch, master, updated. 2.5.10-215-g1c4b2db
The following commit has been merged in the master branch:
commit 1c4b2db90b25502a7a308ab835bff8664648290c
Author: Niels Thykier <niels@thykier.net>
Date: Sun Oct 21 13:18:47 2012 +0200
Test::Lintian: Test for invalid Needs-Info fields
In test_check_desc also test for Needs-Info listing only known
collections. Remove the corresponding test from needs-info-exsts.t,
which now only tests collections.
Signed-off-by: Niels Thykier <niels@thykier.net>
diff --git a/lib/Test/Lintian.pm b/lib/Test/Lintian.pm
index 8d298a4..9478033 100644
--- a/lib/Test/Lintian.pm
+++ b/lib/Test/Lintian.pm
@@ -79,14 +79,31 @@ recommended to not specify a plan and use done_testing().
This sub uses a Data file (see L</load_profile_for_test ([PROFNAME[, INC...]])>).
+OPTS may contain the following key/value pairs:
+
+=over 4
+
+=item coll-dir
+
+Path to the collection directory (defaults to:
+/usr/share/lintian/collection). This is mostly useful for testing
+Lintian itself.
+
+If set to C<undef>, the test of Needs-Info containing only existing
+collections will be skipped.
+
+=back
+
=cut
sub test_check_desc {
my ($opts, @descs);
my $builder = $CLASS->builder;
+ my $colldir = '/usr/share/lintian/collection';
if (ref $_[0] eq 'HASH') {
$opts = shift;
+ $colldir = $opts->{'coll-dir'}//'' if exists $opts->{'coll-dir'};
}
$opts //= {};
@descs = @_;
@@ -97,6 +114,7 @@ sub test_check_desc {
my $cname = $header->{'check-script'}//'';
my $ctype = $header->{'type'} // '';
my $cinfo = $header->{'info'} // '';
+ my $needs = $header->{'needs-info'} // '';
my $i = 1; # paragraph counter.
$builder->isnt_eq ($cname, '', "Check has a name ($desc_file)");
$cname = '<missing>' if $cname eq '';
@@ -117,6 +135,20 @@ sub test_check_desc {
$builder->skip ("Cannot check type of $cname is valid (field is empty/missing)");
}
+ if ($needs and $colldir ne '') {
+ my @bad = ();
+
+ # new lines are not allowed, map them to "\\n" for readability.
+ $needs =~ s/\n/\\n/go;
+ foreach my $need (split m/\s*+,\s*+/o, $needs) {
+ push @bad, $need unless -f "$colldir/$need.desc";
+ }
+ $builder->is_eq (join (', ', @bad), '', '$cname has unknown collections in Needs-Info');
+ } else {
+ $builder->ok (1, 'Tag has a valid Needs-Info (empty)') if $colldir ne '';
+ $builder->skip ('Needs-Info test checks due to empty coll-dir') if $needs ne '';
+ }
+
$builder->is_eq (check_spelling (undef, $cinfo), 0,
"$cname Info has no spelling errors");
diff --git a/t/scripts/check-descs.t b/t/scripts/check-descs.t
index 28e6654..5c5c3a5 100755
--- a/t/scripts/check-descs.t
+++ b/t/scripts/check-descs.t
@@ -26,6 +26,10 @@ use Test::Lintian;
load_profile_for_test ('debian/main', $ENV{'LINTIAN_ROOT'});
-test_check_desc (<$ENV{'LINTIAN_ROOT'}/checks/*.desc>);
+my $opts = {
+ 'coll-dir' => "$ENV{'LINTIAN_ROOT'}/collection",
+};
+
+test_check_desc ($opts, <$ENV{'LINTIAN_ROOT'}/checks/*.desc>);
done_testing;
diff --git a/t/scripts/needs-info-exists.t b/t/scripts/needs-info-exists.t
index c6d8db2..86de157 100755
--- a/t/scripts/needs-info-exists.t
+++ b/t/scripts/needs-info-exists.t
@@ -22,31 +22,24 @@ use Test::More;
use Lintian::CollScript;
use Lintian::Util qw(read_dpkg_control);
-# Find all of the desc files in either collection or checks. We'll do one
-# check per description.
-our @DESCS = (<$ENV{LINTIAN_ROOT}/collection/*.desc>,
- <$ENV{LINTIAN_ROOT}/checks/*.desc>);
+# Find all of the desc files in collection. We'll do one check per
+# description. We don't check checks/*.desc because check-desc.t
+# handles that.
+our @DESCS = (<$ENV{LINTIAN_ROOT}/collection/*.desc>):
plan tests => scalar(@DESCS);
# For each desc file, load the first stanza of the file and check that all of
# its Needs-Info script references exist.
for my $desc (@DESCS) {
- my ($header) = read_dpkg_control($desc);
- my @needs;
+ my $coll = Lintian::CollScript->new ($desc);
+ my $name = $coll->name;
+ my @needs = $coll->needs_info;
my @missing;
- if ($header->{'collector-script'}) {
- my $coll = Lintian::CollScript->new ($desc);
- @needs = $coll->needs_info;
- } else {
- @needs = split(/\s*,\s*/, $header->{'needs-info'} || '');
- }
for my $coll (@needs) {
unless (-f "$ENV{LINTIAN_ROOT}/collection/$coll") {
- push(@missing, $coll);
+ push @missing, $coll;
}
}
- my $short = $desc;
- $short =~ s/^\Q$ENV{LINTIAN_ROOT}//;
- is(join(', ', @missing), '', "$short has valid needs-info");
+ is (join (', ', @missing), '', "$name has valid needs-info");
}
--
Debian package checker
Reply to: