summaryrefslogtreecommitdiff
path: root/t/lib/common.pl
blob: ac0b4046067b0fe1b2451684a3cb3a5969dc8bcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# This code is used by lib/charnames.t, lib/croak.t, lib/feature.t,
# lib/subs.t, lib/strict.t and lib/warnings.t
#
# On input, $::local_tests is the number of tests in the caller; or
# 'no_plan' if unknown, in which case it is the caller's responsibility
# to call cur_test() to find out how many this executed

BEGIN {
    require './test.pl'; require './charset_tools.pl';
}

use Config;
use File::Path;
use File::Spec::Functions qw(catfile curdir rel2abs);

use strict;
use warnings;
my (undef, $file) = caller;
my ($pragma_name) = $file =~ /([A-Za-z_0-9]+)\.t$/
    or die "Can't identify pragma to test from file name '$file'";

$| = 1;

my @w_files;

if (@ARGV) {
    print "ARGV = [@ARGV]\n";
    @w_files = map { "./lib/$pragma_name/$_" } @ARGV;
} else {
    @w_files = sort grep !/( \.rej | ~ | \ \(Autosaved\)\.txt ) \z/nx,
			 glob catfile(curdir(), "lib", $pragma_name, "*");
}

if ($::IS_EBCDIC) { # Skip Latin1 files
    @w_files = grep { $_ !~ / _l1 $/x } @w_files
}

my ($tests, @prgs) = setup_multiple_progs(@w_files);

$^X = rel2abs($^X);
@INC = map { rel2abs($_) } @INC;
my $tempdir = tempfile;

mkdir $tempdir, 0700 or die "Can't mkdir '$tempdir': $!";
chdir $tempdir or die die "Can't chdir '$tempdir': $!";
my $cleanup = 1;

END {
    if ($cleanup) {
	chdir '..' or die "Couldn't chdir .. for cleanup: $!";
	rmtree($tempdir);
    }
}

if ($::local_tests && $::local_tests =~ /\D/) {
    # If input is 'no_plan', pass it on unchanged
    plan $::local_tests;
} else {
    plan $tests + ($::local_tests || 0);
}

run_multiple_progs('../..', @prgs);

1;