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 => ["beamer_test.lyx"],
40 check => [["beamer_test.tex", "beamer_test.tex.orig"]],
41 commands => ["file-open beamer_test.lyx",
43 "repeat 150 outline-down",
44 "repeat 150 outline-up",
45 "buffer-export pdflatex",
51 command => [$git_exe, "ls-files", "--error-unmatch", "vcs_info_export.lyx"],
54 src_files => ["vcs_info_export.lyx"],
55 check => [["vcs_info_export.tex", "vcs_info_export.tex.orig"]],
56 command_line => ["-E", "pdflatex", "vcs_info_export.tex", "$data/vcs_info_export.lyx"],
59 src_files => ["ams-import.tex"],
60 check => [["ams-import.pdf", "ams-import.pdf", $comparepdf],
62 commands => ["buffer-new",
63 "buffer-import latex ams-import.tex",
70 die("Expected argument missing") if (! defined($ARGV[0]));
72 die("Invalid argument") if (! defined($Tests{$test}));
77 my @expected = &addFiles($data, $Tests{$test}->{check},1);
79 my @created = &addFiles($workdir, $Tests{$test}->{check}, 0);
81 my @comparecommand = &addFiles(undef, $Tests{$test}->{check}, 2);
83 # Copy src-files to work with
84 for my $f (@{$Tests{$test}->{src_files}}) {
85 copy("$data/$f", "$workdir/$f") or die("Copy failed: $!");
87 print "Unlinking " . join(' ', @created) . "\n";
92 $ENV{LANGUAGE} = "en_US";
96 my @command = ($lyx_exe, "-userdir", $userdir);
97 if (defined($Tests{$test}->{command_line})) {
98 push(@command, @{$Tests{$test}->{command_line}});
100 if (defined($Tests{$test}->{commands}->[0])) {
101 if ($qt_version eq "QT5") {
102 push(@command, "-platform", "offscreen");
104 if (defined($Tests{$test}->{commands}->[1])) { # more than one command
105 push(@command, "-x", "command-sequence " . join(';', @{$Tests{$test}->{commands}}));
108 push(@command, "-x", $Tests{$test}->{commands}->[0]);
114 for (my $i = 0; defined($created[$i]); $i++) {
115 die("File \"$created[$i]\" not created") if (! -e "$created[$i]");
116 if (defined($expected[$i])) {
117 die("Expected ($expected[$i]) and created ($created[$i]) files differ") if (&mycompare($comparecommand[$i], $expected[$i], $created[$i]) != 0);
122 sub checkPrecondition()
124 return if (! defined($Tests{$test}->{precondition}));
125 my $rPrecond = $Tests{$test}->{precondition};
126 my @command = @{$rPrecond->{command}};
127 if (defined($rPrecond->{workdir})) {
128 chdir($rPrecond->{workdir});
130 my $result = &system1(@command);
131 print "Pre-condition result = $result\n";
132 die("Pre-condition error") if ($result != 0);
137 my ($exe, @params) = @_;
138 print "Executing:\n\t$exe '" . join("' '", @params) . "'\n";
139 return(system($exe, @params));
142 # Create a list of file paths
144 # rBases: List of base-names
147 my ($tdir, $rrBases, $idx) = @_;
149 if (defined($tdir)) {
156 for my $rf (@{$rrBases}) {
158 if (defined($rf) && defined($rf->[$idx])) {
159 $path = "$dir$rf->[$idx]";
161 push(@result, $path);
168 my ($cmd, $expected, $created) = @_;
170 if (defined($cmd)) { # system command desired
172 if ($cmd =~ /NOTFOUND/) {
173 # no check is done due to missing executable
176 if ($cmd =~ /comparepdf/) {
177 push(@params, "-ca", "-v=1", $expected, $created);
180 die("unknown system command $cmd");
183 if (&system1($cmd, @params) != 0) {
185 $error = sprintf("failed to execute: $cmd");
188 $error = sprintf("$cmd with signal %d, %s coredump",
189 ($? & 127), ($? & 128) ? 'with' : 'without');
192 $error = sprintf("child $cmd exited with value %d", $? >> 8);
195 die($error) if ($error ne "");
200 # defaut text comparision
201 $result = compare($created, $expected);