From 5dbe57b3d6c146ea938baaa5600b0232ed70b80c Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Sat, 3 Dec 2016 11:32:19 +0100 Subject: [PATCH] Cmake tests: Add a script to modify preferences prior to export testing --- lib/scripts/CMakeLists.txt | 1 + lib/scripts/prefTest.pl.in | 82 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100755 lib/scripts/prefTest.pl.in diff --git a/lib/scripts/CMakeLists.txt b/lib/scripts/CMakeLists.txt index a9439b7c51..d39e4fbdb1 100644 --- a/lib/scripts/CMakeLists.txt +++ b/lib/scripts/CMakeLists.txt @@ -9,4 +9,5 @@ if (UNIX) set(_project "scripts") # include(../PyCompile) endif() +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/prefTest.pl.in" "${CMAKE_BINARY_DIR}/prefTest.pl" @ONLY) diff --git a/lib/scripts/prefTest.pl.in b/lib/scripts/prefTest.pl.in new file mode 100755 index 0000000000..08a6c0c2f5 --- /dev/null +++ b/lib/scripts/prefTest.pl.in @@ -0,0 +1,82 @@ +#! /usr/bin/env perl +# -*- mode: perl; -*- + +use strict; + +# Syntax: ReplaceValuesprefTest.pl [= [= ...]] [[ctest parameters]] + +my $bindir = "@CMAKE_BINARY_DIR@"; + +my $userdir = "$bindir/Testing/.lyx"; + +my %allowedKeys = ( + "use_converter_needauth_forbidden" => ["true", "false"], + "use_converter_needauth" => ["true", "false"], + ); + +chdir($bindir); + +# Parse Arguments for strings to substitute + +my %Subst = (); + +my $ctestparams = 0; +my @ctestpars = (); +for my $arg (@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); + } + } +} +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 = ) { + for my $k (keys %Subst) { + if ($l =~ /^\\$k\b/) { + $l = "\\$k $Subst{$k}->[0]\n"; + $Subst{$k}->[1] = 1; + } + } + print FO $l; + } + } + for my $k (keys %Subst) { + if ($Subst{$k}->[1] == 0) { + print FO "\\$k $Subst{$k}->[0]\n"; + } + } + rename("$userdir/preferences.tmp", "$userdir/preferences"); + } +} + +my $res = 0; +if (@ctestpars) { + $res = system("ctest", @ctestpars); +} + +exit($res); -- 2.39.2