summaryrefslogtreecommitdiff
path: root/bug/sanity.pl
blob: 1976d6ddd2febe88c6ac2f285c1a9fea73a49666 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#
#     Copyright (C) 2011 Loic Dachary <loic@dachary.org>
#
#     This program is free software: you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation, either version 3 of the License, or
#     (at your option) any later version.
#
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
#
#     You should have received a copy of the GNU General Public License
#     along with this program.  If not, see <http:www.gnu.org/licenses/>.
#
sub parse {
    my($query_path, $components_path) = @_;
    my($key, $value) = @_;

    open(QUERY, $query_path) or die "$query_path: $!";
    while(<QUERY>) {
        eval $_ if(s/(cpts|vers)\[(\d+)\]\s+=/\$$1\[$2\]=/);
        if(/<select\s+name="product"/../<\/select/) {
            if(/libreoffice/i) {
                $libreoffice = $count;
            }
            if(/<select\s+name="product"/) {
                $count = 0;
            } elsif(/<option/) {
                $count++;
            }
        }
    }
    close(QUERY);

    foreach (@{$cpts[$libreoffice]}) {
        $bugzilla2wiki{$_} = 0;
    }

    open(COMPONENTS, $components_path) or die "$components_path: $!";
    while(<COMPONENTS>) {
        if(/data="(.*?)"/) {
            $component = $1;
            $component =~ s/_/ /g;
            if(exists $bugzilla2wiki{$component}) {
                $bugzilla2wiki{$component}++;
            } else {
                $bugzilla2wiki{$component} = -1;
            }
        }
    }
    close(COMPONENTS);

    return \%bugzilla2wiki;
}

sub analyze {
    my($bugzilla2wiki, $query_path, $components_path) = @_;

    my($status) = 0;

    while ( my ($key, $value) = each(%$bugzilla2wiki) ) {
        if($value == -1) {
            print "component $key found in the wiki but not in the bugzilla\n";
            $status++;
        } elsif($value == 0 && ($key =~ /^\p{isUpper}/) ) {
            print "component $key found in bugzilla but not in the wiki\n";
            $status++;
	} elsif($value >= 1 && ($key =~ /^\p{isLower}/) ) {
	    print "component $key found in wiki but is a lower-case module\n";
	    $status++;
        } elsif($value > 1) {
            print "component $key found $value times in the wiki\n";
            $status++;
        }
    }
    if($status > 0) {
        print "wiki URL http://wiki.documentfoundation.org/BugReport_Details\n";
        print "components extracted with components.xsl from the wiki are in $components_path\n";
        print "bugzilla URL https://bugassistant.libreoffice.org/enter_bug.cgi?product=LibreOffice\n";
        print "bugzilla information retrieved from $query_path\n";
    }
    return $status;
}

sub tests {
    use Test::More;

    my($bugzilla2wiki) = parse('sanity-query.xhtml', 'sanity-components.xhtml');

    while ( my ($key, $value) = each(%$bugzilla2wiki) ) {
        if($key eq "BugAssistant" || $key eq "Localisation") {
            ok($value == 0, "$key $value");
        } elsif($key eq 'Localization') {
            ok($value == -1, "$key $value");
        } elsif($key eq 'Database') {
            ok($value == 2, "$key $value");
        } else {
            ok($value == 1, "$key $value");
        }
    }

    my($status) = analyze($bugzilla2wiki, 'sanity-query.xhtml', 'sanity-components.xhtml');
    ok($status == 5, "analyze $status");

    done_testing(21);
}

if($ARGV[0] eq 'TEST') {
    tests();
} else {
    exit(analyze(parse($ARGV[0], $ARGV[1]), $ARGV[0], $ARGV[1]));
}