Updated Spanish translation
[gtk-doc.git] / gtkdoc-check.in
blob560d69b90383bfd1321f0c2f92cf5123bafb98db
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 $checks = 4;
56 # Get parameters from test env, if not there try to grab them from the makefile
57 # We like Makefile.am more but builddir does not necessarily contain one.
58 my $makefile = (-f 'Makefile.am') ? 'Makefile.am' : 'Makefile';
60 # For historic reasons tests are launched in srcdir
61 my $SRCDIR = $ENV{"SRCDIR"};
62 my $BUILDDIR = $ENV{"BUILDDIR"};
63 my $dir = ".";
64 if (defined($BUILDDIR) and $BUILDDIR ne "") {
65     $dir=$BUILDDIR;
68 # debug
69 #for my $key (sort(keys(%ENV))) { print "$key = ", $ENV{$key}, "\n"; }
70 # debug
72 my $DOC_MODULE = $ENV{"DOC_MODULE"};
73 if (!defined($DOC_MODULE) or $DOC_MODULE eq "") {
74     $DOC_MODULE = &Grep('^\s*DOC_MODULE\s*=\s*(\S+)', $makefile, 'DOC_MODULE');
76 my $DOC_MAIN_SGML_FILE = $ENV{"DOC_MAIN_SGML_FILE"};
77 if (!defined($DOC_MAIN_SGML_FILE) or $DOC_MAIN_SGML_FILE eq "") {
78     $DOC_MAIN_SGML_FILE = &Grep('^\s*DOC_MAIN_SGML_FILE\s*=\s*(\S+)', $makefile, 'DOC_MAIN_SGML_FILE');
79     $DOC_MAIN_SGML_FILE =~ s/\$\(DOC_MODULE\)/$DOC_MODULE/;
82 print "Running suite(s): gtk-doc-$DOC_MODULE\n";
84 my $undocumented = int &Grep('^(\d+)\s+not\s+documented\.\s*$',
85                              "$dir/$DOC_MODULE-undocumented.txt",
86                              'number of undocumented symbols');
87 my $incomplete = int &Grep('^(\d+)\s+symbols?\s+incomplete\.\s*$',
88                            "$dir/$DOC_MODULE-undocumented.txt",
89                            'number of incomplete symbols');
90 my $total = $undocumented + $incomplete;
91 if ($total) {
92     print "$DOC_MODULE-undocumented.txt:1:E: $total undocumented or incomplete symbols\n";
95 my $undeclared = &CheckEmpty("$dir/$DOC_MODULE-undeclared.txt",
96                              'undeclared symbols');
97 my $unused = &CheckEmpty("$dir/$DOC_MODULE-unused.txt",
98                          'unused documentation entries');
100 my $missing_includes = &CheckIncludes ("$dir/$DOC_MAIN_SGML_FILE");
102 my $failed = ($total > 0) + ($undeclared != 0) + ($unused != 0) + ($missing_includes != 0);
103 my $rate = 100.0*($checks - $failed)/$checks;
104 printf "%.1f%%: Checks %d, Failures: %d\n", $rate, $checks, $failed;
105 exit ($failed != 0);
107 sub Grep() {
108     my ($regexp, $filename, $what) = @_;
109     my $retval;
111     if (not open GFILE, "<$filename") {
112         die "Cannot open $filename: $!\n";
113     }
114     while (<GFILE>) {
115         next if not m/$regexp/;
116         $retval = $1;
117         last;
118     }
119     close GFILE;
120     if (not defined $retval) {
121         die "Cannot find $what in $filename\n";
122     }
123     return $retval;
126 sub CheckEmpty() {
127     my ($filename, $what) = @_;
128     my $count = 0;
130     if (not open GFILE, "<$filename") {
131         return $count;
132     }
133     while (<GFILE>) {
134         if (m/\S/) {
135             $count++
136         }
137     }
138     close GFILE;
139     if ($count) {
140         print "$filename:1:E: $count $what\n"
141     }
142     return $count;
145 sub CheckIncludes() {
146     my ($main_sgml_file) = @_;
148     if (not open GFILE, "<$main_sgml_file") {
149         die "Cannot open $main_sgml_file: $!\n";
150     }
152     # Check that each of the XML files in the xml directory are included in $DOC_MAIN_SGML_FILE
153     my @xml_files = <xml/*.xml>;
154     my $num_missing = 0;
156     foreach my $xml_file (@xml_files) {
157         my $regex = quotemeta ($xml_file);
158         my $found = 0;
160         while (<GFILE>) {
161             next if not m/"$regex"/;
162             $found = 1;
163             last;
164         }
166         if (!$found) {
167             $num_missing++;
168             print "$main_sgml_file doesn't appear to include \"$xml_file\"\n";
169         }
171         seek (GFILE, 0, 0);
172     }
174     close (GFILE);
176     return $num_missing;