| 1 |
# $Id: common-test.pl 16695 2010-01-13 01:18:02Z karl $ |
| 2 |
# Public domain. Originally written 2010, Karl Berry. |
| 3 |
# Common definitions for Perl tests in TeX Live. We want to use Perl to |
| 4 |
# have a chance of running the tests on Windows. |
| 5 |
|
| 6 |
# Try to avoid output files (nested-range.ind) not being created due to |
| 7 |
# caching, although apparently this is not likely to help. When the |
| 8 |
# subprogram exits, that should ensure all caches are updated.. |
| 9 |
$| = 1; |
| 10 |
|
| 11 |
# Find absolute path. |
| 12 |
chomp (my $TL_TESTS_DIR = `cd "$srcdir/../tests" && pwd`); |
| 13 |
|
| 14 |
# srcdir must be a sibling dir to kpathsea, e.g., web2c. |
| 15 |
$ENV{"TEXMFCNF"} = "$srcdir/../kpathsea"; |
| 16 |
$ENV{"AFMFONTS"} |
| 17 |
= $ENV{"BIBINPUTS"} |
| 18 |
= $ENV{"BSTINPUTS"} |
| 19 |
= $ENV{"TEXINPUTS"} |
| 20 |
= ".:$srcdir/tests:$srcdir/../tests/texmf//"; |
| 21 |
|
| 22 |
|
| 23 |
# Run PROG with ARGS. Return the exit status. |
| 24 |
# Die if PROG is not executable. |
| 25 |
# |
| 26 |
sub test_run { |
| 27 |
my ($prog, @args) = @_; |
| 28 |
|
| 29 |
# Possibly we should check that $prog starts with ./, since we always |
| 30 |
# want to run out of the build dir. I think. |
| 31 |
die "$0: no program $prog in " . `pwd` if ! -x $prog; |
| 32 |
|
| 33 |
# use local pm files and kpsewhich. |
| 34 |
$ENV{"PERL5LIB"} = $TL_TESTS_DIR; |
| 35 |
$ENV{"PATH"} = "../kpathsea:$ENV{PATH}"; |
| 36 |
|
| 37 |
# Won't be copyable with weird names, but should get the info across. |
| 38 |
print "$0: running ", $prog, " ", join (" ", @args), "\n"; |
| 39 |
|
| 40 |
# Run it. |
| 41 |
my $ret = system ($prog, @args); |
| 42 |
return $ret; |
| 43 |
} |
| 44 |
|
| 45 |
sub test_file_copy { |
| 46 |
my ($srcfile,$dstfile) = @_; |
| 47 |
|
| 48 |
# don't copy onto itself. |
| 49 |
chomp (my $srcdir = `dirname $srcfile`); |
| 50 |
chomp ($srcdir = `cd $srcdir && pwd`); |
| 51 |
# |
| 52 |
chomp (my $dstdir = `dirname $dstfile`); |
| 53 |
chomp ($dstdir = `cd $dstdir && pwd`); |
| 54 |
return if $srcdir eq $dstdir; |
| 55 |
|
| 56 |
local *IN; |
| 57 |
$IN = "<$srcfile"; |
| 58 |
open (IN) || die "open($srcfile) failed: $!"; |
| 59 |
my @in = <IN>; |
| 60 |
close (IN) || warn "close($srcfile) failed: $!"; |
| 61 |
|
| 62 |
local *OUT; |
| 63 |
$OUT = ">$dstfile"; |
| 64 |
open (OUT) || die "open($dstfile) failed: $!"; |
| 65 |
print (OUT @in) || die "print($dstfile) failed: $!"; |
| 66 |
close (OUT) || warn "close($dstfile) failed: $!"; |
| 67 |
|
| 68 |
return 0; |
| 69 |
} |