[SCM] Debian package checker branch, master, updated. 2.5.10-220-g7aed1e0
The following commit has been merged in the master branch:
commit 7aed1e0f8f983bd90ec243f1f40d812865ff4480
Author: Niels Thykier <niels@thykier.net>
Date: Mon Oct 22 12:05:43 2012 +0200
T::L: Add test_load_checks
Add new sub test_load_checks in Test::Lintian and use it in a new test
script. It tests whether a given check can be loaded and that said
check has the required "run" sub.
Signed-off-by: Niels Thykier <niels@thykier.net>
diff --git a/lib/Test/Lintian.pm b/lib/Test/Lintian.pm
index 834abb3..5cbe46c 100644
--- a/lib/Test/Lintian.pm
+++ b/lib/Test/Lintian.pm
@@ -45,7 +45,13 @@ use warnings;
my $CLASS = __PACKAGE__;
my $PROFILE = undef;
-our @EXPORT = qw(load_profile_for_test test_check_desc test_load_profiles);
+our @EXPORT = qw(
+ load_profile_for_test
+
+ test_check_desc
+ test_load_checks
+ test_load_profiles
+);
use base 'Test::Builder::Module';
@@ -249,6 +255,64 @@ sub test_load_profiles {
File::Find::find (\%opt, $absdir);
}
+=item test_load_checks (DESCFILES...)
+
+Test that the Perl module implementation of the checks can be loaded
+and has a run sub.
+
+DESCFILES is a list of paths in which to check desc files.
+
+For planning purposes, every element in DESCFILES counts for 2 tests.
+
+NB: This will load a profile if one hasn't been loaded already. This
+is done to avoid issues loading L<data files|Lintian::Data> in the
+package scope of the checks. (see
+L</load_profile_for_test ([PROFNAME[, INC...]])>)
+
+=cut
+
+sub test_load_checks {
+ my (@descs) = @_;
+ my $builder = $CLASS->builder;
+
+ load_profile_for_test ();
+
+ foreach my $desc (@descs) {
+ my $cs = Lintian::CheckScript->new ($desc);
+ my $cname = $cs->name;
+ my $ppkg = $cname;
+ my $path = $desc;
+ my $err;
+ my $rs_ref = 'MISSING';
+
+ $path =~ s,\.desc$,,o;
+
+ eval {
+ require $path;
+ };
+
+ if (!$builder->is_eq ($@//'', '', "Check $cname can be loaded")) {
+ $builder->skip ("Cannot check if $cname has a run sub due to load error");
+ next;
+ }
+
+ $ppkg =~ s,[-.],_,go;
+ $ppkg =~ s,/,::,go;
+ $ppkg = "Lintian::$ppkg";
+ eval {
+ # minimal "no strict refs" scope.
+ no strict 'refs';
+ $rs_ref = 'PRESENT'
+ if defined &{$ppkg . '::run'};
+ };
+ $err = $@//'';
+ if (! $builder->is_eq ($rs_ref, 'PRESENT', "Check $cname has runsub")) {
+ $builder->diag ("Expected package name is $ppkg\n");
+ $builder->diag ("Error: $err\n") if $err;
+ }
+ }
+}
+
=item load_profile_for_test ([PROFNAME[, INC...]])
Load a Lintian::Profile and ensure Data files can be used. This is
diff --git a/t/scripts/check-descs.t b/t/scripts/check-load.t
similarity index 77%
copy from t/scripts/check-descs.t
copy to t/scripts/check-load.t
index 5c5c3a5..a998300 100755
--- a/t/scripts/check-descs.t
+++ b/t/scripts/check-load.t
@@ -21,15 +21,14 @@
use strict;
use warnings;
-use Test::More import => ['done_testing'];
+use Test::More import => ['plan'];
use Test::Lintian;
-load_profile_for_test ('debian/main', $ENV{'LINTIAN_ROOT'});
+# Test that all checks can be loaded (except lintian.desc, which is
+# a special case).
+our @DESCS = (grep { !m,/lintian.desc$, } <$ENV{LINTIAN_ROOT}/checks/*.desc>);
-my $opts = {
- 'coll-dir' => "$ENV{'LINTIAN_ROOT'}/collection",
-};
+plan tests => 2 * scalar @DESCS;
-test_check_desc ($opts, <$ENV{'LINTIAN_ROOT'}/checks/*.desc>);
+test_load_checks (@DESCS);
-done_testing;
--
Debian package checker
Reply to: