Move file parsing code from t/lib/common.pl to t/test.pl
authorNicholas Clark <nick@ccl4.org>
Sun, 14 Jul 2013 16:58:58 +0000 (18:58 +0200)
committerNicholas Clark <nick@ccl4.org>
Mon, 22 Jul 2013 08:04:48 +0000 (10:04 +0200)
Move the code that prepares input to run_multiple_progs() by parsing files
into a subroutine setup_multiple_progs(). This will enable the parsing code
in run_multiple_progs() to be merged, and the combined code to be altered to
give improved diagnostics on test failure.

t/lib/common.pl
t/test.pl

index 97aeace..4ab00b1 100644 (file)
@@ -30,42 +30,7 @@ if (@ARGV) {
     @w_files = sort glob catfile(curdir(), "lib", $pragma_name, "*");
 }
 
-my $tests;
-my @prgs;
-foreach my $file (@w_files) {
-    next if $file =~ /(?:~|\.orig|,v)$/;
-    next if $file =~ /perlio$/ && !PerlIO::Layer->find('perlio');
-    next if -d $file;
-
-    open my $fh, '<', $file or die "Cannot open $file: $!\n" ;
-    my $found;
-    while (<$fh>) {
-        if (/^__END__/) {
-            ++$found;
-            last;
-        }
-    }
-    # This is an internal error, and should never happen. All bar one of the
-    # files had an __END__ marker to signal the end of their preamble, although
-    # for some it wasn't technically necessary as they have no tests.
-    # It might be possible to process files without an __END__ by seeking back
-    # to the start and treating the whole file as tests, but it's simpler and
-    # more reliable just to make the rule that all files must have __END__ in.
-    # This should never fail - a file without an __END__ should not have been
-    # checked in, because the regression tests would not have passed.
-    die "Could not find '__END__' in $file"
-        unless $found;
-
-    {
-        local $/ = undef;
-        my @these = split "\n########\n", <$fh>;
-        $tests += @these;
-        push @prgs, $file, @these;
-    }
-
-    close $fh
-        or die "Cannot close $file: $!\n";
-}
+my ($tests, @prgs) = setup_multiple_progs(@w_files);
 
 $^X = rel2abs($^X);
 @INC = map { rel2abs($_) } @INC;
index e141b91..39c083d 100644 (file)
--- a/t/test.pl
+++ b/t/test.pl
@@ -969,6 +969,46 @@ sub fresh_perl_like {
 # If the global variable $FATAL is true then OPTION fatal is the
 # default.
 
+sub setup_multiple_progs {
+    my ($tests, @prgs);
+    foreach my $file (@_) {
+        next if $file =~ /(?:~|\.orig|,v)$/;
+        next if $file =~ /perlio$/ && !PerlIO::Layer->find('perlio');
+        next if -d $file;
+
+        open my $fh, '<', $file or die "Cannot open $file: $!\n" ;
+        my $found;
+        while (<$fh>) {
+            if (/^__END__/) {
+                ++$found;
+                last;
+            }
+        }
+        # This is an internal error, and should never happen. All bar one of
+        # the files had an __END__ marker to signal the end of their preamble,
+        # although for some it wasn't technically necessary as they have no
+        # tests. It might be possible to process files without an __END__ by
+        # seeking back to the start and treating the whole file as tests, but
+        # it's simpler and more reliable just to make the rule that all files
+        # must have __END__ in. This should never fail - a file without an
+        # __END__ should not have been checked in, because the regression tests
+        # would not have passed.
+        die "Could not find '__END__' in $file"
+            unless $found;
+
+        {
+            local $/ = undef;
+            my @these = split "\n########\n", <$fh>;
+            $tests += @these;
+            push @prgs, $file, @these;
+        }
+
+        close $fh
+            or die "Cannot close $file: $!\n";
+    }
+    return ($tests, @prgs);
+}
+
 sub run_multiple_progs {
     my $up = shift;
     my @prgs;