]> git.lyx.org Git - features.git/commitdiff
keytests: New script to replace 'pcregrep' in more complex cases.
authorKornel Benko <kornel@lyx.org>
Sun, 14 May 2017 16:57:25 +0000 (18:57 +0200)
committerKornel Benko <kornel@lyx.org>
Sun, 14 May 2017 16:58:55 +0000 (18:58 +0200)
Suppose, we want to test a key sequence which should produce
logs in defined sequence. ATM, we use pcregrep to see, if
a pattern occurs in the log-file. This is OK, if using only single
tests with only one message to care about.
But it is not OK for combined tests.
As an example, the file 'findadv-combine-in.txt' is combining
tests findadv-re-01-in.txt, findadv-re-02-in.txt and findadv-re-03-in.txt.
This test runns here about 25 seconds, while the time for the other three
is about 144 secs.
(Most time is with starting/stopping lyx)

development/autotests/keytest.py
development/autotests/searchPatterns.pl [new file with mode: 0755]
development/autotests/single-test.cmake
development/autotests/single-test.sh

index f9cd929b4e84b335b63061f49da4e6925b5ec258..53d02652e79e9058ab4c2c98c051c4ccfc138e76 100755 (executable)
@@ -413,6 +413,12 @@ max_loops = os.environ.get('MAX_LOOPS')
 if max_loops is None:
     max_loops = 3
 
+extra_path = os.environ.get('EXTRA_PATH')
+if not extra_path is None:
+  os.environ['PATH'] = extra_path + os.pathsep + os.environ['PATH']
+  print("Added " + extra_path + " to path")
+  print(os.environ['PATH'])
+
 PACKAGE = os.environ.get('PACKAGE')
 if not PACKAGE is None:
   print("PACKAGE = " + PACKAGE + "\n")
@@ -448,7 +454,7 @@ if locale_dir is None:
 def_delay = os.environ.get('XVKBD_DELAY')
 if def_delay is None:
     if qt_frontend == 'QT5':
-        def_delay = '5'
+        def_delay = '1'
     else:
         def_delay = '1'
 
