1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
use strict;
use warnings;
BEGIN {
use Test::More;
use File::Find;
# Are we an author test?
plan skip_all => 'Skipping author tests'
unless $ENV{RUN_AUTHOR_TESTS};
}
my @files;
find({
wanted => \&process,
follow => 0
}, '.');
sub process
{
my $file = $_;
return if $File::Find::dir =~m/\.svn/;
return if $File::Find::dir =~m/archive/;
push @files, $File::Find::name
if $file =~m/\.yml$|\.pm$|\.pod$|\.tt$|\.txt$|\.js$|\.css$|\.sql$|\.html$/;
}
my $CR = "\015"; # Apple II family, Mac OS thru version 9
my $CRLF = "\015\012"; # CP/M, MP/M, DOS, Microsoft Windows
my $FF = "\014"; # printer form feed
my $LF = "\012"; # Unix, Linux, Xenix, Mac OS X, BeOS, Amiga
my $test_builder = Test::More->builder;
if( $#files )
{
$test_builder->plan(tests => ($#files+1)*2);
foreach my $file (@files)
{
## Get a good filehandle
open( my $fh, '<', $file)
or fail "Can't open $file, can't finish testing";
## Only need to test the first line.
my ($first, $second) = <$fh>;
## Don't need this anymore
close($fh);
SKIP: {
skip "$file is Empty!", 2 unless $first;
## Are we DOS or MACOS/APPLE?
ok $first!~m/$CRLF$|$CR$|$FF$/, "$file isn't in a forbidden format";
## If there is more than one line, we HAVE to be UNIX
SKIP: {
skip "$file only has a single line", 1 unless $second;
ok $first=~m/$LF$/, "$file Is unix linefeed";
}
}
}
}
else
{
$test_builder->plan(skip_all => 'No Text Files Found! (This is probably BIG Trouble...');
}
1;
|