This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
podcheck.t: Guard against weird input file types
[perl5.git] / t / lib / common.pl
CommitLineData
6fc551a0
NC
1# This code is used by lib/charnames.t, lib/feature.t, lib/subs.t,
2# lib/strict.t and lib/warnings.t
3d243db0
KW
3#
4# On input, $::local_tests is the number of tests in the caller; or
5# 'no_plan' if unknown, in which case it is the caller's responsibility
6# to call cur_test() to find out how many this executed
25ae1130
RGS
7
8BEGIN {
25ae1130
RGS
9 require './test.pl';
10}
11
afb1190b 12use Config;
ebf2da99 13use File::Path;
11ce4a76 14use File::Spec::Functions qw(catfile curdir rel2abs);
25ae1130
RGS
15
16use strict;
742dc32d 17use warnings;
a80e93c2
NC
18my (undef, $file) = caller;
19my ($pragma_name) = $file =~ /([A-Za-z_0-9]+)\.t$/
20 or die "Can't identify pragama to test from file name '$file'";
25ae1130
RGS
21
22$| = 1;
23
25ae1130
RGS
24my @prgs = () ;
25my @w_files = () ;
26
27if (@ARGV)
28 { print "ARGV = [@ARGV]\n" ;
25ae1130 29 @w_files = map { s#^#./lib/$pragma_name/#; $_ } @ARGV
25ae1130
RGS
30 }
31else
32 { @w_files = sort glob(catfile(curdir(), "lib", $pragma_name, "*")) }
33
34my $files = 0;
35foreach my $file (@w_files) {
36
37 next if $file =~ /(~|\.orig|,v)$/;
38 next if $file =~ /perlio$/ && !(find PerlIO::Layer 'perlio');
39 next if -d $file;
40
8606a93d 41 open my $fh, '<', $file or die "Cannot open $file: $!\n" ;
25ae1130 42 my $line = 0;
8606a93d 43 while (<$fh>) {
25ae1130
RGS
44 $line++;
45 last if /^__END__/ ;
46 }
47
48 {
49 local $/ = undef;
50 $files++;
8606a93d 51 @prgs = (@prgs, $file, split "\n########\n", <$fh>) ;
25ae1130 52 }
8606a93d 53 close $fh;
25ae1130
RGS
54}
55
11ce4a76 56$^X = rel2abs($^X);
463cf062
NC
57my $tempdir = tempfile;
58
59mkdir $tempdir, 0700 or die "Can't mkdir '$tempdir': $!";
60chdir $tempdir or die die "Can't chdir '$tempdir': $!";
61unshift @INC, '../../lib';
62my $cleanup = 1;
463cf062
NC
63
64END {
65 if ($cleanup) {
66 chdir '..' or die "Couldn't chdir .. for cleanup: $!";
ebf2da99 67 rmtree($tempdir);
463cf062
NC
68 }
69}
70
3d243db0 71local $/ = undef;
25ae1130 72
3d243db0
KW
73my $tests = $::local_tests || 0;
74$tests = scalar(@prgs)-$files + $tests if $tests !~ /\D/;
75plan $tests; # If input is 'no_plan', pass it on unchanged
25ae1130 76
5f7e0818 77run_multiple_progs('../..', @prgs);
25ae1130 78
25ae1130 791;