add generated_hello.pbc to examples-clean
[parrot.git] / t / codingstd / c_returns.t
blob0f4d6f630284aafd39b0a8210d34350270742e9a
1 #! perl
2 # Copyright (C) 2006-2009, Parrot Foundation.
3 # $Id$
5 use strict;
6 use warnings;
8 use lib qw( . lib ../lib ../../lib );
9 use Test::More tests => 1;
10 use Parrot::Distribution;
12 =head1 NAME
14 t/codingstd/c_returns.t - checks for possible use of C<return (foo);> from functions
16 =head1 SYNOPSIS
18     # test all files
19     % prove t/codingstd/c_returns.t
21     # test specific files
22     % perl t/codingstd/c_returns.t src/foo.c include/parrot/bar.h
24 =head1 DESCRIPTION
26 Checks that all C language source files return using C<return foo;> rather
27 than C<return (foo);>
29 =head1 NOTES
31 This test was hacked from the C<check_returns> sub in
32 C<tools/dev/check_source_standards.pl>, which is no longer part of the Parrot
33 distribution.
35 =head1 SEE ALSO
37 L<docs/pdds/pdd07_codingstd.pod>
39 =cut
41 my $DIST = Parrot::Distribution->new;
42 my @files = @ARGV ? <@ARGV> : $DIST->get_c_language_files();
43 my @paren_return;
45 foreach my $file (@files) {
46     my $path;
48     ## get the full path of the file
49     # if we have command line arguments, the file is the full path
50     if (@ARGV) {
51         $path = $file;
52     }
54     # otherwise, use the relevant Parrot:: path method
55     else {
56         $path = $file->path;
57     }
59     my $buf = $DIST->slurp($path);
61     # look for instances of return(
62     push @paren_return => "$path\n"
63         if ( $buf =~ m/[^_.]return\(/ );
66 ok( !scalar(@paren_return), 'Correctly formed return statement' )
67     or diag( "Possible use of C<return(foo);> rather than C<return foo;> in "
68         . scalar @paren_return
69         . " files:\n@paren_return" );
71 # Local Variables:
72 #   mode: cperl
73 #   cperl-indent-level: 4
74 #   fill-column: 100
75 # End:
76 # vim: expandtab shiftwidth=4: