]> git.lyx.org Git - features.git/blob - lib/scripts/lyx_batch.pl.in
vcs_info_export moved to new directory, part 2
[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                  "repeat 150 outline-down",
34                  "buffer-reload dump",
35                  "lyx-quit"]
36   },
37   vcs_info_export => {
38     precondition => {
39       command => [$git_exe, "ls-files", "--error-unmatch", "vcs_info_export.lyx"],
40       workdir => "$data",
41     },
42     create => "vcs_info_export.tex",
43     command_line => ["-E", "pdflatex", "vcs_info_export.tex", "$data/vcs_info_export.lyx"],
44   }
45     );
46
47 die("Expected argument missing") if (! defined($ARGV[0]));
48 my $test = $ARGV[0];
49 die("Invalid argument") if (! defined($Tests{$test}));
50
51 my $orig_lyx = "$data/$test.lyx";
52 my $work_lyx = "$workdir/$test.lyx";
53 my $expected = "$data/$test.tex.orig";
54 my $created = "$workdir/$Tests{$test}->{create}";
55
56 die("File \"$expected\" does not exist") if (! -e $expected);
57 # Create lyx-file to work with
58 copy($orig_lyx, $work_lyx) or die("Copy failed: $!");
59 unlink($created);
60 $ENV{LANG} = "en";
61 $ENV{LC_ALL} = "C";
62 $ENV{LANGUAGE} = "en_US";
63
64 check_precondition();
65 chdir($workdir);
66 my @command = ($lyx_exe, "-userdir", $userdir);
67 if (defined($Tests{$test}->{command_line})) {
68     push(@command, @{$Tests{$test}->{command_line}});
69 }
70 if (defined($Tests{$test}->{commands})) {
71     push(@command, "-x", "command-sequence " . join(';', @{$Tests{$test}->{commands}}));
72 }
73
74 system1(@command);
75 die("Expected ($expected) and created ($created) files differ") if (compare($expected, $created) != 0);
76
77 exit(0);
78
79 sub check_precondition()
80 {
81   return if (! defined($Tests{$test}->{precondition}));
82   my $rPrecond = $Tests{$test}->{precondition};
83   my @command = @{$rPrecond->{command}};
84   if (defined($rPrecond->{workdir})) {
85     chdir($rPrecond->{workdir});
86   }
87   my $result = system1(@command);
88   print "Pre-condition result = $result\n";
89   die("Pre-condition error") if ($result != 0);
90 }
91
92 sub system1(@)
93 {
94   my ($exe, @params) = @_;
95   print "Executing:\n\t$exe '" . join("' '", @params) . "'\n";
96   system($exe, @params);
97 }