13 t/newlines.t - test to make sure all text files are in unix linefeed format
17 Descends through the distribution directory and verifies that all text files
18 (files with an extention matching a pattern, such as *.txt) are in unix
23 This module defines the following tests.
25 =head2 Descend Distribution
27 Starting at the Distribution root, look at all files in all subdirections and
28 if the file matches a text type (according to a particular regex for it's
29 extension) add it to a files of files to test.
44 return if $File::Find::dir =~m/\.svn/;
45 return if $File::Find::dir =~m/archive/;
47 push @files, $File::Find::name
48 if $file =~m/\.yml$|\.pm$|\.pod$|\.tt$|\.txt$|\.js$|\.css$|\.sql$|\.html$/;
52 =head2 test linefeedtype
54 Check if the generated files are correctly unix linefeeds
58 my $CR = "\015"; # Apple II family, Mac OS thru version 9
59 my $CRLF = "\015\012"; # CP/M, MP/M, DOS, Microsoft Windows
60 my $FF = "\014"; # printer form feed
61 my $LF = "\012"; # Unix, Linux, Xenix, Mac OS X, BeOS, Amiga
63 my $test_builder = Test::More->builder;
67 $test_builder->plan(tests => ($#files+1)*2);
69 foreach my $file (@files)
71 ## Get a good filehandle
72 open( my $fh, '<', $file)
73 or fail "Can't open $file, can't finish testing";
75 ## Only need to test the first line.
76 my ($first, $second) = <$fh>;
78 ## Don't need this anymore
83 skip "$file is Empty!", 2 unless $first;
85 ## Are we DOS or MACOS/APPLE?
86 ok $first!~m/$CRLF$|$CR$|$FF$/, "$file isn't in a forbidden format";
88 ## If there is more than one line, we HAVE to be UNIX
92 skip "$file only has a single line", 1 unless $second;
93 ok $first=~m/$LF$/, "$file Is unix linefeed";
100 $test_builder->plan(skip_all => 'No Text Files Found! (This is probably BIG Trouble...');
105 John Napiorkowski, C<< <jjn1056 at yahoo.com> >>
107 =head1 COPYRIGHT & LICENSE
109 Copyright 2008 John Napiorkowski.
111 This program is free software; you can redistribute it and/or modify it
112 under the same terms as Perl itself.