2 # Copyright (C) 2006-2009, Parrot Foundation.
8 use lib qw( . lib ../lib ../../lib );
9 use Test::More tests => 1;
10 use Parrot::Distribution;
14 t/codingstd/check_toxxx.t - checks that the toxxx() functions are passed
20 % prove t/codingstd/check_toxxx.t
23 % perl t/codingstd/check_toxxx.t src/foo.c include/parrot/bar.h
27 Checks all C language files to make sure that arguments to the toxxx()
28 functions are explicitly cast to unsigned char.
32 L<docs/pdds/pdd07_codingstd.pod>
36 my $DIST = Parrot::Distribution->new;
37 my @files = @ARGV ? <@ARGV> : $DIST->get_c_language_files();
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
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;
64 push @no_explicit_cast, $path if $num_no_cast;
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" );
78 # cperl-indent-level: 4
81 # vim: expandtab shiftwidth=4: