mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Cmake export tests: Modularisation of prefTest.pl
Also added a parameter to easier switch between standard settings in preferences and settings to use in export tests.
This commit is contained in:
parent
d4d7cdf9a1
commit
c5e53637c2
@ -4,17 +4,28 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
# Syntax: prefTest.pl [<var1>=<Subst1> [<var2>=<Subst> ...]] [[ctest parameters]]
|
||||
# Syntax: prefTest.pl [test|default] [<var1>=<Subst1> [<var2>=<Subst> ...]] [[ctest parameters]]
|
||||
# If the first parameter is "test"
|
||||
# allow use of -shell-escape in converters and
|
||||
# allow use of external programs
|
||||
# If the first parameter is "default"
|
||||
# remove "-shell-escape" from converters and
|
||||
# forbid use of external programs
|
||||
# Else
|
||||
# allow use of -shell-escape in converters and
|
||||
# do not change handling the use of external programs
|
||||
############################################################
|
||||
|
||||
BEGIN {
|
||||
unshift(@INC, "@CMAKE_CURRENT_SOURCE_DIR@");
|
||||
}
|
||||
|
||||
use prefTest;
|
||||
|
||||
my $bindir = "@CMAKE_BINARY_DIR@";
|
||||
|
||||
my $userdir = "$bindir/Testing/.lyx";
|
||||
|
||||
sub createConvLine($);
|
||||
sub getConverters($);
|
||||
sub getConverter($);
|
||||
sub getNext($);
|
||||
|
||||
my %allowedKeys = (
|
||||
"use_converter_needauth_forbidden" => ["true", "false"],
|
||||
"use_converter_needauth" => ["true", "false"],
|
||||
@ -29,85 +40,36 @@ chdir($bindir);
|
||||
|
||||
my %Subst = ();
|
||||
|
||||
my $ctestparams = 0;
|
||||
my @ctestpars = ();
|
||||
|
||||
&getConverters($userdir);
|
||||
|
||||
for my $arg ("allow_geometry_session=false", @ARGV) {
|
||||
if ($ctestparams) {
|
||||
push(@ctestpars, $arg);
|
||||
}
|
||||
else {
|
||||
if ($arg =~ /^([^=]+)=(.*)$/) {
|
||||
my $key = $1;
|
||||
my $value = $2;
|
||||
my $valid = 0;
|
||||
if (defined($allowedKeys{$key})) {
|
||||
for my $val (@{$allowedKeys{$key}}) {
|
||||
if ($val eq $value) {
|
||||
$valid = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($valid) {
|
||||
$Subst{$key} = [$value, 0];
|
||||
}
|
||||
else {
|
||||
die("invalid key or value specified in \"$arg\"");
|
||||
}
|
||||
}
|
||||
else {
|
||||
$ctestparams = 1;
|
||||
push(@ctestpars, $arg);
|
||||
}
|
||||
}
|
||||
my $shell_escapes = 1;
|
||||
my $handle_argv = "";
|
||||
if (defined($ARGV[0]) && ($ARGV[0] =~ /^(test|default)$/)) {
|
||||
$handle_argv = $1;
|
||||
shift(@ARGV);
|
||||
}
|
||||
|
||||
if (%Subst) { # Try to do something only if a substitute is requested
|
||||
if (open(FO, '>', "$userdir/preferences.tmp")) {
|
||||
if (open(FI, "$userdir/preferences")) {
|
||||
while (my $l = <FI>) {
|
||||
for my $k (keys %Subst) {
|
||||
if ($l =~ /^\\$k\b/) {
|
||||
$l = "\\$k $Subst{$k}->[0]\n";
|
||||
$Subst{$k}->[1] = 1;
|
||||
}
|
||||
elsif ($l =~ /^\\converter\s+(.*)$/) {
|
||||
my $entry = &getConverter($1);
|
||||
if (defined($entry)) {
|
||||
my $key = $entry->[0];
|
||||
if (defined($Converter{$key})) {
|
||||
if (defined($Converter{$key}->[2])) {
|
||||
$l = "";
|
||||
}
|
||||
else {
|
||||
$Converter{$key}->[2] = 1;
|
||||
$l = &createConvLine($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
print FO $l;
|
||||
}
|
||||
}
|
||||
for my $k (keys %Subst) {
|
||||
if ($Subst{$k}->[1] == 0) {
|
||||
print FO "\\$k $Subst{$k}->[0]\n";
|
||||
}
|
||||
}
|
||||
for my $key (keys %Converter) {
|
||||
if (! defined($Converter{$key}->[2])) {
|
||||
$Converter{$key}->[2] = 1;
|
||||
my $l = &createConvLine($key);
|
||||
print FO $l;
|
||||
}
|
||||
}
|
||||
rename("$userdir/preferences.tmp", "$userdir/preferences");
|
||||
}
|
||||
if ($handle_argv eq "test") {
|
||||
@ctestpars = &getSubstitutes(\%allowedKeys, \%Subst,
|
||||
"allow_geometry_session=false",
|
||||
"use_converter_needauth_forbidden=false",
|
||||
"use_converter_needauth=false", @ARGV);
|
||||
}
|
||||
elsif ($handle_argv eq "default") {
|
||||
$shell_escapes = 0;
|
||||
@ctestpars = &getSubstitutes(\%allowedKeys, \%Subst,
|
||||
"allow_geometry_session=false",
|
||||
"use_converter_needauth_forbidden=true",
|
||||
"use_converter_needauth=true", @ARGV);
|
||||
}
|
||||
else {
|
||||
@ctestpars = &getSubstitutes(\%allowedKeys, \%Subst,
|
||||
"allow_geometry_session=false", @ARGV);
|
||||
}
|
||||
|
||||
&getConverters($userdir, \%Converter, $shell_escapes);
|
||||
|
||||
&applyChanges($userdir, \%Subst, \%Converter, $shell_escapes);
|
||||
|
||||
my $res = 0;
|
||||
if (@ctestpars) {
|
||||
@ -116,66 +78,3 @@ if (@ctestpars) {
|
||||
|
||||
exit($res);
|
||||
|
||||
sub createConvLine($)
|
||||
{
|
||||
my ($key) = @_;
|
||||
my $l = "\\converter $key \"$Converter{$key}->[0]\" \"$Converter{$key}->[1]\"\n";
|
||||
return($l);
|
||||
}
|
||||
|
||||
sub getConverters($)
|
||||
{
|
||||
my ($userdir) = @_;
|
||||
|
||||
if (open(FI, "$userdir/lyxrc.defaults")) {
|
||||
while (my $l = <FI>) {
|
||||
if ($l =~ s/^\s*\\converter\s+//) {
|
||||
my $entry = &getConverter($l);
|
||||
if (defined($entry)) {
|
||||
$Converter{$entry->[0]} = $entry->[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub getConverter($)
|
||||
{
|
||||
my ($l) = @_;
|
||||
chomp($l);
|
||||
my ($from, $to, $cmd, $par);
|
||||
($l, $from) = getNext($l);
|
||||
return undef if ($from !~ /tex$/);
|
||||
($l, $to) = getNext($l);
|
||||
return undef if ($to !~ /^(dvi|dvi3|pdf|pdf[23456])$/);
|
||||
($l, $cmd) = getNext($l);
|
||||
if ($cmd !~ /\-shell-escape/) {
|
||||
if ($cmd =~ /^(\S+)\s*(.*)$/) {
|
||||
$cmd = "$1 -shell-escape $2";
|
||||
$cmd =~ s/\s+$//;
|
||||
}
|
||||
}
|
||||
($l, $par) = getNext($l);
|
||||
return undef if ($par !~ /^latex/);
|
||||
my $key = "\"$from\" \"$to\"";
|
||||
return([$key, [$cmd, $par]]);
|
||||
}
|
||||
|
||||
sub getNext($)
|
||||
{
|
||||
my ($l) = @_;
|
||||
my $val = undef;
|
||||
|
||||
if ($l =~ /^\s*\"([^\"]*)\"\s*(.*)$/) {
|
||||
$val = $1;
|
||||
$l = $2;
|
||||
}
|
||||
elsif ($l =~ /^\s*(\S+)\s*(.*)$/) {
|
||||
$val = $1;
|
||||
$l = $2;
|
||||
}
|
||||
else {
|
||||
exit(7);
|
||||
}
|
||||
return($l, $val);
|
||||
}
|
||||
|
196
lib/scripts/prefTest.pm
Normal file
196
lib/scripts/prefTest.pm
Normal file
@ -0,0 +1,196 @@
|
||||
# -*- mode: perl; -*-
|
||||
package prefTest;
|
||||
|
||||
our(@EXPORT, @ISA);
|
||||
BEGIN {
|
||||
use Exporter ();
|
||||
@ISA = qw(Exporter);
|
||||
@EXPORT = qw(getSubstitutes getConverters applyChanges);
|
||||
}
|
||||
|
||||
sub getSubstitutes($$@);
|
||||
sub getConverters($$$);
|
||||
sub getConverter($$);
|
||||
sub getNext($);
|
||||
sub writeConverters($$);
|
||||
|
||||
sub getSubstitutes($$@)
|
||||
{
|
||||
my ($rAllowedKeys, $rSubst, @args) = @_;
|
||||
|
||||
my @ctestpars = ();
|
||||
my $ctestparams = 0;
|
||||
for my $arg (@args) {
|
||||
if ($ctestparams) {
|
||||
push(@ctestpars, $arg);
|
||||
}
|
||||
else {
|
||||
if ($arg =~ /^([^=]+)=(.*)$/) {
|
||||
my $key = $1;
|
||||
my $value = $2;
|
||||
my $valid = 0;
|
||||
if (defined($rAllowedKeys->{$key})) {
|
||||
for my $val (@{$rAllowedKeys->{$key}}) {
|
||||
if ($val eq $value) {
|
||||
$valid = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($valid) {
|
||||
$rSubst->{$key} = [$value, 0];
|
||||
}
|
||||
else {
|
||||
die("invalid key or value specified in \"$arg\"");
|
||||
}
|
||||
}
|
||||
else {
|
||||
$ctestparams = 1;
|
||||
push(@ctestpars, $arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
return(@ctestpars);
|
||||
}
|
||||
|
||||
sub getConverters($$$)
|
||||
{
|
||||
my ($userdir, $rConverter, $add) = @_;
|
||||
|
||||
if (open(FI, "$userdir/lyxrc.defaults")) {
|
||||
while (my $l = <FI>) {
|
||||
if ($l =~ s/^\s*\\converter\s+//) {
|
||||
my $entry = &getConverter($l, $add);
|
||||
if (defined($entry)) {
|
||||
$rConverter->{$entry->[0]} = $entry->[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
close(FI);
|
||||
}
|
||||
}
|
||||
|
||||
sub getConverter($$)
|
||||
{
|
||||
my ($l, $add) = @_;
|
||||
chomp($l);
|
||||
my ($from, $to, $cmd, $par);
|
||||
($l, $from) = getNext($l);
|
||||
return undef if ($from !~ /tex$/);
|
||||
($l, $to) = getNext($l);
|
||||
return undef if ($to !~ /^(dvi3?|pdf[23456]?)$/);
|
||||
($l, $cmd) = getNext($l);
|
||||
if ($add) {
|
||||
if ($cmd !~ /\-shell-escape/) {
|
||||
if ($cmd =~ /^(\S+)\s*(.*)$/) {
|
||||
$cmd = "$1 -shell-escape $2";
|
||||
$cmd =~ s/\s+$//;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$cmd =~ s/\s+\-shell\-escape//;
|
||||
}
|
||||
($l, $par) = getNext($l);
|
||||
return undef if ($par !~ /^latex/);
|
||||
my $key = "\"$from\" \"$to\"";
|
||||
if ($add) {
|
||||
return([$key, [$cmd, $par]]);
|
||||
}
|
||||
else {
|
||||
# Removes entry from prefs
|
||||
return([$key, [$cmd, $par, 1]]);
|
||||
}
|
||||
}
|
||||
|
||||
sub getNext($)
|
||||
{
|
||||
my ($l) = @_;
|
||||
my $val = undef;
|
||||
|
||||
if ($l =~ /^\s*\"([^\"]*)\"\s*(.*)$/) {
|
||||
$val = $1;
|
||||
$l = $2;
|
||||
}
|
||||
elsif ($l =~ /^\s*(\S+)\s*(.*)$/) {
|
||||
$val = $1;
|
||||
$l = $2;
|
||||
}
|
||||
else {
|
||||
exit(7);
|
||||
}
|
||||
return($l, $val);
|
||||
}
|
||||
|
||||
sub writeConverters($$)
|
||||
{
|
||||
my ($fo, $rConverter) = @_;
|
||||
for my $key (sort keys %{$rConverter}) {
|
||||
if (! defined($rConverter->{$key}->[2])) {
|
||||
$rConverter->{$key}->[2] = 1;
|
||||
my $l = &createConvLine($key, $rConverter);
|
||||
print $fo $l;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub createConvLine($$)
|
||||
{
|
||||
my ($key, $rConverter) = @_;
|
||||
my $l = "\\converter $key \"$rConverter->{$key}->[0]\" \"$rConverter->{$key}->[1]\"\n";
|
||||
return($l);
|
||||
}
|
||||
|
||||
sub applyChanges($$$$)
|
||||
{
|
||||
my ($userdir, $rSubst, $rConverter, $add) = @_;
|
||||
|
||||
if (open(FO, '>', "$userdir/preferences.tmp")) {
|
||||
if (open(FI, "$userdir/preferences")) {
|
||||
my $conv_section = -1;
|
||||
while (my $l = <FI>) {
|
||||
if ($conv_section-- == 0) {
|
||||
&writeConverters(*FO, $rConverter);
|
||||
}
|
||||
if ($l =~ /^\# CONVERTERS SECTION/) {
|
||||
$conv_section = 2; # converters begin 2 lines later
|
||||
}
|
||||
if ($l =~ /^\\converter\s+(.*)$/) {
|
||||
my $entry = &getConverter($1, $add);
|
||||
if (defined($entry)) {
|
||||
my $key = $entry->[0];
|
||||
if (defined($rConverter->{$key})) {
|
||||
if (defined($rConverter->{$key}->[2])) {
|
||||
$l = "";
|
||||
}
|
||||
else {
|
||||
$rConverter->{$key}->[2] = 1;
|
||||
$l = &createConvLine($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for my $k (keys %{$rSubst}) {
|
||||
if ($l =~ /^\\$k\b/) {
|
||||
$l = "\\$k $rSubst->{$k}->[0]\n";
|
||||
$rSubst->{$k}->[1] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
print FO $l;
|
||||
}
|
||||
close(FI);
|
||||
}
|
||||
for my $k (keys %{$rSubst}) {
|
||||
if ($rSubst->{$k}->[1] == 0) {
|
||||
print FO "\\$k $rSubst->{$k}->[0]\n";
|
||||
}
|
||||
}
|
||||
&writeConverters(*FO, $rConverter);
|
||||
close(FO);
|
||||
rename("$userdir/preferences.tmp", "$userdir/preferences");
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
Loading…
Reference in New Issue
Block a user