From fdb35a6344fc7c623305e4e675f396e98a1b900e Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Sun, 14 Jul 2013 18:58:58 +0200 Subject: [PATCH] Move file parsing code from t/lib/common.pl to t/test.pl 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 | 37 +------------------------------------ t/test.pl | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/t/lib/common.pl b/t/lib/common.pl index 97aeace..4ab00b1 100644 --- a/t/lib/common.pl +++ b/t/lib/common.pl @@ -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; diff --git a/t/test.pl b/t/test.pl index e141b91..39c083d 100644 --- 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; -- 2.7.4