Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Tests/X04: use temporary pattern matching for OpenBSD missing leading 0m



On 22 Jan 2019, at 09:27, Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
>phy1729 reports that OpenBSD doesn't include a leading 0m in its
>control codes output. Thus, X04 tests fail on that OS.

The failure is due to $termcap[me] on OpenBSD using \e(B\e[m where the test
expects \e[0m. After normalising to the latter and stripping \e(B from the
output, it passes. Fiddling about with hard-coded escape sequences feels
pretty brittle to me, but i guess that's what we're already doing, so...
hopefully it's at least better than just dropping the sequence entirely.

(I also fixed some white space; included as a separate diff below.)

Tested on macOS and OpenBSD. It passed for Matthew as well.

dana


diff --git a/Test/X04zlehighlight.ztst b/Test/X04zlehighlight.ztst
index e14517490..9e3b2681b 100644
--- a/Test/X04zlehighlight.ztst
+++ b/Test/X04zlehighlight.ztst
@@ -29,6 +29,8 @@
       integer i
       for (( i = 0; i < ${1:-1}; ++i )); do
         zpty -r zsh REPLY
+        # Normalise me/sgr0 to \e[0m. We also need to strip \e(B in zpty_stop()
+        REPLY=${REPLY//${termcap[me]}/$'\x1b[0m'}
         # P is for "preserve", and induces keeping some
         # expected color codes to test region_highlight,
         # etc. - the color codes are made a regular text.
@@ -54,7 +56,7 @@
       # zpty gives no output when piped without these braces (?)
       # The while loop with // substitution is to convert `e^Mexit'
       # into `exit' (see zpty_line). The sed commands remove escapes
-      { zpty -r zsh } | sed -e $'/[^\t\r ]/!d' -e $'s/\r$//' -e $'s/\x1b\\[[0-9;]*m//g' | while read REPLY; do REPLY=${REPLY//(#b)((?(#c0,1))$cm(?(#c0,1)))/${${${(M)match[2]:#${match[3]}}:+${match[2]}}:-${${match[1]##[[:space:]]##}%%[[:space:]]##}}}; print -rn -- "$REPLY"; done
+      { zpty -r zsh } | sed -e $'/[^\t\r ]/!d' -e $'s/\r$//' -e $'s/\x1b\\[[0-9;]*m//g' -e $'s/\x1b([A-Z]//g' | while read REPLY; do REPLY=${REPLY//(#b)((?(#c0,1))$cm(?(#c0,1)))/${${${(M)match[2]:#${match[3]}}:+${match[2]}}:-${${match[1]##[[:space:]]##}%%[[:space:]]##}}}; print -rn -- "$REPLY"; done
       zpty -d
       :
     }

diff --git a/Test/X04zlehighlight.ztst b/Test/X04zlehighlight.ztst
index 9e3b2681b..b6a8c35fd 100644
--- a/Test/X04zlehighlight.ztst
+++ b/Test/X04zlehighlight.ztst
@@ -56,7 +56,12 @@
       # zpty gives no output when piped without these braces (?)
       # The while loop with // substitution is to convert `e^Mexit'
       # into `exit' (see zpty_line). The sed commands remove escapes
-      { zpty -r zsh } | sed -e $'/[^\t\r ]/!d' -e $'s/\r$//' -e $'s/\x1b\\[[0-9;]*m//g' -e $'s/\x1b([A-Z]//g' | while read REPLY; do REPLY=${REPLY//(#b)((?(#c0,1))$cm(?(#c0,1)))/${${${(M)match[2]:#${match[3]}}:+${match[2]}}:-${${match[1]##[[:space:]]##}%%[[:space:]]##}}}; print -rn -- "$REPLY"; done
+      { zpty -r zsh } |
+      sed -e $'/[^\t\r ]/!d' -e $'s/\r$//' -e $'s/\x1b\\[[0-9;]*m//g' -e $'s/\x1b([A-Z]//g' |
+      while read REPLY; do
+        REPLY=${REPLY//(#b)((?(#c0,1))$cm(?(#c0,1)))/${${${(M)match[2]:#${match[3]}}:+${match[2]}}:-${${match[1]##[[:space:]]##}%%[[:space:]]##}}}
+        print -rn -- "$REPLY"
+      done
       zpty -d
       :
     }



Messages sorted by: Reverse Date, Date, Thread, Author