[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.10-216-g4905b0e



The following commit has been merged in the master branch:
commit 4905b0e1346b12f8e2cd6e01b9ee75c879e455e7
Author: Niels Thykier <niels@thykier.net>
Date:   Sun Oct 21 14:07:15 2012 +0200

    Test::L: Add sub to test that profiles are loadable
    
    Add sub to find and load all profiles in a given LINTIAN_ROOT.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/lib/Test/Lintian.pm b/lib/Test/Lintian.pm
index 9478033..e168dd8 100644
--- a/lib/Test/Lintian.pm
+++ b/lib/Test/Lintian.pm
@@ -45,10 +45,13 @@ use warnings;
 
 my $CLASS = __PACKAGE__;
 my $PROFILE = undef;
-our @EXPORT = qw(load_profile_for_test test_check_desc);
+our @EXPORT = qw(load_profile_for_test test_check_desc test_load_profiles);
 
 use base 'Test::Builder::Module';
 
+use File::Find ();
+use Cwd qw(realpath);
+
 use Lintian::Check qw(check_spelling);
 use Lintian::Data;
 use Lintian::Profile;
@@ -198,6 +201,54 @@ sub test_check_desc {
     }
 }
 
+=item test_load_profile (ROOT, INC...)
+
+Test that all profiles in I<ROOT/profiles> are loadable.  INC will be
+the INC path used as include path for the profile.
+
+If INC is omitted, then the include path will consist of (ROOT,
+'/usr/share/lintian').  Otherwise, INC will be used as is (and should
+include ROOT).
+
+This sub will do one test per profile loaded.
+
+=cut
+
+sub test_load_profiles {
+    my ($dir, @inc) = @_;
+    my $builder = $CLASS->builder;
+    my $absdir = realpath $dir;
+    my $sre;
+    my %opt = (
+        'no_chdir' => 1,
+    );
+    if (not defined $absdir) {
+        die "$dir cannot be resolved: $!";
+    }
+    $absdir = "$absdir/profiles";
+    $sre = qr,\Q$absdir\E/,;
+
+    @inc = ($absdir, '/usr/share/lintian') unless @inc;
+
+    $opt{'wanted'} = sub {
+        my $profname = $File::Find::name;
+        my ($err, $prof);
+
+        return unless $profname =~ s/\.profile$//o;
+        $profname =~ s,^$sre,,;
+
+        eval {
+            $prof = Lintian::Profile->new ($profname, \@inc);
+        };
+        $err = $@;
+
+        $builder->ok ($prof, "$profname is loadable.")
+            or $builder->diag ("Load error: $@\n");
+    };
+
+    File::Find::find (\%opt, $absdir);
+}
+
 =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/profile-load.t b/t/scripts/profile-load.t
new file mode 100755
index 0000000..aabc44a
--- /dev/null
+++ b/t/scripts/profile-load.t
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+
+# Test that all profiles are loadable...
+
+use strict;
+use warnings;
+
+use Test::Lintian;
+use Test::More;
+
+# We could use a plan, but then we had to update every time we added
+# or removed a profile...
+test_load_profiles ($ENV{'LINTIAN_ROOT'}, $ENV{'LINTIAN_ROOT'});
+
+done_testing;
+

-- 
Debian package checker


Reply to: