4 # lyx_batch.pl testname
10 use File::Slurp qw(read_dir);
12 sub checkPrecondition();
17 my $builddir = "@CMAKE_BINARY_DIR@";
18 my $userdir = "$builddir/Testing/.lyxbatch";
19 my $workdir = "$builddir/autotests/out-home";
21 my $vsuffix = "@PROGRAM_SUFFIX@";
22 my $lyx_exe = "$builddir/bin/lyx$vsuffix";
23 my $git_exe = "@LYX_GITVERSION@";
24 my $qt_version = "@LYX_USE_QT@";
26 my $lyxsource = "@LYX_ABS_TOP_SRCDIR@";
27 my $data = "$lyxsource/development/batchtests";
28 my $test_bin = "$lyxsource/development/batchtests/bin";
29 my $comparepdf = "@COMPAREPDF_EXECUTABLE@";
30 my $perl = "@PERL_EXECUTABLE@";
32 # src_files := Files to be copied from lyx-source to build-dir
33 # check := List of pairs of files to check
34 # created file (in build-dir)
35 # expected file (in source dir, to be compared with the created one)
36 # check_type: Type of check to perform, can be either:
37 # * text (default) - compares using File::Compare (i.e. full comparison)
38 # * pdf - compares using comparepdf (must be installed)
39 # * custom - compares using a custom script
40 # check_script: For check_type==custom, this is the script that's executed to do the comparison
41 # commands := List of commands (lyx-functions) to be executed by lyx in a batch
42 # precondition: system commands to be executed prior to the test
43 # command_line: List of parameters to be used on the lyx-command-line
46 src_files => ["save_as.lyx"],
47 check => [["save_as_saved.lyx"],
48 ["save_as_saved2.lyx"]],
49 commands => ["file-open beamer_test.lyx",
50 "buffer-write-as save_as_saved.lyx",
52 "buffer-write-as save_as_saved2.lyx",
56 src_files => ["beamer_test.lyx"],
57 check => [["beamer_test.tex", "beamer_test.tex.orig"]],
58 commands => ["file-open beamer_test.lyx",
60 "repeat 150 outline-down",
61 "repeat 150 outline-up",
62 "buffer-export pdflatex",
68 command => [$git_exe, "ls-files", "--error-unmatch", "vcs_info_export.lyx"],
71 src_files => ["vcs_info_export.lyx"],
72 check => [["vcs_info_export.tex", "vcs_info_export.tex.orig"]],
73 command_line => ["-E", "pdflatex", "vcs_info_export.tex", "$data/vcs_info_export.lyx"],
76 src_files => ["ams-import.tex"],
78 check => [["ams-import.pdf", "ams-import.pdf"],
80 commands => ["buffer-new",
81 "buffer-import latex ams-import.tex",
87 src_files => ["old.lyx", "new.lyx"],
88 check_type => 'custom',
89 check_script => ["$perl","$test_bin/compare_custom.pl"],
90 test_dir => "$lyxsource/development/batchtests/compare_tests/",
91 check => [["diffs.lyx", "diffs.expected.lyx"]],
93 "dialog-show compare run-blocking $workdir/old.lyx $workdir/new.lyx",
94 "buffer-write-as $workdir/diffs.lyx",
100 die("Expected argument missing") if (! defined($ARGV[0]));
102 die("Invalid argument") if (! defined($Tests{$test}));
110 $ENV{LANGUAGE} = "en_US";
112 if (defined $Tests{$test}->{test_dir}) {
113 my @dirs = read_dir($Tests{$test}->{test_dir}, prefix => 1);
114 foreach my $dir (@dirs) {
116 print "--- Running tests in $dir\n";
128 my $test_dir = shift;
130 my @expected = &addFiles($test_dir, $Tests{$test}->{check},1);
132 my @created = &addFiles($workdir, $Tests{$test}->{check}, 0);
134 # Copy src-files to work with
135 for my $f (@{$Tests{$test}->{src_files}}) {
136 copy("$test_dir/$f", "$workdir/$f") or die("Copy failed: $!");
138 print "Unlinking " . join(' ', @created) . "\n";
141 &checkPrecondition();
143 my @command = ($lyx_exe, "-userdir", $userdir);
144 if (defined($Tests{$test}->{command_line})) {
145 push(@command, @{$Tests{$test}->{command_line}});
147 if (defined($Tests{$test}->{commands}->[0])) {
148 if ($qt_version eq "QT5") {
149 push(@command, "-platform", "offscreen");
151 if (defined($Tests{$test}->{commands}->[1])) { # more than one command
152 push(@command, "-x", "command-sequence " . join(';', @{$Tests{$test}->{commands}}));
155 push(@command, "-x", $Tests{$test}->{commands}->[0]);
161 for (my $i = 0; defined($created[$i]); $i++) {
162 die("File \"$created[$i]\" not created") if (! -e "$created[$i]");
164 if (defined($expected[$i])) {
165 my $res = mycompare($Tests{$test}->{check_type}, $expected[$i], $created[$i], $Tests{$test}->{check_script});
167 die("Expected ($expected[$i]) and created ($created[$i]) files differ") if $res != 0;
172 sub checkPrecondition()
174 return if (! defined($Tests{$test}->{precondition}));
175 my $rPrecond = $Tests{$test}->{precondition};
176 my @command = @{$rPrecond->{command}};
177 if (defined($rPrecond->{workdir})) {
178 chdir($rPrecond->{workdir});
180 my $result = &system1(@command);
181 print "Pre-condition result = $result\n";
182 die("Pre-condition error") if ($result != 0);
187 my ($exe, @params) = @_;
188 print "Executing:\n\t$exe '" . join("' '", @params) . "'\n";
189 return(system($exe, @params));
192 # Create a list of file paths
194 # rBases: List of base-names
197 my ($tdir, $rrBases, $idx) = @_;
199 if (defined($tdir)) {
206 for my $rf (@{$rrBases}) {
208 if (defined($rf) && defined($rf->[$idx])) {
209 $path = "$dir$rf->[$idx]";
211 push(@result, $path);
218 my ($check_type, $expected, $created, $check_script) = @_;
221 $check_type //= 'text';
223 if ($check_type eq 'pdf') {
224 my $cmd = $comparepdf;
226 if ($cmd =~ /NOTFOUND/) {
227 # no check is done due to missing executable
231 "-ca", "-v=1", $expected, $created
235 if (&system1($cmd, @params) != 0) {
237 $error = sprintf("failed to execute: $cmd");
240 $error = sprintf("$cmd with signal %d, %s coredump",
241 ($? & 127), ($? & 128) ? 'with' : 'without');
244 $error = sprintf("child $cmd exited with value %d", $? >> 8);
247 die($error) if ($error ne "");
251 elsif ($check_type eq 'custom') {
252 $result = system1(@$check_script, $expected, $created);
254 elsif ($check_type eq 'text') {
255 # defaut text comparision
256 $result = compare($created, $expected);
259 die "Unknown check type: $check_type";