File: profiles-coverage.t

package info (click to toggle)
lintian 2.5.10.4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 12,608 kB
  • sloc: perl: 12,430; sh: 5,787; makefile: 2,834; xml: 1,125; ansic: 347; python: 28; java: 9; tcl: 4; sed: 3
file content (84 lines) | stat: -rwxr-xr-x 2,294 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/perl

# Test for complete coverage of tags in profiles
#  - side-effect, test that all tags and checks
#    in the profiles are valid.

use strict;
use warnings;

use Test::More;

use File::Find;
use Lintian::Util qw(read_dpkg_control); # Test::More (also) exports fail

my $root = $ENV{'LINTIAN_ROOT'};
my @profiles;
my %CHECKS;
my %TAGS;

foreach my $desc (<$root/checks/*.desc>) {
    my ($header, @tags) = read_dpkg_control($desc);
    my $list = [];
    unless ($header->{'check-script'}) {
        fail("missing Check-Script field in $desc");
    }
    $CHECKS{$header->{'check-script'}} = $list;
    for my $tag (@tags) {
        unless ($tag->{tag}) {
            fail("missing Tag field in $desc");
        }
        push @$list, $tag->{tag};
        $TAGS{$tag->{tag}} = 0;
    }
}

plan tests => scalar (keys %TAGS);

File::Find::find(\&prof_wanted, "$root/profiles");

foreach my $tag (sort keys %TAGS){
    cmp_ok($TAGS{$tag}, '>', 0, $tag);
}

exit 0;

## SUBS ##

sub parse_profile {
    my ($profile) = @_;
    my ($header, @section) = read_dpkg_control($profile);
    my $en_checks = $header->{'enable-tags-from-check'}//'';
    my $dis_checks = $header->{'disable-tags-from-check'}//'';
    my $en_tag = $header->{'enable-tags'}//'';
    my $dis_tag = $header->{'disable-tags'}//'';
    foreach my $check (split m/\s*+,\s*+/o, $en_checks){
        die "Unknown check ($check) in $profile.\n" unless $CHECKS{$check};
        foreach my $tag (@{$CHECKS{$check}}){
            $TAGS{$tag}++;
        }
    }
    foreach my $tag (split m/\s*+,\s*+/o, $en_tag){
        die "Unknown tag ($tag) in $profile.\n" unless exists $TAGS{$tag};
        $TAGS{$tag}++;
    }

    # Check for unknown checks in the other fields
    foreach my $check (split m/\s*+,\s*+/o, $dis_checks){
        die "Unknown check in $profile.\n" unless $CHECKS{$check};
    }
    foreach my $tag (split m/\s*+,\s*+/o, $dis_tag){
        die "Unknown tag in $profile.\n" unless exists $TAGS{$tag};
    }
    # ... and other fields
    foreach my $sect (@section){
        foreach my $tag (split m/\s*+,\s*+/o, $sect->{'tags'}//''){
            die "Unknown tag ($tag) in $profile.\n" unless exists $TAGS{$tag};
        }
    }
}

sub prof_wanted {
    parse_profile($_) if -f && m/\.profile$/o;
}