Ideas. Add common method for prining (gcc-style) warnings. Use new method.
[gtk-doc.git] / gtkdoc-check.in
blobd98639daac3a5c794e6a08a24865de5bb94dd290
1 #!@PERL@ -w
2 # -*- cperl -*-
4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 2007  David Nečas
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #############################################################################
23 # Script      : gtkdoc-check
24 # Description : Runs various checks on built documentation and outputs test
25 #               results. Can be run druring make check, by adding this to the
26 #               documentations Makefile.am: TESTS = $(GTKDOC_CHECK)
27 #############################################################################
29 my $DOC_MODULE;
30 my $checks = 3;
32 # We like Makefile.am more but builddir does not necessarily contain one.
33 my $makefile = (-f 'Makefile.am') ? 'Makefile.am' : 'Makefile';
34 $DOC_MODULE = &Grep('^\s*DOC_MODULE\s*=\s*(\S+)', $makefile, 'DOC_MODULE');
36 print "Running suite(s): gtk-doc-$DOC_MODULE\n";
38 my $undocumented = int &Grep('^(\d+)\s+not\s+documented\.\s*$',
39                              "$DOC_MODULE-undocumented.txt",
40                              'number of undocumented symbols');
41 my $incomplete = int &Grep('^(\d+)\s+symbols?\s+incomplete\.\s*$',
42                            "$DOC_MODULE-undocumented.txt",
43                            'number of incomplete symbols');
44 my $total = $undocumented + $incomplete;
45 if ($total) {
46     print "$DOC_MODULE-undocumented.txt:1:E: $total undocumented or incomplete symbols\n";
49 my $undeclared = &CheckEmpty("$DOC_MODULE-undeclared.txt",
50                              'undeclared symbols');
51 my $unused = &CheckEmpty("$DOC_MODULE-unused.txt",
52                          'unused documentation entries');
54 my $failed = ($total > 0) + ($undeclared != 0) + ($unused != 0);
55 my $rate = 100.0*($checks - $failed)/$checks;
56 printf '%.1f%%: Checks %d, Failures: %d%s', $rate, $checks, $failed, "\n";
57 exit ($failed != 0);
59 sub Grep() {
60     my ($regexp, $filename, $what) = @_;
61     my $retval;
63     if (not open GFILE, "<$filename") {
64         die "Cannot open $filename: $!\n";
65     }
66     while (<GFILE>) {
67         next if not m/$regexp/;
68         $retval = $1;
69         last;
70     }
71     close GFILE;
72     if (not defined $retval) {
73         die "Cannot find $what in $filename\n";
74     }
75     return $retval;
78 sub CheckEmpty() {
79     my ($filename, $what) = @_;
80     my $count = 0;
82     if (not open GFILE, "<$filename") {
83         return $count;
84     }
85     while (<GFILE>) {
86         if (m/\S/) {
87             $count++
88         }
89     }
90     close GFILE;
91     if ($count) {
92         print "$filename:1:E: $count $what\n"
93     }
94     return $count;