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/pmc_docs.t - checks for missing function documentation
21 % prove t/codingstd/pmc_docs.t
24 % perl t/codingstd/pmc_docs.t src/foo.pmc src/bar.pmc
28 Checks that all PMC source files have documentation for each function
33 my $DIST = Parrot::Distribution->new;
34 my $headerizer = Parrot::Headerizer->new;
36 my @files = @ARGV ? @ARGV :
37 map {s/^$PConfig{build_dir}\///; $_}
39 map {$_->path} $DIST->pmc_source_files();
41 plan tests => scalar @files;
53 # Traverse each file, analyzing each function declaration therein, then
54 # post results in %all_files.
56 foreach my $path (@files) {
57 my $buf = $DIST->slurp($path);
58 my @function_decls = $headerizer->extract_function_declarations($buf);
60 # We start out asserting that every file will have documentation for each
61 # of its function declarations. We then seek to contradict this
64 my %this_file = ( overall => 1 );
66 for my $function_decl (@function_decls) {
68 = $headerizer->generate_documentation_signature($function_decl);
69 $this_file{$function_decl}{esc} = $escaped_decl;
71 if ( $buf =~ m/^\Q$escaped_decl\E$(.*?)^=cut/sm ) {
74 if ($docs eq '') { # boilerplate only
75 $this_file{$function_decl}{status} = 0;
76 $this_file{overall} = 0;
78 else { # documentation found
79 $this_file{$function_decl}{status} = 1;
82 else { # no documentation found
83 $this_file{$function_decl}{status} = undef;
84 $this_file{overall} = 0;
87 $all_files{$path} = \%this_file;
90 foreach my $path (sort keys %all_files) {
92 local $TODO = 'Missing function docs' if $todos{$path};
93 ok( $all_files{$path}{overall}, $path )
94 or diag( diagnosis( \%all_files, $path ) );
99 my ($all_files_ref, $path) = @_;
101 my $boilerplate = '';
102 my %this_file = %{ $all_files_ref->{$path} };
103 delete $this_file{overall};
104 foreach my $decl ( sort keys %this_file ) {
105 if ( ! defined $this_file{$decl}{status} ) {
106 $missing .= "$decl\n";
107 $missing .= "Need:\n";
108 $missing .= "$this_file{$decl}{esc}\n\n";
110 elsif ( ! $this_file{$decl}{status} ) {
111 $boilerplate .= "$this_file{$decl}{esc}\n\n";
117 my $diagnosis = "$path\n";
118 $diagnosis .= "Undocumented functions:\n\n$missing" if $missing;
119 $diagnosis .= "Boilerplate only:\n$boilerplate" if $boilerplate;
125 src/pmc/callcontext.pmc
128 src/pmc/coroutine.pmc
131 src/pmc/namespace.pmc
135 src/pmc/threadinterpreter.pmc
136 src/pmc/unmanagedstruct.pmc
140 # cperl-indent-level: 4
143 # vim: expandtab shiftwidth=4: