4 # lyx_batch.pl testname
11 sub checkPrecondition();
16 my $builddir = "@CMAKE_BINARY_DIR@";
17 my $userdir = "$builddir/Testing/.lyxbatch";
18 my $workdir = "$builddir/autotests/out-home";
20 my $vsuffix = "@PROGRAM_SUFFIX@";
21 my $lyx_exe = "$builddir/bin/lyx$vsuffix";
22 my $git_exe = "@LYX_GITVERSION@";
23 my $qt_version = "@LYX_USE_QT@";
25 my $lyxsource = "@LYX_ABS_TOP_SRCDIR@";
26 my $data = "$lyxsource/development/batchtests";
27 my $comparepdf = "@COMPAREPDF_EXECUTABLE@";
29 # src_files := Files to be copied from lyx-source to build-dir
30 # check := List of tripples
31 # created file (in build-dir)
32 # expected file (in source dir, to be compared with the created one)
33 # eventually system command to compare files
34 # commands := List of commands (lyx-functions) to be executed by lyx in a batch
35 # precondition: system commands to be executed prior to the test
36 # command_line: List of parameters to be used on the lyx-command-line
39 src_files => ["save_as.lyx"],
40 check => [["save_as_saved.lyx"],
41 ["save_as_saved2.lyx"]],
42 commands => ["file-open beamer_test.lyx",
43 "buffer-write-as save_as_saved.lyx",
45 "buffer-write-as save_as_saved2.lyx",
49 src_files => ["beamer_test.lyx"],
50 check => [["beamer_test.tex", "beamer_test.tex.orig"]],
51 commands => ["file-open beamer_test.lyx",
53 "repeat 150 outline-down",
54 "repeat 150 outline-up",
55 "buffer-export pdflatex",
61 command => [$git_exe, "ls-files", "--error-unmatch", "vcs_info_export.lyx"],
64 src_files => ["vcs_info_export.lyx"],
65 check => [["vcs_info_export.tex", "vcs_info_export.tex.orig"]],
66 command_line => ["-E", "pdflatex", "vcs_info_export.tex", "$data/vcs_info_export.lyx"],
69 src_files => ["ams-import.tex"],
70 check => [["ams-import.pdf", "ams-import.pdf", $comparepdf],
72 commands => ["buffer-new",
73 "buffer-import latex ams-import.tex",
80 die("Expected argument missing") if (! defined($ARGV[0]));
82 die("Invalid argument") if (! defined($Tests{$test}));
87 my @expected = &addFiles($data, $Tests{$test}->{check},1);
89 my @created = &addFiles($workdir, $Tests{$test}->{check}, 0);
91 my @comparecommand = &addFiles(undef, $Tests{$test}->{check}, 2);
93 # Copy src-files to work with
94 for my $f (@{$Tests{$test}->{src_files}}) {
95 copy("$data/$f", "$workdir/$f") or die("Copy failed: $!");
97 print "Unlinking " . join(' ', @created) . "\n";
102 $ENV{LANGUAGE} = "en_US";
104 &checkPrecondition();
106 my @command = ($lyx_exe, "-userdir", $userdir);
107 if (defined($Tests{$test}->{command_line})) {
108 push(@command, @{$Tests{$test}->{command_line}});
110 if (defined($Tests{$test}->{commands}->[0])) {
111 if ($qt_version eq "QT5") {
112 push(@command, "-platform", "offscreen");
114 if (defined($Tests{$test}->{commands}->[1])) { # more than one command
115 push(@command, "-x", "command-sequence " . join(';', @{$Tests{$test}->{commands}}));
118 push(@command, "-x", $Tests{$test}->{commands}->[0]);
124 for (my $i = 0; defined($created[$i]); $i++) {
125 die("File \"$created[$i]\" not created") if (! -e "$created[$i]");
126 if (defined($expected[$i])) {
127 die("Expected ($expected[$i]) and created ($created[$i]) files differ") if (&mycompare($comparecommand[$i], $expected[$i], $created[$i]) != 0);
132 sub checkPrecondition()
134 return if (! defined($Tests{$test}->{precondition}));
135 my $rPrecond = $Tests{$test}->{precondition};
136 my @command = @{$rPrecond->{command}};
137 if (defined($rPrecond->{workdir})) {
138 chdir($rPrecond->{workdir});
140 my $result = &system1(@command);
141 print "Pre-condition result = $result\n";
142 die("Pre-condition error") if ($result != 0);
147 my ($exe, @params) = @_;
148 print "Executing:\n\t$exe '" . join("' '", @params) . "'\n";
149 return(system($exe, @params));
152 # Create a list of file paths
154 # rBases: List of base-names
157 my ($tdir, $rrBases, $idx) = @_;
159 if (defined($tdir)) {
166 for my $rf (@{$rrBases}) {
168 if (defined($rf) && defined($rf->[$idx])) {
169 $path = "$dir$rf->[$idx]";
171 push(@result, $path);
178 my ($cmd, $expected, $created) = @_;
180 if (defined($cmd)) { # system command desired
182 if ($cmd =~ /NOTFOUND/) {
183 # no check is done due to missing executable
186 if ($cmd =~ /comparepdf/) {
187 push(@params, "-ca", "-v=1", $expected, $created);
190 die("unknown system command $cmd");
193 if (&system1($cmd, @params) != 0) {
195 $error = sprintf("failed to execute: $cmd");
198 $error = sprintf("$cmd with signal %d, %s coredump",
199 ($? & 127), ($? & 128) ? 'with' : 'without');
202 $error = sprintf("child $cmd exited with value %d", $? >> 8);
205 die($error) if ($error ne "");
210 # defaut text comparision
211 $result = compare($created, $expected);