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