add and change NEWS for 2.8.0 release
[parrot.git] / t / codingstd / check_isxxx.t
blobd8612203eb0cfb8272da84d67d94ec6ac16867ed
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;
11 use Parrot::Test::Util::Runloop;
13 =head1 NAME
15 t/codingstd/check_isxxx.t - checks that the isxxx() functions are passed
16 unsigned char
18 =head1 SYNOPSIS
20     # test all files
21     % prove t/codingstd/check_isxxx.t
23     # test specific files
24     % perl t/codingstd/check_isxxx.t src/foo.c include/parrot/bar.h
26 =head1 DESCRIPTION
28 Checks all C language files to make sure that arguments to the isxxx()
29 functions are explicitly cast to unsigned char.
31 =head1 SEE ALSO
33 L<docs/pdds/pdd07_codingstd.pod>
35 =cut
37 my $DIST  = Parrot::Distribution->new;
38 my @files = @ARGV ? <@ARGV> : $DIST->get_c_language_files();
40 my @no_explicit_cast;
42 my @isxxx_functions_list = qw(
43     isalnum
44     isalpha
45     isblank
46     iscntrl
47     isdigit
48     isgraph
49     islower
50     isprint
51     ispunct
52     isspace
53     isupper
56 my $isxxx_functions = join '|', @isxxx_functions_list;
58 sub check_isxxx {
59     my $line = shift;
61     # does the line contain an isxxx call?
62     return 1 unless $line =~ /[^_]($isxxx_functions)\([^)]+/;
63     # is the line missing a cast?
64     return 1 unless $line !~ /[^_]($isxxx_functions)\(\(unsigned char\)/;
65     # yes!  fail.
66     return 0;
69 Parrot::Test::Util::Runloop->testloop(
70     name     => 'isxxx() functions cast correctly',
71     files    => [@files],
72     per_line => \&check_isxxx,
73     diag_prefix => 'isxxx() function not cast to unsigned char'
76 # Local Variables:
77 #   mode: cperl
78 #   cperl-indent-level: 4
79 #   fill-column: 100
80 # End:
81 # vim: expandtab shiftwidth=4: