4 # lyx_batch.pl testname
11 sub check_precondition();
15 my $builddir = "@CMAKE_BINARY_DIR@";
16 my $userdir = "$builddir/Testing/.lyxbatch";
17 my $workdir = "$builddir/autotests/out-home";
19 my $vsuffix = "@PROGRAM_SUFFIX@";
20 my $lyx_exe = "$builddir/bin/lyx$vsuffix";
21 my $git_exe = "@LYX_GITVERSION@";
22 my $qt_version = "@LYX_USE_QT@";
24 my $lyxsource = "@LYX_ABS_TOP_SRCDIR@";
25 my $data = "$lyxsource/development/batchtests";
27 # src_files := Files to be copied from lyx-source to build-dir
28 # create := Files which are expected to be created in the build-dir
29 # original := Files in the lyx-source, corresponding to the created ones,
30 # which we provide for comparison
31 # commands := List of commands (lyx-functions) to be executed by lyx in a batch
32 # precondition: system commands to be executed prior to the test
33 # command_line: List of parameters to be used on the lyx-command-line
36 src_files => ["beamer_test.lyx"],
37 create => ["beamer_test.tex"],
38 original => ["beamer_test.tex.orig"],
39 commands => ["file-open beamer_test.lyx",
41 "repeat 150 outline-down",
42 "repeat 150 outline-up",
43 "buffer-export pdflatex",
49 command => [$git_exe, "ls-files", "--error-unmatch", "vcs_info_export.lyx"],
52 src_files => ["vcs_info_export.lyx"],
53 create => ["vcs_info_export.tex"],
54 original => ["vcs_info_export.tex.orig"],
55 command_line => ["-E", "pdflatex", "vcs_info_export.tex", "$data/vcs_info_export.lyx"],
58 src_files => ["ams-import.tex"],
59 create => ["ams-import.pdf", "ams-import.lyx"],
60 original => [undef, undef],
61 commands => ["buffer-new",
62 "buffer-import latex ams-import.tex",
69 die("Expected argument missing") if (! defined($ARGV[0]));
71 die("Invalid argument") if (! defined($Tests{$test}));
76 my @expected = &add_files($data, $Tests{$test}->{original});
78 my @created = &add_files($workdir, $Tests{$test}->{create});
80 # Copy src-files to work with
81 for my $f (@{$Tests{$test}->{src_files}}) {
82 copy("$data/$f", "$workdir/$f") or die("Copy failed: $!");
84 print "Unlinking " . join(' ', @created) . "\n";
89 $ENV{LANGUAGE} = "en_US";
93 my @command = ($lyx_exe, "-userdir", $userdir);
94 if (defined($Tests{$test}->{command_line})) {
95 push(@command, @{$Tests{$test}->{command_line}});
97 if (defined($Tests{$test}->{commands})) {
98 if ($qt_version eq "QT5") {
99 push(@command, "-platform", "offscreen");
101 push(@command, "-x", "command-sequence " . join(';', @{$Tests{$test}->{commands}}));
105 for my $f (@created) {
106 die("File \"$f\" not created") if (! -e "$f");
108 for (my $i = 0; defined($created[$i]); $i++) {
109 if (defined($expected[$i])) {
110 die("Expected ($expected[$i]) and created ($created[$i]) files differ") if (compare($expected[$i], $created[$i]) != 0);
115 sub check_precondition()
117 return if (! defined($Tests{$test}->{precondition}));
118 my $rPrecond = $Tests{$test}->{precondition};
119 my @command = @{$rPrecond->{command}};
120 if (defined($rPrecond->{workdir})) {
121 chdir($rPrecond->{workdir});
123 my $result = system1(@command);
124 print "Pre-condition result = $result\n";
125 die("Pre-condition error") if ($result != 0);
130 my ($exe, @params) = @_;
131 print "Executing:\n\t$exe '" . join("' '", @params) . "'\n";
132 system($exe, @params);
135 # Create a list of file paths
137 # rBases: List of base-names
140 my ($dir, $rBases) = @_;
142 for my $f (@{$rBases}) {
144 push(@result, "$dir/$f");
147 push(@result, undef);