Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Preserve DPUTS output in comptest-based tests
- X-seq: zsh-workers 54805
- From: Philippe Altherr <philippe.altherr@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Preserve DPUTS output in comptest-based tests
- Date: Thu, 18 Jun 2026 20:51:24 +0200
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=ygickD11y9aHnWx55lmUsa5RSz13XxAkhGsu9Giq2/o=; fh=vuDAGjptCPc/P1/HEZ3j98yPJEW1XjuEoEAmmwDS/+U=; b=PqwRbbJrG6n8Bgws+EDjkylqs8jiAC82XtuWgb4pYanYlGl9JYfxPLSj3kukA/VhOw GeCxkZpRupSQ6eGVpuf621Jfxg9V+kbpbFqS/mcXhIE4ObF0WEqr55Pjg8CRmLaHwe5f uDhcRX87oM4za2uQ6vge5y1fbRqZZjAeC6NJmDAnpK/WON2ec8vV4PjL9yPtO82FxZ00 WtiWdY0KoFVUWw/USVL88cCDofu3X2MHdWWBEhqb1ThbeGS3WKy2IHwWnNf2Df890PIU bMGwyAKGjpHA7oLyygxPvqv4JUBHtK3O3THAE19XJh5OnaVQdvG0NUoomtdC68vMzyJJ SJfg==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1781808697; cv=none; d=google.com; s=arc-20240605; b=DB6+PIDL/4ll4Lkqq8pb9rvTXZT2aUKSLPmcWJXd9uS+2mWoZB9siMw6lzPeFG6yfu fJCRlf37ZvrBELQ6Qt8mcDHDZufme5kwDkXeoZWT+L8XPb/IWgL8zD8QP2AyCCj75imO j4s03sxbaxOAsrGiJMwyfGRir+5GQU5DqLNhJEP+jjsR4V2VHLG1MsdYSvoyF6NJyFya UhnYMwuwz96l7LXXNIk/HG/SxlPBhpvYEH93qqSTJ0mR16l+NSCG2nzm5qJjXhyMG6kh xjIRCQ4ZCu+lZlKacAj6a4iUq3JHWfvAbTG9d3kS5XEmaZNcKqVKXqZeaeoujCzZouoC h9gw==
- Archived-at: <https://zsh.org/workers/54805>
- In-reply-to: <CAGdYchtt=44dgzLK48u3B9fUoNrG8jRK59aiHaV-Jmzuibtj=g@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAGdYcht32_OWShJ-fzd2fZ0XcTdVCu292AWTSquVDKpzHQrhaw@mail.gmail.com> <CAHYJk3TnmE4eRh_K_yEEAS9OPkCOBVgT71Lst2A5LZ7dOZt1AQ@mail.gmail.com> <CAGdYchuXO1BJjTmm+4HODejQftr9HRpFysENt9E-Z--3DTEq8g@mail.gmail.com> <CAH+w=7Z2HM43RE9rnatqm8fxhfMiTk3NseNQrf5LtmFEor2SJw@mail.gmail.com> <CAGdYchtt=44dgzLK48u3B9fUoNrG8jRK59aiHaV-Jmzuibtj=g@mail.gmail.com>
Here is an updated patch where I write the DPUTS messages to stderr. I also added a missing $.
The proposed patch relies on a named reference in the function zpty_handle_dputs. If you think that it's better to avoid that for now, you can apply the second patch on top of it.
Philippe
diff --git a/Test/comptest b/Test/comptest
index 39ad14768..31de475e5 100644
--- a/Test/comptest
+++ b/Test/comptest
@@ -21,7 +21,7 @@ comptestinit () {
export PS1="<PROMPT>"
zpty zsh "$comptest_zsh -f +Z"
- zpty -r zsh log1 "*<PROMPT>*" || {
+ zpty_read log1 "*<PROMPT>*" || {
print "first prompt hasn't appeared."
return 1
}
@@ -99,20 +99,47 @@ bindkey -a "^X" zle-finish
'
}
+# Reads output until the pattern $2 is matched or the end is reached.
+# Detects, prints, and removes any DPUTS messages found in the output.
+# Stores the result in the parameter named $1. Returns 0 iff the
+# pattern was matched.
+zpty_read() {
+ local logvar=$1 pattern=$2
+ zpty -r -m zsh $logvar $pattern
+ local -i result=$?
+ zpty_handle_dputs $logvar
+ return result
+}
+
zpty_flush() {
local junk
if zpty -r -t zsh junk \*; then
+ zpty_handle_dputs junk
(( ZTST_verbose > 2 )) && print -n -u $ZTST_fd "$*: ${(V)junk}"
while zpty -r -t zsh junk \* ; do
+ zpty_handle_dputs junk
(( ZTST_verbose > 2 )) && print -n -u $ZTST_fd "${(V)junk}"
done
(( ZTST_verbose > 2 )) && print -u $ZTST_fd ''
fi
}
+# Detects, prints as "DPUTS:{<message>}\n", and removes any DPUTS
+# messages found in the parameter named $1.
+zpty_handle_dputs() {
+ local -nu log=$1
+ local -i lastend=0
+ while (( ${(N)${log[lastend+1,-1]}#*(#b)((<->:|) *.c:<->: *[$'\r\n'])} )); do
+ print -u2 -r "DPUTS:{${match[1][1,-2]}}"
+ log[lastend+$mbegin[1],lastend+$mend[1]]=""
+ [[ $log[lastend+$mbegin[1]] != $'\n' ]] || log[lastend+$mbegin[1]]=""
+ lastend+=$mbegin[1]
+ done
+}
+
zpty_run() {
zpty -w zsh "$*"
- zpty -r -m zsh log "*<PROMPT>*" || {
+ zpty_read log "*<PROMPT>*" || {
print "prompt hasn't appeared."
return 1
}
@@ -130,7 +157,7 @@ comptesteval () {
# zpty_flush Before comptesteval
zpty -w zsh ". ${(q)tmp}"
- zpty -r -m zsh log_eval "*<PROMPT>*" || {
+ zpty_read log_eval "*<PROMPT>*" || {
print "prompt hasn't appeared."
return 1
}
@@ -144,7 +171,7 @@ comptesteval () {
comptest () {
input="$*"
zpty -n -w zsh "$input"$'\C-Z'
- zpty -r -m zsh log "*<WIDGET><finish>*<PROMPT>*" || {
+ zpty_read log "*<WIDGET><finish>*<PROMPT>*" || {
print "failed to invoke finish widget."
return 1
}
@@ -184,7 +211,7 @@ zletest () {
zpty -n -w zsh "$input"
done
zpty -n -w zsh $'\C-X'
- zpty -r -m zsh log "*<WIDGET><finish>*<PROMPT>*" || {
+ zpty_read log "*<WIDGET><finish>*<PROMPT>*" || {
print "failed to invoke finish widget."
return 1
}
diff --git a/Test/comptest b/Test/comptest
index 31de475e5..2d5b97005 100644
--- a/Test/comptest
+++ b/Test/comptest
@@ -127,12 +127,11 @@ zpty_flush() {
# Detects, prints as "DPUTS:{<message>}\n", and removes any DPUTS
# messages found in the parameter named $1.
zpty_handle_dputs() {
- local -nu log=$1
local -i lastend=0
- while (( ${(N)${log[lastend+1,-1]}#*(#b)((<->:|) *.c:<->: *[$'\r\n'])} )); do
+ while (( ${(N)${${(P)1}[lastend+1,-1]}#*(#b)((<->:|) *.c:<->: *[$'\r\n'])} )); do
print -u2 -r "DPUTS:{${match[1][1,-2]}}"
- log[lastend+$mbegin[1],lastend+$mend[1]]=""
- [[ $log[lastend+$mbegin[1]] != $'\n' ]] || log[lastend+$mbegin[1]]=""
+ eval $1'[lastend+$mbegin[1],lastend+$mend[1]]=""'
+ [[ ${${(P)1}[lastend+$mbegin[1]]} != $'\n' ]] || eval $1'[lastend+$mbegin[1]]=""'
lastend+=$mbegin[1]
done
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author