diff --git a/development/autotests/searchPatterns.pl b/development/autotests/searchPatterns.pl
new file mode 100755 (executable)
index 0000000..0fa0d93
--- /dev/null
@@ -0,0 +1,183 @@
+#! /usr/bin/env perl
+# -*- mode: perl; -*-
+#
+# file searchPatterns.pl
+# Uses patterns-file to consecutively process given tex-file
+# Command succedes if each pattern matches the file content in given order
+#
+# How to use:
+#
+# searchPatterns.pl patterns=<name of file with patterns> log=<name of file to check against>
+
+use strict;
+use warnings;
+
+sub sexit($);                  # Print synax and exit
+sub readPatterns($);           # Process patterns file
+sub processLogFile($);
+sub convertPattern($);         # escape some chars, (e.g. ']' ==> '\]')
+
+my %options = (
+  "log" => undef,
+  "patterns" => undef,
+    );
+
+my @patterns = ();
+
+for my $arg (@ARGV) {
+  if ($arg eq "-help") {
+    &sexit(0);
+  }
+  if ($arg =~ /^([^=]+)=(.+)$/) {
+    my ($what, $val) = ($1, $2);
+    if (exists($options{$what})) {
+      if (defined($options{$what})) {
+       print "Value for \"$what\" already defined\n";
+       &sexit(1);
+      }
+      $options{$what} = $val;
+    }
+    else {
+      print "Unknown param \"$what\"\n";
+      &sexit(1);
+    }
+  }
+  else {
+    print "Wrong param syntax for \"$arg\"\n";
+    &sexit(1);
+  }
+}
+
+for my $k (keys %options) {
+  if (! defined($options{$k})) {
+    &sexit(1);
+  }
+  if (! -r $options{$k}) {
+    print "File \"$options{$k}\" is not readable\n";
+    &sexit(1);
+  }
+}
+
+# Read patterns
+&readPatterns($options{"patterns"});
+if (&processLogFile($options{"log"}) > 0) {
+  print "Errors occured, exiting\n";
+  exit(1);
+}
+
+exit(0);
+
+sub syntax()
+{
+  print "Syntax:\n";
+  print " $0";
+  for my $k (keys %options) {
+    print " $k=<filename>";
+  }
+  print "\n";
+}
+
+sub sexit($)
+{
+  my ($exval) = @_;
+  &syntax();
+  exit($exval);
+}
+
+sub convertPattern($)
+{
+  # Convert all chars '[]()+'
+  my ($pat) = @_;
+  if ($pat eq "") {
+    return("");
+  }
+  if ($pat =~ /^(.*)([\[\]\(\)\+\^\{\}])(.*)$/) {
+    my ($first, $found, $third) = ($1, $2, $3);
+    $first = &convertPattern($first);
+    $third = &convertPattern($third);
+    return($first . "\\$found" . $third);
+  }
+  # Substitue white spaces
+  while ($pat =~ s/[\s]+/\\s\+/) {};
+  return($pat);
+}
+
+sub readPatterns($)
+{
+  my ($patfile) = @_;
+
+  if (open(FP, $patfile)) {
+    while (my $p = <FP>) {
+      chomp($p);
+      $p = &convertPattern($p);
+      push(@patterns, $p);
+    }
+    close(FP);
+  }
+}
+
+sub processLogFile($)
+{
+  my ($log) = @_;
+  my $prevl = "\n";
+
+  my $found;
+  my $errors = 1;
+  my @savedlines = ();
+  my $readsavedlines = 0;
+  my $savedline;
+  if (open(FL, $log)) {
+    $errors = 0;
+    my $line = 0;
+    for my $pat (@patterns) {
+      #print "Searching for \"$pat\"\n";
+      $found = 0;
+      my @lines = ();
+      if ($readsavedlines) {
+       # Last regex not found
+       @lines = @savedlines;
+       @savedlines = ();
+       $line = $savedline;
+      }
+      else {
+       $savedline = $line;
+      }
+      while (1) {
+       my $l;
+       if ($readsavedlines) {
+         $l = shift(@lines);
+       }
+       else {
+         $l = <FL>;
+       }
+       last if (! $l);
+       my $check = $prevl . $l;
+       $prevl = $l;
+       $line++;
+       if ($check =~ /$pat/) {
+         print "$line:\tfound \"$pat\"\n";
+         $found = 1;
+         $prevl = "\n";        # Don't search this line again
+         if ($readsavedlines) {
+           @savedlines = @lines;
+         }
+         else {
+           @savedlines = ();
+         }
+         $savedline = $line;
+         last;
+       }
+       else {
+         push(@savedlines, $l);
+       }
+      }
+      if (! $found) {
+       $errors++;
+       print "\tNOT found \"$pat\" in remainder of file\n";
+       $readsavedlines = 1;
+      }
+    }
+    close(FL);
+  }
+  return($errors);
+}
index 0528666010a8c8674de2fe5abfb7860540da9098..871bf11540cf6258d26c85c6b15336837785d6b2 100755 (executable)
@@ -70,6 +70,7 @@ if(EXISTS "${LYX_TESTS_USERDIR}/session")
   execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f "${LYX_TESTS_USERDIR}/session")
 endif()
 # Environments needed by keytest.py
+set(ENV{EXTRA_PATH} "${AUTOTEST_ROOT}")
 set(ENV{PACKAGE} ${PACKAGE})
 set(ENV{LOCALE_DIR} ${LOCALE_DIR})
 set(ENV{LYX_LOCALEDIR} "${LOCALE_DIR}")
index bb0ed2a7c6f20d881a5d5ed7d11c7c7d59f361d8..326cb45be923892d5515c11a507a1b2a2414e5ad 100755 (executable)
@@ -32,6 +32,7 @@ echo LYX_WINDOW_NAME=$LYX_WINDOW_NAME
 
 export MAX_LOOPS=1
 export LYX_EXE=${LYX_EXE:-../../src/lyx}
+export EXTRA_PATH=`pwd`
 
 if [ "$XVKBD_HACKED" != "" ]; then
     export XVKBD_EXE=${XVKBD_EXE:-./xvkbd/xvkbd};