]> git.lyx.org Git - features.git/blob - lib/scripts/lyx_batch.pl.in
Adapt test outline-beamer' to the synchronous batch export
[features.git] / lib / scripts / lyx_batch.pl.in
1 #! /usr/bin/env perl
2 # -*- mode: perl; -*-
3
4 # lyx_batch.pl testname
5
6 use strict;
7 use warnings;
8 use File::Copy;
9 use File::Compare;
10
11 sub check_precondition();
12 sub system1(@);
13
14 my $builddir = "@CMAKE_BINARY_DIR@";
15 my $userdir = "$builddir/Testing/.lyx";
16 my $workdir = "$builddir/autotests/out-home";
17
18 my $vsuffix = "@PROGRAM_SUFFIX@";
19 my $lyx_exe = "$builddir/bin/lyx$vsuffix";
20 my $git_exe = "@LYX_GITVERSION@";
21
22 my $lyxsource = "@LYX_ABS_TOP_SRCDIR@";
23 my $data = "$lyxsource/development/batchtests";
24
25 my %Tests = (
26   beamer_test => {
27     create => "beamer_test.tex",
28     commands => ["file-open beamer_test.lyx",
29                  "buffer-begin",
30                  "repeat 150 outline-down",
31                  "repeat 150 outline-up",
32                  "buffer-export pdflatex",
33                  "buffer-reload dump",
34                  "lyx-quit"]
35   },
36   vcs_info_export => {
37     precondition => {
38       command => [$git_exe, "ls-files", "--error-unmatch", "vcs_info_export.lyx"],
39       workdir => "$data",
40     },
41     create => "vcs_info_export.tex",
42     command_line => ["-E", "pdflatex", "vcs_info_export.tex", "$data/vcs_info_export.lyx"],
43   }
44     );
45
46 die("Expected argument missing") if (! defined($ARGV[0]));
47 my $test = $ARGV[0];
48 die("Invalid argument") if (! defined($Tests{$test}));
49
50 my $orig_lyx = "$data/$test.lyx";
51 my $work_lyx = "$workdir/$test.lyx";
52 my $expected = "$data/$test.tex.orig";
53 my $created = "$workdir/$Tests{$test}->{create}";
54
55 die("File \"$expected\" does not exist") if (! -e $expected);
56 # Create lyx-file to work with
57 copy($orig_lyx, $work_lyx) or die("Copy failed: $!");
58 unlink($created);
59 $ENV{LANG} = "en";
60 $ENV{LC_ALL} = "C";
61 $ENV{LANGUAGE} = "en_US";
62
63 check_precondition();
64 chdir($workdir);
65 my @command = ($lyx_exe, "-userdir", $userdir);
66 if (defined($Tests{$test}->{command_line})) {
67     push(@command, @{$Tests{$test}->{command_line}});
68 }
69 if (defined($Tests{$test}->{commands})) {
70     push(@command, "-x", "command-sequence " . join(';', @{$Tests{$test}->{commands}}));
71 }
72
73 system1(@command);
74 die("Expected ($expected) and created ($created) files differ") if (compare($expected, $created) != 0);
75
76 exit(0);
77
78 sub check_precondition()
79 {
80   return if (! defined($Tests{$test}->{precondition}));
81   my $rPrecond = $Tests{$test}->{precondition};
82   my @command = @{$rPrecond->{command}};
83   if (defined($rPrecond->{workdir})) {
84     chdir($rPrecond->{workdir});
85   }
86   my $result = system1(@command);
87   print "Pre-condition result = $result\n";
88   die("Pre-condition error") if ($result != 0);
89 }
90
91 sub system1(@)
92 {
93   my ($exe, @params) = @_;
94   print "Executing:\n\t$exe '" . join("' '", @params) . "'\n";
95   system($exe, @params);
96 }