7
use lib $Bin.'/../lib';
8
use Test::More tests => 1;
9
use Gnash::Distribution;
10
use Gnash::Utils qw/clean/;
12
my $DIST = Gnash::Distribution->new;
14
## Jerry Gay explained that this construction was needed because Windows
15
## does not get @ARGV the same way as most systems.
17
? ( $^O eq 'MSwin32' ? <@ARGV> : @ARGV )
18
: $DIST->get_cpp_language_files();
20
my @var_types = qw/int bool char long double/;
23
foreach my $path (@files) {
24
open my $fh, '<', $path
25
or die "Cannot open '$path' for reading: $!\n";
27
my $prefix = qq< $path line(s):>;
30
## Read in the entire file, as some of the cleaning spans lines
32
my $entire_file = clean(<$fh>);
33
my @lines = split /\n/, $entire_file;
35
## We need the array index to report the correct line number.
36
LINE: foreach my $i (0..$#lines) {
37
my $string = $lines[$i];
39
## Look for C-style pointer for each builtin data type. This
40
## will not check for user-defined types, but it prevents false
41
## positives such as functions.
43
TYPE: foreach my $type (@var_types) {
44
## Skip unless a cast of type 'int num = (int*) x;' is found.
45
$errmark = 1, last TYPE if ( $string =~ /=\s*\($type\*?\)\s*\w+/ );
47
## Skip unless a cast of type 'num = int*(x);' is found
48
$errmark = 1, last TYPE if ( $string =~ /=\s*$type\*?\(\w+\)/ );
51
next LINE unless ($errmark);
52
$message .= " ".($i+1);
54
push @failures => "$prefix$message\n" if ($message);
58
ok( !scalar(@failures), "C-style casting" )
59
or diag("C-style casting found in ".scalar @failures." files:\n@failures");
63
devtools/testsuite/c_casts.t - checks for C-style casts C++ source and headers
68
% prove devtools/testsuite/c_casts.t
71
% perl devtools/testsuite/c_casts.t recently/modified/file
75
This test looks for C++ source files which contain C-style casts. These
76
are examples of casting using C-style:
84
C++ casting style (shown below) provides better diagnoses of usage errors
85
and are easier to identify and maintain.
88
int num = static_cast<int>(x);
92
Ann Barcomb <kudra@domaintje.com>, based upon ideas from the Parrot
93
L<http://http://dev.perl.org/perl6/> test suite.
97
Copyright (C) 2007 Free Software Foundation, Inc.
99
This program is free software; you can redistribute it and/or modify
100
it under the terms of the GNU General Public License as published by
101
the Free Software Foundation; either version 3 of the License, or
102
(at your option) any later version.
104
This program is distributed in the hope that it will be useful,
105
but WITHOUT ANY WARRANTY; without even the implied warranty of
106
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
107
GNU General Public License for more details.
108
You should have received a copy of the GNU General Public License
109
along with this program; if not, write to the Free Software
110
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA