2018-01-14 12:47:27 +00:00
|
|
|
#! /usr/bin/env perl
|
|
|
|
# -*- mode: perl; -*-
|
|
|
|
|
|
|
|
# lyx_batch.pl testname
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use File::Copy;
|
|
|
|
use File::Compare;
|
|
|
|
|
2018-06-09 07:08:42 +00:00
|
|
|
sub checkPrecondition();
|
2018-01-17 11:25:22 +00:00
|
|
|
sub system1(@);
|
2018-06-09 07:08:42 +00:00
|
|
|
sub addFiles($$$);
|
|
|
|
sub mycompare($$$);
|
2018-01-17 11:25:22 +00:00
|
|
|
|
2018-01-14 12:47:27 +00:00
|
|
|
my $builddir = "@CMAKE_BINARY_DIR@";
|
2018-05-24 18:49:11 +00:00
|
|
|
my $userdir = "$builddir/Testing/.lyxbatch";
|
2018-01-14 12:47:27 +00:00
|
|
|
my $workdir = "$builddir/autotests/out-home";
|
|
|
|
|
|
|
|
my $vsuffix = "@PROGRAM_SUFFIX@";
|
|
|
|
my $lyx_exe = "$builddir/bin/lyx$vsuffix";
|
2018-01-17 11:25:22 +00:00
|
|
|
my $git_exe = "@LYX_GITVERSION@";
|
2018-05-26 11:30:30 +00:00
|
|
|
my $qt_version = "@LYX_USE_QT@";
|
2018-01-14 12:47:27 +00:00
|
|
|
|
|
|
|
my $lyxsource = "@LYX_ABS_TOP_SRCDIR@";
|
|
|
|
my $data = "$lyxsource/development/batchtests";
|
2018-06-09 07:08:42 +00:00
|
|
|
my $comparepdf = "@COMPAREPDF_EXECUTABLE@";
|
2018-01-14 12:47:27 +00:00
|
|
|
|
2018-05-25 15:19:34 +00:00
|
|
|
# src_files := Files to be copied from lyx-source to build-dir
|
2018-06-09 07:08:42 +00:00
|
|
|
# check := List of tripples
|
|
|
|
# created file (in build-dir)
|
|
|
|
# expected file (in source dir, to be compared with the created one)
|
|
|
|
# eventually system command to compare files
|
|
|
|
# commands := List of commands (lyx-functions) to be executed by lyx in a batch
|
2018-05-25 15:19:34 +00:00
|
|
|
# precondition: system commands to be executed prior to the test
|
|
|
|
# command_line: List of parameters to be used on the lyx-command-line
|
2018-01-14 12:47:27 +00:00
|
|
|
my %Tests = (
|
|
|
|
beamer_test => {
|
2018-05-25 15:19:34 +00:00
|
|
|
src_files => ["beamer_test.lyx"],
|
2018-06-09 07:08:42 +00:00
|
|
|
check => [["beamer_test.tex", "beamer_test.tex.orig"]],
|
2018-01-14 12:47:27 +00:00
|
|
|
commands => ["file-open beamer_test.lyx",
|
2018-05-25 15:19:34 +00:00
|
|
|
"buffer-begin",
|
|
|
|
"repeat 150 outline-down",
|
|
|
|
"repeat 150 outline-up",
|
|
|
|
"buffer-export pdflatex",
|
|
|
|
"buffer-reload dump",
|
|
|
|
"lyx-quit"],
|
2018-01-17 11:25:22 +00:00
|
|
|
},
|
|
|
|
vcs_info_export => {
|
|
|
|
precondition => {
|
|
|
|
command => [$git_exe, "ls-files", "--error-unmatch", "vcs_info_export.lyx"],
|
|
|
|
workdir => "$data",
|
|
|
|
},
|
2018-05-25 15:19:34 +00:00
|
|
|
src_files => ["vcs_info_export.lyx"],
|
2018-06-09 07:08:42 +00:00
|
|
|
check => [["vcs_info_export.tex", "vcs_info_export.tex.orig"]],
|
2018-01-17 11:25:22 +00:00
|
|
|
command_line => ["-E", "pdflatex", "vcs_info_export.tex", "$data/vcs_info_export.lyx"],
|
2018-05-24 18:49:11 +00:00
|
|
|
},
|
|
|
|
"ams-import" => {
|
2018-05-25 15:19:34 +00:00
|
|
|
src_files => ["ams-import.tex"],
|
2018-06-09 07:08:42 +00:00
|
|
|
check => [["ams-import.pdf", "ams-import.pdf", $comparepdf],
|
|
|
|
["ams-import.lyx"]],
|
2018-05-24 18:49:11 +00:00
|
|
|
commands => ["buffer-new",
|
2018-05-25 15:19:34 +00:00
|
|
|
"buffer-import latex ams-import.tex",
|
|
|
|
"buffer-write",
|
|
|
|
"buffer-export pdf2",
|
|
|
|
"lyx-quit"],
|
2018-05-24 18:49:11 +00:00
|
|
|
},
|
2018-05-25 15:19:34 +00:00
|
|
|
);
|
2018-01-14 12:47:27 +00:00
|
|
|
|
2018-01-17 11:25:22 +00:00
|
|
|
die("Expected argument missing") if (! defined($ARGV[0]));
|
2018-01-14 12:47:27 +00:00
|
|
|
my $test = $ARGV[0];
|
2018-01-17 11:25:22 +00:00
|
|
|
die("Invalid argument") if (! defined($Tests{$test}));
|
2018-01-14 12:47:27 +00:00
|
|
|
|
2018-05-24 18:49:11 +00:00
|
|
|
if (! -e $userdir) {
|
2018-05-25 15:19:34 +00:00
|
|
|
mkdir($userdir);
|
2018-05-24 18:49:11 +00:00
|
|
|
}
|
2018-06-09 07:08:42 +00:00
|
|
|
my @expected = &addFiles($data, $Tests{$test}->{check},1);
|
2018-05-25 15:19:34 +00:00
|
|
|
|
2018-06-09 07:08:42 +00:00
|
|
|
my @created = &addFiles($workdir, $Tests{$test}->{check}, 0);
|
|
|
|
|
|
|
|
my @comparecommand = &addFiles(undef, $Tests{$test}->{check}, 2);
|
2018-05-25 15:19:34 +00:00
|
|
|
|
|
|
|
# Copy src-files to work with
|
|
|
|
for my $f (@{$Tests{$test}->{src_files}}) {
|
|
|
|
copy("$data/$f", "$workdir/$f") or die("Copy failed: $!");
|
2018-05-24 18:49:11 +00:00
|
|
|
}
|
|
|
|
print "Unlinking " . join(' ', @created) . "\n";
|
|
|
|
unlink(@created);
|
2018-05-25 15:19:34 +00:00
|
|
|
|
2018-01-14 12:47:27 +00:00
|
|
|
$ENV{LANG} = "en";
|
|
|
|
$ENV{LC_ALL} = "C";
|
|
|
|
$ENV{LANGUAGE} = "en_US";
|
|
|
|
|
2018-06-09 07:08:42 +00:00
|
|
|
&checkPrecondition();
|
2018-01-14 12:47:27 +00:00
|
|
|
chdir($workdir);
|
2018-01-17 11:25:22 +00:00
|
|
|
my @command = ($lyx_exe, "-userdir", $userdir);
|
|
|
|
if (defined($Tests{$test}->{command_line})) {
|
2018-05-25 15:19:34 +00:00
|
|
|
push(@command, @{$Tests{$test}->{command_line}});
|
2018-01-17 11:25:22 +00:00
|
|
|
}
|
2018-06-09 07:08:42 +00:00
|
|
|
if (defined($Tests{$test}->{commands}->[0])) {
|
2018-05-26 11:30:30 +00:00
|
|
|
if ($qt_version eq "QT5") {
|
|
|
|
push(@command, "-platform", "offscreen");
|
|
|
|
}
|
2018-06-09 07:08:42 +00:00
|
|
|
if (defined($Tests{$test}->{commands}->[1])) { # more than one command
|
|
|
|
push(@command, "-x", "command-sequence " . join(';', @{$Tests{$test}->{commands}}));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push(@command, "-x", $Tests{$test}->{commands}->[0]);
|
|
|
|
}
|
2018-01-17 11:25:22 +00:00
|
|
|
}
|
|
|
|
|
2018-06-09 07:08:42 +00:00
|
|
|
&system1(@command);
|
|
|
|
|
2018-05-25 15:19:34 +00:00
|
|
|
for (my $i = 0; defined($created[$i]); $i++) {
|
2018-06-09 07:08:42 +00:00
|
|
|
die("File \"$created[$i]\" not created") if (! -e "$created[$i]");
|
|
|
|
if (defined($expected[$i])) {
|
|
|
|
die("Expected ($expected[$i]) and created ($created[$i]) files differ") if (&mycompare($comparecommand[$i], $expected[$i], $created[$i]) != 0);
|
2018-05-25 15:19:34 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-14 12:47:27 +00:00
|
|
|
exit(0);
|
|
|
|
|
2018-06-09 07:08:42 +00:00
|
|
|
sub checkPrecondition()
|
2018-01-17 11:25:22 +00:00
|
|
|
{
|
|
|
|
return if (! defined($Tests{$test}->{precondition}));
|
|
|
|
my $rPrecond = $Tests{$test}->{precondition};
|
|
|
|
my @command = @{$rPrecond->{command}};
|
|
|
|
if (defined($rPrecond->{workdir})) {
|
|
|
|
chdir($rPrecond->{workdir});
|
|
|
|
}
|
2018-06-09 07:08:42 +00:00
|
|
|
my $result = &system1(@command);
|
2018-01-17 11:25:22 +00:00
|
|
|
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";
|
2018-06-09 07:08:42 +00:00
|
|
|
return(system($exe, @params));
|
2018-01-17 11:25:22 +00:00
|
|
|
}
|
2018-05-25 15:19:34 +00:00
|
|
|
|
|
|
|
# Create a list of file paths
|
|
|
|
# dir: result-dir
|
|
|
|
# rBases: List of base-names
|
2018-06-09 07:08:42 +00:00
|
|
|
sub addFiles($$$)
|
2018-05-25 15:19:34 +00:00
|
|
|
{
|
2018-06-09 07:08:42 +00:00
|
|
|
my ($tdir, $rrBases, $idx) = @_;
|
|
|
|
my $dir;
|
|
|
|
if (defined($tdir)) {
|
|
|
|
$dir = "$tdir/";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$dir = "";
|
|
|
|
}
|
2018-05-25 15:19:34 +00:00
|
|
|
my @result = ();
|
2018-06-09 07:08:42 +00:00
|
|
|
for my $rf (@{$rrBases}) {
|
|
|
|
my $path = undef;
|
|
|
|
if (defined($rf) && defined($rf->[$idx])) {
|
|
|
|
$path = "$dir$rf->[$idx]";
|
|
|
|
}
|
|
|
|
push(@result, $path);
|
|
|
|
}
|
|
|
|
return(@result);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mycompare($$$)
|
|
|
|
{
|
|
|
|
my ($cmd, $expected, $created) = @_;
|
|
|
|
my $result;
|
|
|
|
if (defined($cmd)) { # system command desired
|
|
|
|
my @params = ();
|
|
|
|
if ($cmd =~ /NOTFOUND/) {
|
|
|
|
# no check is done due to missing executable
|
2018-05-25 15:19:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-06-09 07:08:42 +00:00
|
|
|
if ($cmd =~ /comparepdf/) {
|
|
|
|
push(@params, "-ca", "-v=1", $expected, $created);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
die("unknown system command $cmd");
|
|
|
|
}
|
|
|
|
my $error = "";
|
|
|
|
if (&system1($cmd, @params) != 0) {
|
|
|
|
if ($? == -1) {
|
|
|
|
$error = sprintf("failed to execute: $cmd");
|
|
|
|
}
|
|
|
|
elsif ($? & 127) {
|
|
|
|
$error = sprintf("$cmd with signal %d, %s coredump",
|
|
|
|
($? & 127), ($? & 128) ? 'with' : 'without');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$error = sprintf("child $cmd exited with value %d", $? >> 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
die($error) if ($error ne "");
|
2018-05-25 15:19:34 +00:00
|
|
|
}
|
2018-06-09 07:08:42 +00:00
|
|
|
$result = 0;
|
2018-05-25 15:19:34 +00:00
|
|
|
}
|
2018-06-09 07:08:42 +00:00
|
|
|
else {
|
|
|
|
# defaut text comparision
|
|
|
|
$result = compare($created, $expected);
|
|
|
|
}
|
|
|
|
return($result);
|
2018-05-25 15:19:34 +00:00
|
|
|
}
|