+
+sub run_tests {
+ my $test_dir = shift;
+
+ if (-e "$test_dir/skip.test") {
+ my $skip_msg = read_file("$test_dir/skip.test");
+ print "TEST SKIPPED.\n$skip_msg\n";
+ return;
+ }
+
+ my @expected = &addFiles($test_dir, $Tests{$test}->{check},1);
+
+ my @created = &addFiles($workdir, $Tests{$test}->{check}, 0);
+
+ # Copy src-files to work with
+ for my $f (@{$Tests{$test}->{src_files}}) {
+ copy("$test_dir/$f", "$workdir/$f") or die("Copy failed: $!");
+ }
+ print "Unlinking " . join(' ', @created) . "\n";
+ unlink(@created);
+
+ &checkPrecondition();
+ chdir($workdir);
+ my @command = ($lyx_exe, "-userdir", $userdir);
+ if (defined($Tests{$test}->{command_line})) {
+ push(@command, @{$Tests{$test}->{command_line}});
+ }
+ if (defined($Tests{$test}->{commands}->[0])) {
+ if ($qt_version eq "QT5") {
+ push(@command, "-platform", "offscreen");
+ }
+ if (defined($Tests{$test}->{commands}->[1])) { # more than one command
+ push(@command, "-x", "command-sequence " . join(';', @{$Tests{$test}->{commands}}));
+ }
+ else {
+ push(@command, "-x", $Tests{$test}->{commands}->[0]);
+ }
+ }
+
+ &system1(@command);
+
+ for (my $i = 0; defined($created[$i]); $i++) {
+ die("File \"$created[$i]\" not created") if (! -e "$created[$i]");
+
+ if (defined($expected[$i])) {
+ my $res = mycompare($Tests{$test}->{check_type}, $expected[$i], $created[$i], $Tests{$test}->{check_script});
+
+ die("Expected ($expected[$i]) and created ($created[$i]) files differ") if $res != 0;
+ }
+ }
+}
+
+sub checkPrecondition()
+{
+ return if (! defined($Tests{$test}->{precondition}));
+ my $rPrecond = $Tests{$test}->{precondition};
+ my @command = @{$rPrecond->{command}};
+ if (defined($rPrecond->{workdir})) {
+ chdir($rPrecond->{workdir});
+ }
+ my $result = &system1(@command);
+ print "Pre-condition result = $result\n";
+ die("Pre-condition error") if ($result != 0);
+}
+
+sub system1(@)
+{
+ my ($exe, @params) = @_;
+ print "Executing:\n\t$exe '" . join("' '", @params) . "'\n";
+ return(system($exe, @params));
+}
+
+# Create a list of file paths
+# dir: result-dir
+# rBases: List of base-names
+sub addFiles($$$)
+{
+ my ($tdir, $rrBases, $idx) = @_;
+ my $dir;
+ if (defined($tdir)) {
+ $dir = "$tdir/";
+ }
+ else {
+ $dir = "";
+ }
+ my @result = ();
+ for my $rf (@{$rrBases}) {
+ my $path = undef;
+ if (defined($rf) && defined($rf->[$idx])) {
+ $path = "$dir$rf->[$idx]";
+ }
+ push(@result, $path);
+ }
+ return(@result);
+}
+
+sub mycompare($$$$)
+{
+ my ($check_type, $expected, $created, $check_script) = @_;
+ my $result;
+
+ $check_type //= 'text';
+
+if ($check_type eq 'pdf') {
+ my $cmd = $comparepdf;
+
+ if ($cmd =~ /NOTFOUND/) {
+ # no check is done due to missing executable
+ }
+ else {
+ my @params = (
+ "-ca", "-v=1", $expected, $created
+ );
+
+ my $error = "";
+ if (&system1($cmd, @params) != 0) {
+ if ($? == -1) {
+ $error = sprintf("failed to execute: $cmd");
+ }
+ elsif ($? & 127) {
+ $error = sprintf("$cmd with signal %d, %s coredump",
+ ($? & 127), ($? & 128) ? 'with' : 'without');
+ }
+ else {
+ $error = sprintf("child $cmd exited with value %d", $? >> 8);
+ }
+ }
+ die($error) if ($error ne "");
+ }
+ $result = 0;
+ }
+ elsif ($check_type eq 'custom') {
+ $result = system1(@$check_script, $expected, $created);
+ }
+ elsif ($check_type eq 'text') {
+ # defaut text comparision
+ $result = compare($created, $expected);
+ }
+ else {
+ die "Unknown check type: $check_type";
+ }
+ return($result);
+}