zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Commit 137b15a fails X02zlevi test
Date: Mon, 10 Feb 2014 23:37:03 -0800	[thread overview]
Message-ID: <140210233703.ZM11806@torch.brasslantern.com> (raw)
In-Reply-To: <17919.1391985011@quattro>

On Feb 9, 11:30pm, Oliver Kiddle wrote:
} Subject: Re: Commit 137b15a fails X02zlevi test
}
} Bart wrote:
} > I've been repeatedly running
} > 
} >     make check TESTNUM=X02
} > 
} > and have decided that it fails nondeterministically.
} 
} On my desktop it never seems to fail. I just tried on my NAS box and
} it appears to reliably fail there.

After some futher fooling around ... I created this function:

    zpty_flush() {
      local junk
      if zpty -r -t zsh junk \*; then
	print -n -u $ZTST_fd "$*: ${(V)junk}"
	while zpty -r -t zsh junk \*
          do print -n -u $ZTST_fd "${(V)junk}"; done
	print -u $ZTST_fd ''
      fi
    }

and then added calls to that in comptesteval, comptest, and zletest.

For Y02completion, the output looks like this, repeated once per test
with no blank lines:

------------
After comptesteval: ^[[K
After comptest: ^[[K
------------

For X02zlevi, the output is unpredictable, but usually looks like this:

------------
Before zletest: ^[[K
After zletest: end^[[K^M^M

Before zletest: ^[[1m^[[7m%^[[m^[[1m^[[0m
^M ^M
Before comptesteval: text^[[K^M^M
text^[[K^H^M^M

After comptesteval: ^[[K.^H. /tmp/comptest
Before zletest: .27823^M^M

After zletest: after^[[K^M^M
after^[[K^H^M^M

------------

The blank lines are really there, I did not add them for readability.

My conclusion is that being in viins mode causes ZLE to do much more
work updating the display, resulting in some words being overstruck,
extra cursor motions, etc.  Combine this with using "print -lr" to
try to send cursor position, etc., in-band at the end of each test,
and confusion results.  Now, why this would *sometimes* not happen is
quite the mystery -- I would have thought that e.g. the "stty 38400"
thrown in there would make it behave at least consistently, but no.

The one that reads

After comptesteval: ^[[K.^H. /tmp/comptest
Before zletest: .27823^M^M

is quite interesting, because it indicates that the prompt is being
redrawn in the midst of the string ". /tmp/comptest.27823" which is
written to the pty by comptesteval and expected to be executed as a
command.  I think that has to do with using \C-M as the binding for
zle-finish.

The following reformulation works more than 90% of the time for me,
but still fails occasionally, and still not always on the same test.

If I remove "zle -I", it becomes less reliable.

If I remove "zle redisplay" it fails every time.

If I change the zle-finish binding back to ^M it fails every time.

Calling zpty_flush in comptest is not really needed ... by I don't
know why it's not needed there, which bothers me.


diff --git a/Test/comptest b/Test/comptest
index f1c5af0..4a23e89 100644
--- a/Test/comptest
+++ b/Test/comptest
@@ -69,12 +69,15 @@ comp-finish () {
   zle -R
 }
 zle-finish () {
-  print -lr "<WIDGET><finish>" "BUFFER: $BUFFER" "CURSOR: $CURSOR"
-  (( region_active )) && print -lr "MARK: $MARK"
-  zle -K main
+  local buffer="$BUFFER" cursor="$CURSOR" mark="$MARK"
+  (( region_active)) || unset mark
+  BUFFER=""
+  zle -I
   zle clear-screen
-  zle send-break
-  zle -R
+  zle redisplay
+  print -lr "<WIDGET><finish>" "BUFFER: $buffer" "CURSOR: $cursor"
+  (( $+mark )) && print -lr "MARK: $mark"
+  zle accept-line
 }
 zle -N expand-or-complete-with-report
 zle -N list-choices-with-report
@@ -83,30 +86,45 @@ zle -N zle-finish
 bindkey "^I" expand-or-complete-with-report
 bindkey "^D" list-choices-with-report
 bindkey "^Z" comp-finish
-bindkey "^M" zle-finish
-bindkey -a "^M" zle-finish
+bindkey "^X" zle-finish
+bindkey -a "^X" zle-finish
 '
 }
 
+zpty_flush() {
+  local junk
+  if zpty -r -t zsh junk \*; then
+    (( ZTST_verbose > 2 )) && print -n -u $ZTST_fd "$*: ${(V)junk}"
+    while zpty -r -t zsh junk \* ; do
+      (( ZTST_verbose > 2 )) && print -n -u $ZTST_fd "${(V)junk}"
+    done
+    (( ZTST_verobse > 2 )) && print -u $ZTST_fd ''
+  fi
+}
+
 comptesteval () {
   local tmp=/tmp/comptest.$$
 
   print -lr - "$@" > $tmp
+  zpty_flush Before comptesteval
   zpty -w zsh ". $tmp"
   zpty -r -m zsh log_eval "*<PROMPT>*" || {
     print "prompt hasn't appeared."
     return 1
   }
+  zpty_flush After comptesteval
   rm $tmp
 }
 
 comptest () {
   input="$*"
+  zpty_flush Before comptest
   zpty -n -w zsh "$input"$'\C-Z'
   zpty -r -m zsh log "*<WIDGET><finish>*<PROMPT>*" || {
     print "failed to invoke finish widget."
     return 1
   }
+  zpty_flush After comptest
 
   logs=(${(s:<WIDGET>:)log})
   shift logs
@@ -136,10 +154,12 @@ comptest () {
 
 zletest () {
   input="$*"
-  zpty -n -w zsh "$input"$'\C-M'
+  zpty_flush Before zletest
+  zpty -n -w zsh "$input"$'\C-X'
   zpty -r -m zsh log "*<WIDGET><finish>*<PROMPT>*" || {
     print "failed to invoke finish widget."
     return 1
   }
+  zpty_flush After zletest
   print -lr "${(@)${(ps:\r\n:)log##*<WIDGET><finish>}[1,-2]}"
 }


  reply	other threads:[~2014-02-11  7:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-08 20:13 Bart Schaefer
2014-02-08 22:45 ` Bart Schaefer
2014-02-09 18:53   ` Bart Schaefer
2014-02-09 21:00     ` Peter Stephenson
2014-02-09 22:30     ` Oliver Kiddle
2014-02-11  7:37       ` Bart Schaefer [this message]
2014-02-13  5:49         ` Bart Schaefer
2014-02-13  9:32           ` Peter Stephenson
2014-02-13 16:17           ` Jun T.
2014-02-13 17:39             ` Bart Schaefer
2014-02-14 15:59               ` Jun T.
2014-02-15  1:42                 ` Bart Schaefer
2014-02-15 17:07                   ` Jun T.
2014-02-15 21:35                     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=140210233703.ZM11806@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).