xref: /openbsd-src/gnu/usr.bin/perl/t/lib/common.pl (revision eac174f2741a08d8deb8aae59a7f778ef9b5d770)
1898184e3Ssthen# This code is used by lib/charnames.t, lib/croak.t, lib/feature.t,
2898184e3Ssthen# lib/subs.t, lib/strict.t and lib/warnings.t
3898184e3Ssthen#
4898184e3Ssthen# On input, $::local_tests is the number of tests in the caller; or
5898184e3Ssthen# 'no_plan' if unknown, in which case it is the caller's responsibility
6898184e3Ssthen# to call cur_test() to find out how many this executed
7850e2753Smillert
8850e2753SmillertBEGIN {
9b8851fccSafresh1    require './test.pl'; require './charset_tools.pl';
10850e2753Smillert}
11850e2753Smillert
12850e2753Smillertuse Config;
13850e2753Smillertuse File::Path;
14898184e3Ssthenuse File::Spec::Functions qw(catfile curdir rel2abs);
15850e2753Smillert
16850e2753Smillertuse strict;
17850e2753Smillertuse warnings;
18898184e3Ssthenmy (undef, $file) = caller;
19898184e3Ssthenmy ($pragma_name) = $file =~ /([A-Za-z_0-9]+)\.t$/
20*eac174f2Safresh1    or die "Can't identify pragma to test from file name '$file'";
21850e2753Smillert
22850e2753Smillert$| = 1;
23850e2753Smillert
246fb12b70Safresh1my @w_files;
25850e2753Smillert
266fb12b70Safresh1if (@ARGV) {
276fb12b70Safresh1    print "ARGV = [@ARGV]\n";
286fb12b70Safresh1    @w_files = map { "./lib/$pragma_name/$_" } @ARGV;
296fb12b70Safresh1} else {
309f11ffb7Safresh1    @w_files = sort grep !/( \.rej | ~ | \ \(Autosaved\)\.txt ) \z/nx,
319f11ffb7Safresh1			 glob catfile(curdir(), "lib", $pragma_name, "*");
329f11ffb7Safresh1}
339f11ffb7Safresh1
349f11ffb7Safresh1if ($::IS_EBCDIC) { # Skip Latin1 files
359f11ffb7Safresh1    @w_files = grep { $_ !~ / _l1 $/x } @w_files
36850e2753Smillert}
37850e2753Smillert
386fb12b70Safresh1my ($tests, @prgs) = setup_multiple_progs(@w_files);
39850e2753Smillert
40898184e3Ssthen$^X = rel2abs($^X);
4191f110e0Safresh1@INC = map { rel2abs($_) } @INC;
42898184e3Ssthenmy $tempdir = tempfile;
43850e2753Smillert
44898184e3Ssthenmkdir $tempdir, 0700 or die "Can't mkdir '$tempdir': $!";
45898184e3Ssthenchdir $tempdir or die die "Can't chdir '$tempdir': $!";
46898184e3Ssthenmy $cleanup = 1;
47850e2753Smillert
48898184e3SsthenEND {
49898184e3Ssthen    if ($cleanup) {
50898184e3Ssthen	chdir '..' or die "Couldn't chdir .. for cleanup: $!";
51898184e3Ssthen	rmtree($tempdir);
52850e2753Smillert    }
5343003dfeSmillert}
5443003dfeSmillert
556fb12b70Safresh1if ($::local_tests && $::local_tests =~ /\D/) {
566fb12b70Safresh1    # If input is 'no_plan', pass it on unchanged
576fb12b70Safresh1    plan $::local_tests;
586fb12b70Safresh1} else {
596fb12b70Safresh1    plan $tests + ($::local_tests || 0);
606fb12b70Safresh1}
61850e2753Smillert
62898184e3Ssthenrun_multiple_progs('../..', @prgs);
63850e2753Smillert
64850e2753Smillert1;
65