lyx_mirror/lib/scripts/lyx_batch.pl.in
Kornel Benko 1a36fee79d Added testcase for ticket #11156
The test is named "AMS-import", with defined test-labels 'tex2lyx' and 'batch'
2018-05-24 20:49:11 +02:00

122 lines
3.2 KiB
Perl

#! /usr/bin/env perl
# -*- mode: perl; -*-
# lyx_batch.pl testname
use strict;
use warnings;
use File::Copy;
use File::Compare;
sub check_precondition();
sub system1(@);
my $builddir = "@CMAKE_BINARY_DIR@";
my $userdir = "$builddir/Testing/.lyxbatch";
my $workdir = "$builddir/autotests/out-home";
my $vsuffix = "@PROGRAM_SUFFIX@";
my $lyx_exe = "$builddir/bin/lyx$vsuffix";
my $git_exe = "@LYX_GITVERSION@";
my $lyxsource = "@LYX_ABS_TOP_SRCDIR@";
my $data = "$lyxsource/development/batchtests";
my %Tests = (
beamer_test => {
orig_ext => "lyx",
create => ["beamer_test.tex"],
commands => ["file-open beamer_test.lyx",
"buffer-begin",
"repeat 150 outline-down",
"repeat 150 outline-up",
"buffer-export pdflatex",
"buffer-reload dump",
"lyx-quit"]
},
vcs_info_export => {
precondition => {
command => [$git_exe, "ls-files", "--error-unmatch", "vcs_info_export.lyx"],
workdir => "$data",
},
orig_ext => "lyx",
create => ["vcs_info_export.tex"],
command_line => ["-E", "pdflatex", "vcs_info_export.tex", "$data/vcs_info_export.lyx"],
},
"ams-import" => {
docompare => 0,
orig_ext => "tex",
create => ["ams-import.pdf", "ams-import.lyx"],
commands => ["buffer-new",
"buffer-import latex ams-import.tex",
"buffer-write",
"buffer-export pdf2",
"lyx-quit"],
},
);
die("Expected argument missing") if (! defined($ARGV[0]));
my $test = $ARGV[0];
die("Invalid argument") if (! defined($Tests{$test}));
if (! -e $userdir) {
mkdir($userdir);
}
my $orig_file = "$data/$test.$Tests{$test}->{orig_ext}";
my $work_file = "$workdir/$test.$Tests{$test}->{orig_ext}";
my $expected = "$data/$test.tex.orig";
my @created = ();
if (defined($Tests{$test}->{create})) {
for my $created (@{$Tests{$test}->{create}}) {
push(@created, "$workdir/$created");
}
}
my $created = $created[0];
my $docompare = 1;
if (defined($Tests{$test}->{docompare})) {
$docompare = $Tests{$test}->{docompare};
}
die("File \"$expected\" does not exist") if ($docompare && ! -e $expected);
# Create lyx-file to work with
copy($orig_file, $work_file) or die("Copy failed: $!");
print "Unlinking " . join(' ', @created) . "\n";
unlink(@created);
$ENV{LANG} = "en";
$ENV{LC_ALL} = "C";
$ENV{LANGUAGE} = "en_US";
check_precondition();
chdir($workdir);
my @command = ($lyx_exe, "-userdir", $userdir);
if (defined($Tests{$test}->{command_line})) {
push(@command, @{$Tests{$test}->{command_line}});
}
if (defined($Tests{$test}->{commands})) {
push(@command, "-x", "command-sequence " . join(';', @{$Tests{$test}->{commands}}));
}
system1(@command);
die("Expected ($expected) and created ($created) files differ") if ($docompare && compare($expected, $created) != 0);
exit(0);
sub check_precondition()
{
return if (! defined($Tests{$test}->{precondition}));
my $rPrecond = $Tests{$test}->{precondition};
my @command = @{$rPrecond->{command}};
if (defined($rPrecond->{workdir})) {
chdir($rPrecond->{workdir});
}
my $result = system1(@command);
print "Pre-condition result = $result\n";
die("Pre-condition error") if ($result != 0);
}
sub system1(@)
{
my ($exe, @params) = @_;
print "Executing:\n\t$exe '" . join("' '", @params) . "'\n";
system($exe, @params);
}