Fix RT#53727
Tomas Doran [Wed, 10 Feb 2010 21:57:26 +0000 (21:57 +0000)]
Changes
lib/Test/NoTabs.pm
t/13-badpod.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 5618fe9..2f127ab 100644 (file)
--- a/Changes
+++ b/Changes
@@ -35,4 +35,6 @@ Revision history for Test-NoTabs
 
 1.0
      - Fix warnings with old perl versions (5.8.3) RT#54477
+     - Fix bug where malformed POD in one file would break tab-detection
+       in following files. (RT#53727)
 
index 76f555a..8c4f3dc 100644 (file)
@@ -71,7 +71,7 @@ sub notabs_ok {
     while (<$fh>) {
         $line++;
         next if (/^\s*#/);
-        next if (/^\s*=.+/ .. /^\s*=(cut|back|end)/);
+        next if (/^\s*=.+/ .. (/^\s*=(cut|back|end)/ || eof($fh)));
         last if (/^\s*(__END__|__DATA__)/);
         if ( /\t/ ) {
           $Test->ok(0, $test_txt . " on line $line");
@@ -85,7 +85,7 @@ sub notabs_ok {
 sub all_perl_files_ok {
     my @files = _all_perl_files( @_ );
     _make_plan();
-    foreach my $file ( @files ) {
+    foreach my $file ( sort @files ) {
       notabs_ok($file);
     }
 }
diff --git a/t/13-badpod.t b/t/13-badpod.t
new file mode 100644 (file)
index 0000000..09bccdf
--- /dev/null
@@ -0,0 +1,64 @@
+use strict;
+
+use Test::More qw(no_plan);
+
+use File::Temp qw( tempdir tempfile );
+
+my $perl  = $^X || 'perl';
+my $inc = join(' -I ', @INC) || '';
+$inc = "-I $inc" if $inc;
+
+# Test to check that bad Pod doesn't break subsequent files. Here the test is that 
+# both files should be detected as containing tabs, when tested one after the 
+# other. 
+
+{
+    my $dir = tempdir();
+    make_bad_pod_file($dir);
+    make_bad_tab_file($dir);
+    my (undef, $outfile) = tempfile();
+    ok( `$perl $inc -MTest::NoTabs -e "all_perl_files_ok( '$dir' )" 2>&1 > $outfile` );
+    local $/ = undef;
+    open my $fh, '<', $outfile or die $!;
+    my $content = <$fh>;
+    
+    # Filter the ok 1 line as we really don't care - it doesn't contain a tab anyway
+    $content =~ s{^ok 1[^\n]*\n}{}s;
+    
+    like( $content, qr/^not ok 2 - No tabs in '[^']*' on line 4/m, 'tabs found in tmp file 2' );
+    unlink $outfile;
+    system("rm -rf $dir");
+}
+
+sub make_bad_pod_file {
+  my ($tmpdir) = @_;
+  
+  # First file, template begins "a"
+  my ($fh, $filename) = tempfile( "a_badpod_XXXXXX", DIR => $tmpdir, SUFFIX => '.pL' );
+  print $fh <<"DUMMY";
+#!perl
+
+=head1
+
+Some unterminated Pod documentation follows, otherwise the file is OK
+
+DUMMY
+  close($fh);
+  return $filename;
+}
+sub make_bad_tab_file {
+  my ($tmpdir) = @_;
+  
+  # Second file, template begins "b"
+  my ($fh, $filename) = tempfile( "b_badtab_podtest_XXXXXX", DIR => $tmpdir, SUFFIX => '.pL' );
+  print $fh <<"DUMMY";
+#!perl
+
+sub main {
+\tprint "Hello!\n";
+}
+
+DUMMY
+  close($fh);
+}
+