2 # Copyright (C) 2006-2010, Parrot Foundation.
8 use lib qw( . lib ../lib ../../lib );
10 use Parrot::Config qw(%PConfig);
11 use Parrot::Distribution;
12 use Parrot::Headerizer;
16 t/codingstd/c_function_docs.t - checks for missing function documentation
21 % prove t/codingstd/c_function_docs.t
24 % perl t/codingstd/c_function_docs.t src/foo.c include/parrot/bar.h
28 Checks that all C language source files have documentation for each function
33 my $DIST = Parrot::Distribution->new;
34 my $headerizer = Parrot::Headerizer->new;
36 # can not handle .ops or .pmc files yet
37 my @files = grep {/\.(c|h)$/ } @ARGV ? @ARGV :
38 map {s/^$PConfig{build_dir}\///; $_} map {s/\\/\//g; $_} map {$_->path} $DIST->get_c_language_files();
40 plan tests => scalar @files;
50 foreach my $path (@files) {
52 my $buf = $DIST->slurp($path);
55 my @function_decls = $headerizer->extract_function_declarations($buf);
57 for my $function_decl (@function_decls) {
59 my $escaped_decl = $headerizer->generate_documentation_signature($function_decl);
62 if ( $buf =~ m/^\Q$escaped_decl\E$(.*?)^=cut/sm ) {
66 $missing = 'boilerplate only';
74 if ($missing eq 'boilerplate only') {
75 push @missing_docs, "$path ($missing)\nIn:\n$escaped_decl\n";
78 push @missing_docs, "$path ($missing)\n$function_decl\nWant:\n$escaped_decl\n";
84 local $TODO = 'Missing function docs' if $todos{$path};
86 ok ( ! @missing_docs, $path)
87 or diag( @missing_docs
88 . " function(s) lacking documentation:\n"
89 . join ("\n", @missing_docs, "\n"));
97 # cperl-indent-level: 4
100 # vim: expandtab shiftwidth=4: