3 use Test::More qw(no_plan);
5 use File::Temp qw( tempdir tempfile );
6 my $perl = $^X || 'perl';
7 my $inc = join(' -I ', map { qq{"$_"} } @INC) || '';
8 $inc = "-I $inc" if $inc;
11 my ( $dir, $filename ) = make_raw_badfile();
13 open my $fh, '<', $filename or die $!;
14 binmode( $fh, ':raw' );
16 is( $content, ascii_string(), 'Data written to file is there when we look for it later' );
20 my $dir = make_bad_file_1();
21 run_ok( "all_perl_files_ok( '$dir' )",
22 qr/^not ok 1 - No incorrect line endings in '[^']*' \Qon line 5: [\r]/m,
23 'windows EOL found in tmp file 1' );
26 my $dir = make_bad_file_2();
27 run_ok( "all_perl_files_ok( '$dir' )",
28 qr/^not ok 1 - No incorrect line endings in '[^']*' \Qon line 8: [\r][\r][\r][\r][\r][\r][\r]/m,
29 'windows EOL found in tmp file2 ' );
32 my ($dir, $file) = make_bad_file_3();
33 run_ok( "all_perl_files_ok( '$file' )",
34 qr/^not ok 1 - No incorrect line endings in '[^']*' \Qon line 9: [\r][\r][\r]/m,
35 'windows EOL found in tmp file 3' );
39 my $dir = make_bad_file_4();
40 run_ok( "all_perl_files_ok({trailing_whitespace => 1}, '$dir' )",
41 # Note that line number will be 13
42 qr/^not ok 1 - No incorrect line endings in '[^']*' \Qon line 12: [\s][\t][\s][\s]/m,
43 'Trailing ws EOL found in tmp file 4' );
47 my ($code, $match, $test_name) = @_;
48 my $line = (caller)[2];
49 die "code containing double quotes is not portable on Win32 in one-liners" if $code =~ /"/;
50 my (undef, $outfile) = tempfile();
51 is( `$perl $inc -MTest::EOL -e "$code" > $outfile 2>&1`, '', "test sub program at line $line: output redirected" );
52 is( $? >> 8, 1, "test sub program at line $line: exit code is 1" );
54 open my $fh, '<', $outfile or die $!;
56 like( $content, $match, $test_name );
61 my $o = "<before \r\n between \r\n after \n normal >";
65 sub make_raw_badfile {
66 my $tmpdir = tempdir( CLEANUP => 1 );
67 my ( $fh, $filename ) = tempfile( DIR => $tmpdir, SUFFIX => '.tXt' );
69 print $fh ascii_string();
71 return ( $tmpdir, $filename );
76 my $tmpdir = tempdir( CLEANUP => 1 );
77 my ($fh, $filename) = tempfile( DIR => $tmpdir, SUFFIX => '.pL' );
83 # Note that the generated file will have the CRLF expanded in the source
93 my $tmpdir = tempdir( CLEANUP => 1 );
94 my ($fh, $filename) = tempfile( DIR => $tmpdir, SUFFIX => '.pL' );
103 test.pL - A test script
114 sub make_bad_file_3 {
115 my $tmpdir = tempdir( CLEANUP => 1 );
116 my ($fh, $filename) = tempfile( DIR => $tmpdir, SUFFIX => '.pm' );
124 my (\$class) = \@_;\r
125 my \$self = bless { }, \$class;\r
133 return ($tmpdir, $filename);
136 sub make_bad_file_4 {
137 my $tmpdir = tempdir( CLEANUP => 1 );
138 my ($fh, $filename) = tempfile( DIR => $tmpdir, SUFFIX => '.pL' );
147 test.pL - A test script
154 print $fh qq{ print "Hello!\\n"; \t \n}; # <-- whitespace