Add a long annotated parameter description (regression test for #613611)
[gtk-doc.git] / gtkdoc-check.in
blobc4e03e87a1e736daac883e2fbd7bda0c896f6130
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 use strict;
30 use Getopt::Long;
32 my $PRINT_VERSION;
33 my $PRINT_HELP;
35 my %optctl = ('version' => \$PRINT_VERSION,
36               'help' => \$PRINT_HELP);
37 GetOptions(\%optctl, "version", "help");
39 if ($PRINT_VERSION) {
40     print "@VERSION@\n";
41     exit 0;
44 if ($PRINT_HELP) {
45     print <<EOF;
46 gtkdoc-check version @VERSION@ - run documentation unit tests
48 --version               Print the version of this program
49 --help                  Print this help
50 EOF
51     exit 0;
54 my $DOC_MODULE;
55 my $checks = 3;
57 # We like Makefile.am more but builddir does not necessarily contain one.
58 my $makefile = (-f 'Makefile.am') ? 'Makefile.am' : 'Makefile';
59 $DOC_MODULE = &Grep('^\s*DOC_MODULE\s*=\s*(\S+)', $makefile, 'DOC_MODULE');
61 print "Running suite(s): gtk-doc-$DOC_MODULE\n";
63 my $undocumented = int &Grep('^(\d+)\s+not\s+documented\.\s*$',
64                              "$DOC_MODULE-undocumented.txt",
65                              'number of undocumented symbols');
66 my $incomplete = int &Grep('^(\d+)\s+symbols?\s+incomplete\.\s*$',
67                            "$DOC_MODULE-undocumented.txt",
68                            'number of incomplete symbols');
69 my $total = $undocumented + $incomplete;
70 if ($total) {
71     print "$DOC_MODULE-undocumented.txt:1:E: $total undocumented or incomplete symbols\n";
74 my $undeclared = &CheckEmpty("$DOC_MODULE-undeclared.txt",
75                              'undeclared symbols');
76 my $unused = &CheckEmpty("$DOC_MODULE-unused.txt",
77                          'unused documentation entries');
79 my $failed = ($total > 0) + ($undeclared != 0) + ($unused != 0);
80 my $rate = 100.0*($checks - $failed)/$checks;
81 printf "%.1f%%: Checks %d, Failures: %d\n", $rate, $checks, $failed;
82 exit ($failed != 0);
84 sub Grep() {
85     my ($regexp, $filename, $what) = @_;
86     my $retval;
88     if (not open GFILE, "<$filename") {
89         die "Cannot open $filename: $!\n";
90     }
91     while (<GFILE>) {
92         next if not m/$regexp/;
93         $retval = $1;
94         last;
95     }
96     close GFILE;
97     if (not defined $retval) {
98         die "Cannot find $what in $filename\n";
99     }
100     return $retval;
103 sub CheckEmpty() {
104     my ($filename, $what) = @_;
105     my $count = 0;
107     if (not open GFILE, "<$filename") {
108         return $count;
109     }
110     while (<GFILE>) {
111         if (m/\S/) {
112             $count++
113         }
114     }
115     close GFILE;
116     if ($count) {
117         print "$filename:1:E: $count $what\n"
118     }
119     return $count;