[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog devtools/testsuite/c_casts.t
From: |
Ann Barcomb |
Subject: |
[Gnash-commit] gnash ChangeLog devtools/testsuite/c_casts.t |
Date: |
Sun, 08 Apr 2007 13:51:11 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Ann Barcomb <ann> 07/04/08 13:51:10
Modified files:
. : ChangeLog
Added files:
devtools/testsuite: c_casts.t
Log message:
This test was added at Bastiaan's request. Note that it is currently
reporting the wrong line numbers due to a bug in
devtools/lib/Gnash/Utils.pm,
which could also be affecting other devtools tests.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2812&r2=1.2813
http://cvs.savannah.gnu.org/viewcvs/gnash/devtools/testsuite/c_casts.t?cvsroot=gnash&rev=1.1
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2812
retrieving revision 1.2813
diff -u -b -r1.2812 -r1.2813
--- ChangeLog 8 Apr 2007 10:16:00 -0000 1.2812
+++ ChangeLog 8 Apr 2007 13:51:10 -0000 1.2813
@@ -1,3 +1,8 @@
+2007-04-08 Ann Barcomb <address@hidden>
+
+ * devtools/testsuite/c_casts.t: added this test at Bastiaan's
+ request.
+
2007-04-08 Zou Lunkai <address@hidden>
* testsuite/misc-ming.all/get_frame_number_test.c:
Index: devtools/testsuite/c_casts.t
===================================================================
RCS file: devtools/testsuite/c_casts.t
diff -N devtools/testsuite/c_casts.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ devtools/testsuite/c_casts.t 8 Apr 2007 13:51:10 -0000 1.1
@@ -0,0 +1,112 @@
+#! perl
+
+use strict;
+use warnings;
+
+use FindBin qw/$Bin/;
+use lib $Bin.'/../lib';
+use Test::More tests => 1;
+use Gnash::Distribution;
+use Gnash::Utils qw/clean/;
+
+my $DIST = Gnash::Distribution->new;
+
+## Jerry Gay explained that this construction was needed because Windows
+## does not get @ARGV the same way as most systems.
+my @files = @ARGV
+ ? ( $^O eq 'MSwin32' ? <@ARGV> : @ARGV )
+ : $DIST->get_cpp_language_files();
+
+my @var_types = qw/int bool char long double/;
+my @failures;
+
+foreach my $path (@files) {
+ open my $fh, '<', $path
+ or die "Cannot open '$path' for reading: $!\n";
+
+ my $prefix = qq< $path line(s):>;
+ my $message = '';
+
+ ## Read in the entire file, as some of the cleaning spans lines
+ local $/ = undef;
+ my $entire_file = clean(<$fh>);
+ my @lines = split /\n/, $entire_file;
+
+ ## We need the array index to report the correct line number.
+ LINE: foreach my $i (0..$#lines) {
+ my $string = $lines[$i];
+
+ ## Look for C-style pointer for each builtin data type. This
+ ## will not check for user-defined types, but it prevents false
+ ## positives such as functions.
+ my $errmark = 0;
+ TYPE: foreach my $type (@var_types) {
+ ## Skip unless a cast of type 'int num = (int*) x;' is found.
+ $errmark = 1, last TYPE if ( $string =~ /=\s*\($type\*?\)\s*\w+/ );
+
+ ## Skip unless a cast of type 'num = int*(x);' is found
+ $errmark = 1, last TYPE if ( $string =~ /=\s*$type\*?\(\w+\)/ );
+ }
+
+ next LINE unless ($errmark);
+ $message .= " ".($i+1);
+ }
+ push @failures => "$prefix$message\n" if ($message);
+ close $fh;
+}
+
+ok( !scalar(@failures), "C-style casting" )
+ or diag("C-style casting found in ".scalar @failures."
files:address@hidden");
+
+=head1 NAME
+
+devtools/testsuite/c_casts.t - checks for C-style casts C++ source and headers
+
+=head1 SYNOPSIS
+
+ # test all files
+ % prove devtools/testsuite/c_casts.t
+
+ # test specific files
+ % perl devtools/testsuite/c_casts.t recently/modified/file
+
+=head1 DESCRIPTION
+
+This test looks for C++ source files which contain C-style casts. These
+are examples of casting using C-style:
+
+ double x;
+ int num = (int) x
+
+ double x;
+ num = int*(x)
+
+C++ casting style (shown below) provides better diagnoses of usage errors
+and are easier to identify and maintain.
+
+ double x;
+ int num = static_cast<int>(x);
+
+=head1 AUTHORS
+
+Ann Barcomb <address@hidden>, based upon ideas from the Parrot
+L<http://http://dev.perl.org/perl6/> test suite.
+
+=head1 COPYRIGHT
+
+Copyright (C) 2007 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+=cut
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog devtools/testsuite/c_casts.t,
Ann Barcomb <=