4 # lyx_batch.pl testname
10 use File::Slurp qw(read_dir read_file);
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 if (-e "$test_dir/skip.test") {
131 my $skip_msg = read_file("$test_dir/skip.test");
132 print "TEST SKIPPED.\n$skip_msg\n";
136 my @expected = &addFiles($test_dir, $Tests{$test}->{check},1);
138 my @created = &addFiles($workdir, $Tests{$test}->{check}, 0);
140 # Copy src-files to work with
141 for my $f (@{$Tests{$test}->{src_files}}) {
142 copy("$test_dir/$f", "$workdir/$f") or die("Copy failed: $!");
144 print "Unlinking " . join(' ', @created) . "\n";
147 &checkPrecondition();
149 my @command = ($lyx_exe, "-userdir", $userdir);
150 if (defined($Tests{$test}->{command_line})) {
151 push(@command, @{$Tests{$test}->{command_line}});
153 if (defined($Tests{$test}->{commands}->[0])) {
154 if ($qt_version eq "QT5") {
155 push(@command, "-platform", "offscreen");
157 if (defined($Tests{$test}->{commands}->[1])) { # more than one command
158 push(@command, "-x", "command-sequence " . join(';', @{$Tests{$test}->{commands}}));
161 push(@command, "-x", $Tests{$test}->{commands}->[0]);
167 for (my $i = 0; defined($created[$i]); $i++) {
168 die("File \"$created[$i]\" not created") if (! -e "$created[$i]");
170 if (defined($expected[$i])) {
171 my $res = mycompare($Tests{$test}->{check_type}, $expected[$i], $created[$i], $Tests{$test}->{check_script});
173 die("Expected ($expected[$i]) and created ($created[$i]) files differ") if $res != 0;
178 sub checkPrecondition()
180 return if (! defined($Tests{$test}->{precondition}));
181 my $rPrecond = $Tests{$test}->{precondition};
182 my @command = @{$rPrecond->{command}};
183 if (defined($rPrecond->{workdir})) {
184 chdir($rPrecond->{workdir});
186 my $result = &system1(@command);
187 print "Pre-condition result = $result\n";
188 die("Pre-condition error") if ($result != 0);
193 my ($exe, @params) = @_;
194 print "Executing:\n\t$exe '" . join("' '", @params) . "'\n";
195 return(system($exe, @params));
198 # Create a list of file paths
200 # rBases: List of base-names
203 my ($tdir, $rrBases, $idx) = @_;
205 if (defined($tdir)) {
212 for my $rf (@{$rrBases}) {
214 if (defined($rf) && defined($rf->[$idx])) {
215 $path = "$dir$rf->[$idx]";
217 push(@result, $path);
224 my ($check_type, $expected, $created, $check_script) = @_;
227 $check_type //= 'text';
229 if ($check_type eq 'pdf') {
230 my $cmd = $comparepdf;
232 if ($cmd =~ /NOTFOUND/) {
233 # no check is done due to missing executable
237 "-ca", "-v=1", $expected, $created
241 if (&system1($cmd, @params) != 0) {
243 $error = sprintf("failed to execute: $cmd");
246 $error = sprintf("$cmd with signal %d, %s coredump",
247 ($? & 127), ($? & 128) ? 'with' : 'without');
250 $error = sprintf("child $cmd exited with value %d", $? >> 8);
253 die($error) if ($error ne "");
257 elsif ($check_type eq 'custom') {
258 $result = system1(@$check_script, $expected, $created);
260 elsif ($check_type eq 'text') {
261 # defaut text comparision
262 $result = compare($created, $expected);
265 die "Unknown check type: $check_type";