MediaWiki r54922 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r54921‎ | r54922 (on ViewVC)‎ | r54923 >
Date:09:47, 13 August 2009
Author:ialex
Status:deferred
Tags:
Comment:
copy from phase3/t/main@54907
Modified paths:

Diff [purge]

Index: trunk/tools/code-utils/maint/bom.t
@@ -0,0 +1,38 @@
 2+#!/usr/bin/env perl
 3+#
 4+# This test detect Byte Order Mark (BOM). The char is sometime included at the
 5+# top of files by some text editors to mark them as being UTF-8 encoded.
 6+# They are not stripped by php 5.x and appear at the beginning of our content,
 7+# You want them removed!
 8+# See:
 9+# http://www.fileformat.info/info/unicode/char/feff/index.htm
 10+# http://bugzilla.wikimedia.org/show_bug.cgi?id=9954
 11+
 12+use strict;
 13+use warnings;
 14+
 15+use Test::More;
 16+
 17+use File::Find;
 18+
 19+# Files for wich we want to check the BOM char ( 0xFE 0XFF )
 20+my $ext = qr/(?:php|inc)/x ;
 21+
 22+my $bomchar = qr/\xef\xbb\xbf/ ;
 23+
 24+my @files;
 25+
 26+find( sub{ push @files, $File::Find::name if -f && /\.$ext$/ }, '.' );
 27+
 28+# Register our files with the test system
 29+plan tests => scalar @files ;
 30+
 31+for my $file (@files) {
 32+ open my $fh, "<", $file or die "Couln't open $file: $!";
 33+ my $line = <$fh>;
 34+ if( $line =~ /$bomchar/ ) {
 35+ fail "$file has a Byte Order Mark at line $.";
 36+ } else {
 37+ pass "$file has no Byte Order Mark!";
 38+ }
 39+}
Property changes on: trunk/tools/code-utils/maint/bom.t
___________________________________________________________________
Name: svn:eol-style
140 + native
Index: trunk/tools/code-utils/maint/eol-style.t
@@ -0,0 +1,35 @@
 2+#!/usr/bin/env perl
 3+#
 4+# Based on php-tag.t
 5+#
 6+use strict;
 7+use warnings;
 8+
 9+use Test::More;
 10+use File::Find;
 11+use IPC::Open3;
 12+use File::Spec;
 13+use Symbol qw(gensym);
 14+
 15+my $ext = qr/(?: php | inc | txt | sql | t)/x;
 16+my @files;
 17+
 18+find( sub { push @files, $File::Find::name if -f && /\. $ext $/x }, '.' );
 19+
 20+plan tests => scalar @files ;
 21+
 22+for my $file (@files) {
 23+ open NULL, '+>', File::Spec->devnull and \*NULL or die;
 24+ my $pid = open3('<&NULL', \*P, '>&NULL', qw'svn propget svn:eol-style', $file);
 25+ my $res = do { local $/; <P> . "" };
 26+ chomp $res;
 27+ waitpid $pid, 0;
 28+
 29+ if ( $? != 0 ) {
 30+ pass "svn propget failed, $file probably not under version control";
 31+ } elsif ( $res eq 'native' ) {
 32+ pass "$file svn:eol-style is 'native'";
 33+ } else {
 34+ fail "$file svn:eol-style is '$res', should be 'native'";
 35+ }
 36+}
Property changes on: trunk/tools/code-utils/maint/eol-style.t
___________________________________________________________________
Name: svn:eol-style
137 + native
Index: trunk/tools/code-utils/maint/php-tag.t
@@ -0,0 +1,29 @@
 2+#!/usr/bin/env perl
 3+use strict;
 4+use warnings;
 5+
 6+use Test::More;;
 7+
 8+use File::Find;
 9+use File::Slurp qw< slurp >;
 10+
 11+my $ext = qr/(?: php | inc )/x;
 12+
 13+my @files;
 14+find( sub { push @files, $File::Find::name if -f && /\. $ext $/x }, '.' );
 15+
 16+plan tests => scalar @files;
 17+
 18+for my $file (@files) {
 19+ my $cont = slurp $file;
 20+ if ( $cont =~ m<<\?php .* \?>>xs ) {
 21+ pass "$file has <?php ?>";
 22+ } elsif ( $cont =~ m<<\? .* \?>>xs ) {
 23+ fail "$file does not use <? ?>";
 24+ } else {
 25+ pass "$file has neither <?php ?> nor <? ?>, check it";
 26+ }
 27+}
 28+
 29+
 30+
Property changes on: trunk/tools/code-utils/maint/php-tag.t
___________________________________________________________________
Name: svn:eol-style
131 + native
Index: trunk/tools/code-utils/maint/unix-newlines.t
@@ -0,0 +1,33 @@
 2+#!/usr/bin/env perl
 3+use strict;
 4+use warnings;
 5+
 6+use Test::More;;
 7+
 8+use File::Find;
 9+use Socket '$CRLF';
 10+
 11+my $ext = qr/(?: t | pm | sql | js | php | inc | xml )/x;
 12+
 13+my @files;
 14+find( sub { push @files, $File::Find::name if -f && /\. $ext $/x }, '.' );
 15+
 16+plan 'no_plan';
 17+
 18+for my $file (@files) {
 19+ open my $fh, "<", $file or die "Can't open $file: $!";
 20+ binmode $fh;
 21+
 22+ my $ok = 1;
 23+ while (<$fh>) {
 24+ if (/$CRLF/) {
 25+ fail "$file has \\r\\n on line $.";
 26+ $ok = 0;
 27+ }
 28+ }
 29+
 30+ pass "$file has only unix newlines" if $ok;
 31+}
 32+
 33+
 34+
Property changes on: trunk/tools/code-utils/maint/unix-newlines.t
___________________________________________________________________
Name: svn:eol-style
135 + native
Index: trunk/tools/code-utils/maint/php-lint.t
@@ -0,0 +1,33 @@
 2+#!/usr/bin/env perl
 3+#
 4+# Based on php-tag.t and eol-style
 5+#
 6+use strict;
 7+use warnings;
 8+
 9+use Test::More;
 10+use File::Find;
 11+use IPC::Open3;
 12+use File::Spec;
 13+use Symbol qw(gensym);
 14+
 15+my $ext = qr/(?: php | inc )/x;
 16+my @files;
 17+
 18+find( sub { push @files, $File::Find::name if -f && /\. $ext $/x }, '.' );
 19+
 20+plan tests => scalar @files ;
 21+
 22+for my $file (@files) {
 23+ open NULL, '+>', File::Spec->devnull and \*NULL or die;
 24+ my $pid = open3('<&NULL', \*P, '>&NULL', qw'php -l', $file);
 25+ my $res = do { local $/; <P> . "" };
 26+ chomp $res;
 27+ waitpid $pid, 0;
 28+
 29+ if ( $? == 0 ) {
 30+ pass($file);
 31+ } else {
 32+ fail("$file does not pass php -l. Error was: $res");
 33+ }
 34+}
Property changes on: trunk/tools/code-utils/maint/php-lint.t
___________________________________________________________________
Name: svn:eol-style
135 + native

Status & tagging log

  • 00:20, 14 September 2011 Meno25 (talk | contribs) changed the status of r54922 [removed: old added: deferred]
  • 01:04, 14 November 2010 Reedy (talk | contribs) changed the status of r54922 [removed: new added: old]