File: checkKeys.pl.in

package info (click to toggle)
lyx 2.4.3-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 130,280 kB
  • sloc: cpp: 259,444; ansic: 106,595; xml: 72,791; python: 32,859; sh: 7,176; makefile: 6,144; pascal: 2,129; perl: 2,007; objc: 1,084; tcl: 163; sed: 16
file content (131 lines) | stat: -rw-r--r-- 2,575 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#! /usr/bin/perl
# -*- mode: perl; -*-

# checkKeys.pl testname
#   testname can be anything satisfying the pattern
#            '^(keytest\/|.*autotests\/out-home\/)?([^\/]+)(|\-in\.txt|\.log[a-z]\.txt)$/
#   interesting is only group(2)
#
# Tool to display keystrokes which made it to lyx while tested with
# the lyx-session with '-dbg key'
# Helpful to check where a 'keytest'-testcase failed because
# of some missing/ignored key.

use strict;

my $bindir = "@CMAKE_BINARY_DIR@";
my $resdir = "@LYX_ABS_TOP_SRCDIR@/development/autotests/keyresults";
my $logdir = "$bindir/autotests/out-home";
my $saveflag = 0;
sub checkKeys($);
sub displayKeys($);

for my $arg (@ARGV) {
  if ($arg =~ /^([^=]+)=([^=]+)$/) {
    my ($par, $val) = ($1, $2);
    $saveflag = $val;
  }
  else {
    &checkKeys($arg);
  }
}

exit(0);

sub checkKeys($)
{
  my ($pattern) = @_;
  my @logs = ();

  $pattern =~ s/^(keytest\/|.*autotests\/out-home\/)//;
  $pattern =~ s/(\-in\.txt|\.log[a-z]\.txt)$//;
  return if ($pattern =~ /\//);
  if (opendir(DI, $logdir)) {
    while (my $f = readdir(DI)) {
      if ($f =~ /$pattern.*\.log([a-z])\.txt$/) {
	push(@logs, $f);
      }
    }
    closedir(DI);
  }
  @logs = sort(@logs);
  for my $f (@logs) {
    &displayKeys($f);
  }
}

my $line;
my @exp;

sub checkPrint($) {
  my ($str) = @_;
  my $saved;
  if (defined($exp[$line])) {
    $saved = $exp[$line];
  }
  else {
    $saved = "";
  }
  $exp[$line] = $str;
  $line++;
  if ($saved ne $str) {
    return 1;
  }
  return 0;
}

sub displayKeys($)
{
  my ($e) = @_;
  my $log = "$logdir/$e";
  my $expected = "$resdir/$e.expected";

  @exp = ();
  if (open(FE, $expected)) {
    while (my $l = <FE>) {
      chomp($l);
      push(@exp, $l);
    }
    close(FE);
  }
  else {
    print "Not found file $expected\n";
  }

  my $errors = 0;
  if (open(FI, $log)) {
    $line = 0;
    while (my $l = <FI>) {
      if ($l =~ /:\s+(KeySym\s+is\s+.*)$/) {
	my $out = $1;
	$errors += &checkPrint($out);
      }
      elsif ($l =~ /:\s+(Key\s+\(queried\)\s+\[action=.*)$/) {
	my $out = $1;
	$errors += &checkPrint($out);
      }
    }
    $errors += 1 if (defined($exp[$line]));
    close(FI);
  }
  if ($errors > 0) {
    print "Diff -u $e:\n";
    open(FX, "| diff -u $expected -");
    for (my $i=0; $i < $line; $i++) {
      print FX "$exp[$i]\n";
    }
    close(FX);
    if ($saveflag) {
      print "Overwriting file $expected\n";
      if (open(FO, '>', $expected)) {
	for (my $i=0; $i < $line; $i++) {
	  print FO "$exp[$i]\n";
	}
	close(FO);
      }
    }
  }
  else {
    print "$e OK\n";
  }
}