]> git.lyx.org Git - features.git/blob - lib/scripts/lyx_batch.pl.in
Added testcase for ticket #11156
[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/.lyxbatch";
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     orig_ext => "lyx",
28     create => ["beamer_test.tex"],
29     commands => ["file-open beamer_test.lyx",
30                  "buffer-begin",
31                  "repeat 150 outline-down",
32                  "repeat 150 outline-up",
33                  "buffer-export pdflatex",
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     orig_ext => "lyx",
43     create => ["vcs_info_export.tex"],
44     command_line => ["-E", "pdflatex", "vcs_info_export.tex", "$data/vcs_info_export.lyx"],
45   },
46   "ams-import" => {
47     docompare => 0,
48     orig_ext => "tex",
49     create => ["ams-import.pdf", "ams-import.lyx"],
50     commands => ["buffer-new",
51                  "buffer-import latex ams-import.tex",
52                  "buffer-write",
53                  "buffer-export pdf2",
54                  "lyx-quit"],
55   },
56   );
57
58 die("Expected argument missing") if (! defined($ARGV[0]));
59 my $test = $ARGV[0];
60 die("Invalid argument") if (! defined($Tests{$test}));
61
62 if (! -e $userdir) {
63     mkdir($userdir);
64 }
65 my $orig_file = "$data/$test.$Tests{$test}->{orig_ext}";
66 my $work_file = "$workdir/$test.$Tests{$test}->{orig_ext}";
67 my $expected = "$data/$test.tex.orig";
68 my @created = ();
69 if (defined($Tests{$test}->{create})) {
70   for my $created (@{$Tests{$test}->{create}}) {
71     push(@created, "$workdir/$created");
72   }
73 }
74 my $created = $created[0];
75 my $docompare = 1;
76 if (defined($Tests{$test}->{docompare})) {
77   $docompare = $Tests{$test}->{docompare};
78 }
79 die("File \"$expected\" does not exist") if ($docompare && ! -e $expected);
80 # Create lyx-file to work with
81 copy($orig_file, $work_file) or die("Copy failed: $!");
82 print "Unlinking " . join(' ', @created) . "\n";
83 unlink(@created);
84 $ENV{LANG} = "en";
85 $ENV{LC_ALL} = "C";
86 $ENV{LANGUAGE} = "en_US";
87
88 check_precondition();
89 chdir($workdir);
90 my @command = ($lyx_exe, "-userdir", $userdir);
91 if (defined($Tests{$test}->{command_line})) {
92     push(@command, @{$Tests{$test}->{command_line}});
93 }
94 if (defined($Tests{$test}->{commands})) {
95     push(@command, "-x", "command-sequence " . join(';', @{$Tests{$test}->{commands}}));
96 }
97
98 system1(@command);
99 die("Expected ($expected) and created ($created) files differ") if ($docompare && compare($expected, $created) != 0);
100
101 exit(0);
102
103 sub check_precondition()
104 {
105   return if (! defined($Tests{$test}->{precondition}));
106   my $rPrecond = $Tests{$test}->{precondition};
107   my @command = @{$rPrecond->{command}};
108   if (defined($rPrecond->{workdir})) {
109     chdir($rPrecond->{workdir});
110   }
111   my $result = system1(@command);
112   print "Pre-condition result = $result\n";
113   die("Pre-condition error") if ($result != 0);
114 }
115
116 sub system1(@)
117 {
118   my ($exe, @params) = @_;
119   print "Executing:\n\t$exe '" . join("' '", @params) . "'\n";
120   system($exe, @params);
121 }