]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - t/maint/bom.t
MediaWiki 1.11.0
[autoinstallsdev/mediawiki.git] / t / maint / bom.t
1 #!/usr/bin/env perl
2 #
3 # This test detect Byte Order Mark (BOM). The char is sometime included at the
4 # top of files by some text editors to mark them as being UTF-8 encoded.
5 # They are not stripped by php 5.x and appear at the beginning of our content,
6 # You want them removed!
7 # See:
8 #   http://www.fileformat.info/info/unicode/char/feff/index.htm
9 #   http://bugzilla.wikimedia.org/show_bug.cgi?id=9954
10
11 use strict;
12 use warnings;
13
14 use Test::More;
15
16 use File::Find;
17
18 # Files for wich we want to check the BOM char ( 0xFE 0XFF )
19 my $ext = qr/(?:php|inc)/x ;
20
21 my $bomchar = qr/\xef\xbb\xbf/ ;
22
23 my @files;
24
25 find( sub{ push @files, $File::Find::name if -f && /\.$ext$/ }, '.' );
26
27 # Register our files with the test system
28 plan tests => scalar @files ;
29
30 for my $file (@files) {
31     open my $fh, "<", $file or die "Couln't open $file: $!";
32     my $line = <$fh>;
33         if( $line =~ /$bomchar/ ) {
34                 fail "$file has a Byte Order Mark at line $.";
35         } else {
36                 pass "$file has no Byte Order Mark!";
37         }
38 }