From 8f74cac381c286fce559072baf3958cf6643a05b Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Thu, 18 May 2017 13:05:36 +0200 Subject: [PATCH] keytests: Add more controls for the *-in.txt files The controls are described in hello-world-in.txt as Cr: not expected regex search pattern before next expected match Cp: not expected search pattern before next expected match See also findadv-re-04-in.txt for an example In this test-case, searching for case sensitive and format considering search is failing. --- development/autotests/findadv-re-04-in.txt | 61 +++++++++++++++++++++- development/autotests/keytest.py | 6 ++- development/autotests/searchPatterns.pl | 53 +++++++++++++++++-- 3 files changed, 113 insertions(+), 7 deletions(-) diff --git a/development/autotests/findadv-re-04-in.txt b/development/autotests/findadv-re-04-in.txt index 36f4137eea..ae1ef42db6 100644 --- a/development/autotests/findadv-re-04-in.txt +++ b/development/autotests/findadv-re-04-in.txt @@ -1,14 +1,71 @@ # Finding styles with regexp Lang sk_SK.utf8 +CO: findadv-re-04.ctrl +CN: Part 1 +CP: Init key TestBegin test.lyx -dbg key,find > findadv-re-04.loga.txt 2>&1 -KK: Hello \CeHello\C\[Home] +CP: Key (queried) [action=buffer-begin][Ctrl+Home] +KK: The quick Brown \CeFox JUmps\Ce over the lazy Dog\[Return] +KK: \C\[Home] KK: \Cs KK: \CF # Uncheck ignore format (depends on IT language) KK: \At\Ai\Ah KK: \Ce +CN: Case insensitive, format not ignored .* KK: \Axregexp-mode\[Return].*\[Return] +Cr: ^.*Putting +CP: Putting selection at .*idx: 0 par: 0 pos: 16\n with len: 9 +TestEnd + +CO: >> findadv-re-04.ctrl +CN: Part 2 +CP: Init key +TestBegin test.lyx -dbg key,find >> findadv-re-04.loga.txt 2>&1 +CN: Case insensitive, format not ignored [a-z]* +KK: \CF +# Uncheck ignore format (depends on IT language) +KK: \At\Ai\Ah +KK: \Ce +KK: \Axregexp-mode\[Return][a-z]*\[Return]\[Return]\[Return] +Cr: ^.*Putting +CP: Putting selection at .*idx: 0 par: 0 pos: 16\n with len: 3 +Cr: ^.*Putting +CP: Putting selection at .*idx: 0 par: 0 pos: 20\n with len: 5 +TestEnd + +CO: >> findadv-re-04.ctrl +CN: Part 3 +CP: Init key +TestBegin test.lyx -dbg key,find >> findadv-re-04.loga.txt 2>&1 + +CN: Case sensitive, format not ignored [a-z]* +KK: \CF +KK: \At\Ai\Ah +KK: \Ce +KK: \Ao\[Tab]\Axregexp-mode\[Return][a-z]*\[Return]\[Return]\[Return]\[Return]\[Return]\[Return]\[Return] +Cr: ^.*Putting +CP: Putting selection at .*idx: 0 par: 0 pos: 17\n with len: 2 +Cr: ^.*Putting +Cr: ^.*Init key +CP: Putting selection at .*idx: 0 par: 0 pos: 22\n with len: 3 +TestEnd + +CO: >> findadv-re-04.ctrl +CN: Part 4 +CP: Init key +TestBegin test.lyx -dbg key,find >> findadv-re-04.loga.txt 2>&1 + +CN: Case sensitive, format not ignored [A-Z]* +KK: \CF +KK: \At\Ai\Ah +KK: \Ce +KK: \Ao\[Tab]\Axregexp-mode\[Return][A-Z]*\[Return]\[Return]\[Return]\[Return]\[Return] +Cr: ^.*Putting +CP: Putting selection at .*idx: 0 par: 0 pos: 16\n with len: 1 +Cr: ^.*Putting +CP: Putting selection at .*idx: 0 par: 0 pos: 20\n with len: 2 TestEnd Lang C -Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 6\n with len: 5' findadv-re-04.loga.txt +Assert searchPatterns.pl log=findadv-re-04.loga.txt patterns=findadv-re-04.ctrl diff --git a/development/autotests/keytest.py b/development/autotests/keytest.py index 67bb3ca152..2edd86b1b6 100755 --- a/development/autotests/keytest.py +++ b/development/autotests/keytest.py @@ -164,7 +164,7 @@ class CommandSourceFromFile(CommandSource): class ControlFile: def __init__(self): - self.control = re.compile(r'^(C[ONPRC]):\s*(.*)$') + self.control = re.compile(r'^(C[ONPpRrC]):\s*(.*)$') self.fileformat = re.compile(r'^((\>\>?)[,\s]\s*)?([^\s]+)\s*$') self.cntrname = None self.cntrfile = None @@ -220,8 +220,12 @@ class ControlFile: self.__addline("Comment: " + text) elif command == "CP": self.__addline("Simple: " + text) + elif command == "Cp": + self.__addline("ErrSimple: " + text) elif command == "CR": self.__addline("Regex: " + text) + elif command == "Cr": + self.__addline("ErrRegex: " + text) else: die(1,"Error, Unrecognised Command '" + command + "'") return True diff --git a/development/autotests/searchPatterns.pl b/development/autotests/searchPatterns.pl index 7b3acf0f93..73a3572789 100755 --- a/development/autotests/searchPatterns.pl +++ b/development/autotests/searchPatterns.pl @@ -17,6 +17,7 @@ sub readPatterns($); # Process patterns file sub processLogFile($); # sub convertPattern($); # check for regex, comment sub convertSimplePattern($); # escape some chars, (e.g. ']' ==> '\]') +sub printInvalid($$); # display lines which should not match my %options = ( "log" => undef, @@ -92,12 +93,14 @@ sub convertPattern($) return(""); } return $pat if ($pat =~ /^Comment:/); - if ($pat =~ s/^Regex:\s+//) { + if ($pat =~ s/^((Err)?Regex):\s+//) { # PassThrough variant - return($pat); + return($1 . ":" . $pat); } - elsif ($pat =~ s/^Simple:\s+//) { - return convertSimplePattern($pat); + elsif ($pat =~ s/^((Err)?Simple):\s+//) { + my $ermark = $2; + $ermark = "" if (!defined($ermark)); + return $ermark . "Regex:" . &convertSimplePattern($pat); } else { # This should not happen. @@ -168,6 +171,8 @@ sub processLogFile($) if (open(FL, $log)) { $errors = 0; my $line = 0; + my @ErrPatterns = (); + my $minprevlines = 0; for my $pat (@patterns) { if ($pat =~ /^Comment:\s*(.*)$/) { $comment = $1; @@ -177,9 +182,25 @@ sub processLogFile($) } next; } + if ($pat =~ /^(Err)?Regex:(.*)$/) { + my ($type, $regex) = ($1, $2); + next if ($regex eq ""); + if (defined($type)) { + # This regex should not apply until next 'found line' + my $erlines = () = $regex =~ /\\n/g; + $minprevlines = $erlines if ($erlines > $minprevlines); + push(@ErrPatterns, $regex); + next; + } + else { + # This is the pattern which we are looking for + $pat = $regex; + } + } #print "Searching for \"$pat\"\n"; $found = 0; my $prevlines = () = $pat =~ /\\n/g; # Number of lines in pattern + $prevlines = $minprevlines if ($prevlines < $minprevlines); my @prevl = (); for (my $i = 0; $i <= $prevlines; $i++) { push(@prevl, "\n"); @@ -210,6 +231,8 @@ sub processLogFile($) my $check = join("", @prevl); $line++; if ($check =~ /$pat/) { + @ErrPatterns = (); # clean search for not wanted patterns + $minprevlines = 0; my $fline = $line - $prevlines; print "$fline:\tfound \"$pat\"\n"; $found = 1; @@ -228,6 +251,18 @@ sub processLogFile($) } else { push(@savedlines, $l); + # Check for not wanted patterns + my $errindex = 0; + for my $ep (@ErrPatterns) { + if ($check =~ /$ep/) { + $errors++; + my $fline = $line - $prevlines; + printInvalid($fline, $check); + #splice(@ErrPatterns, $errindex, 1); + last; + } + $errindex++; + } } } if (! $found) { @@ -240,3 +275,13 @@ sub processLogFile($) } return($errors); } + +sub printInvalid($$) +{ + my ($line, $check) = @_; + my @chk = split(/\n/, $check); + print("$line:\tInvalid match: " . shift(@chk) . "\n"); + for my $l (@chk) { + print("\t\t\t$l\n"); + } +} -- 2.39.2