* examples/pasm/fact.pasm:
[parrot.git] / t / codingstd / check_toxxx.t
blobc19b28cee235c5bbd9ec78da56f9962ff31a44c0
1 #! perl
2 # Copyright (C) 2006-2007, The Perl 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/check_toxxx.t - checks that the toxxx() functions are passed
15 unsigned char
17 =head1 SYNOPSIS
19     # test all files
20     % prove t/codingstd/check_toxxx.t
22     # test specific files
23     % perl t/codingstd/check_toxxx.t src/foo.c include/parrot/bar.h
25 =head1 DESCRIPTION
27 Checks all C language files to make sure that arguments to the toxxx()
28 functions are explicitly cast to unsigned char.
30 =head1 SEE ALSO
32 L<docs/pdds/pdd07_codingstd.pod>
34 =cut
36 my $DIST = Parrot::Distribution->new;
37 my @files = @ARGV ? @ARGV : $DIST->get_c_language_files();
38 my @no_explicit_cast;
39 my $toxxx_functions = "toupper|tolower";
41 foreach my $file (@files) {
43     # if we have command line arguments, the file is the full path
44     # otherwise, use the relevant Parrot:: path method
45     my $path = @ARGV ? $file : $file->path;
47     my $buf = $DIST->slurp($path);
49     my @buffer_lines = split( /\n/, $buf );
51     # find out if toxxx() functions appear in the file
52     my $num_toxxx = grep m/($toxxx_functions)\(/, @buffer_lines;
54     # if so, check if the args are cast to unsigned char
55     if ($num_toxxx) {
57         # get the lines just matching toxxx
58         my @toxxx_lines = grep m/($toxxx_functions)\(/, @buffer_lines;
60         # find the instances without the explicit cast
61         my $num_no_cast = grep !m/($toxxx_functions)\(\(unsigned char\)/, @toxxx_lines;
63         $path .= "\n";
64         push @no_explicit_cast, $path if $num_no_cast;
65     }
66     else {
67         next;
68     }
71 ok( !scalar(@no_explicit_cast), 'toxxx() functions cast correctly' )
72     or diag( "toxxx() function not cast to unsigned char "
73         . scalar @no_explicit_cast
74         . " files:\n@no_explicit_cast" );
76 # Local Variables:
77 #   mode: cperl
78 #   cperl-indent-level: 4
79 #   fill-column: 100
80 # End:
81 # vim: expandtab shiftwidth=4: