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

Re: Adding tests for zle? The missing X series tests

On Dec 20,  8:20am, Felix Rosencrantz wrote:
} There are no zle tests, though the letter X was reserved for
} zle tests.  I was wondering if anyone had thought about how this might
} be done.

I have thought a bit about this in the past and I think there may be a
sort of brute-force way to do it.  It wouldn't work for everything, but
it should work for most simple ZLE edits and for incremental search in

First you'd need to set up a zpty session like the completion tests do.
Make sure to give it adequate dimensions so ZLE scrolling does not kick
in (unless that's what you're testing, I guess).

Next you set PS1 to a recognizable string and clear RPS1 etc.  For some
tests you'd might want a recognizable PS2 as well, but for incremental
search it wouldn't be necessary.

Finally you arrange that clear-screen is bound to a well-known keystroke
(the defaut of ctrl-L is probably fine).

Now you're ready to test.  Start sending keystrokes to the zpty and
read back (and probably discard) the zpty output as you do so.  At
the point where you want to check the result, send clear-screen, which
causes the whole screen to be redrawn (even during incremental search)
including the PS1 prompt.  This repaint should result in pretty much a
linear dump of the editor buffers with few or no cursor movements after
the initial screen clear.

Consequently your next zpty read after the clear-screen can scan for
the PS1 string you set previously, in order to skip over the terminal
control output, and then slurp up everything else that was printed and
compare to what you expected to find.

(A quick check using the script command to capture output indicates that
there is a clear-to-end-of-line emitted at the end of each line of the
output, but that should be relatively easy to ignore when parsing.)

This won't uncover terminal-handling bugs like unexpected line wraps at
the last line/column, but it should be able to verify e.g. the search is
finding the right thing at each incremental step.

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