diff options
| author | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-28 14:16:41 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-28 14:16:41 -0600 |
| commit | 95d31d2d7d5fd7de81d6d5e2caedcdc369ca0fcf (patch) | |
| tree | 4959b8d43268945543be4061b8fccd95d04592b1 /tests/linux | |
| parent | 625908ab56c7c554506d61c83c7001bca19a05f6 (diff) | |
| parent | 6fe2aff8d6611bf45704ba86120efa23950bfa80 (diff) | |
| download | zash-95d31d2d7d5fd7de81d6d5e2caedcdc369ca0fcf.tar.gz | |
Merge pull request #46 from skurtz97/fix/review-2026-11-28
Fixes from the 2026-11-28 code review
Diffstat (limited to 'tests/linux')
| -rw-r--r-- | tests/linux/i-fc-tmpdir.exp | 11 | ||||
| -rw-r--r-- | tests/linux/i-fc-tmpdir.sh | 35 | ||||
| -rw-r--r-- | tests/linux/i-vi-edit.exp | 10 | ||||
| -rw-r--r-- | tests/linux/i-vi-edit.sh | 44 | ||||
| -rw-r--r-- | tests/linux/i-vi.exp | 20 | ||||
| -rw-r--r-- | tests/linux/i-vi.sh | 29 |
6 files changed, 149 insertions, 0 deletions
diff --git a/tests/linux/i-fc-tmpdir.exp b/tests/linux/i-fc-tmpdir.exp new file mode 100644 index 0000000..f0b9bc0 --- /dev/null +++ b/tests/linux/i-fc-tmpdir.exp @@ -0,0 +1,11 @@ +$ echo hello +hello +$ fc -e "$PWD/ed.sh" +echo fc-edited +fc-edited +$ echo vi-edited +vi-edited +$ fc -e 'echo (' +SHELL: syntax error: unexpected 'WORK/tmp dir$x/zash-fc.XXXX' +$ exit +[status 0] diff --git a/tests/linux/i-fc-tmpdir.sh b/tests/linux/i-fc-tmpdir.sh new file mode 100644 index 0000000..a6177b0 --- /dev/null +++ b/tests/linux/i-fc-tmpdir.sh @@ -0,0 +1,35 @@ +# The editor commands fc and vi's `v` put the temporary file name on a +# command line, so a TMPDIR with a space and a `$` in it has to survive +# quoting. Unquoted, the editor got a path cut at the space, and fc ran the +# original commands again. +command -v python3 >/dev/null 2>&1 || exit 77 +mkdir -p 'tmp dir$x' +cat >ed.sh <<'INS' +#!/bin/sh +printf 'echo fc-edited\n' >"$1" +INS +cat >vis.sh <<'INS' +#!/bin/sh +printf 'echo vi-edited\n' >"$1" +INS +chmod +x ed.sh vis.sh +# The syntax error names the temporary file, whose name has the work +# directory and a random suffix in it: fold both, or the .exp could not be +# compared. +{ +TMPDIR="$PWD/tmp dir\$x" PS1='$ ' ENV='' HISTFILE='' VISUAL="$PWD/vis.sh" \ + python3 "$TESTS/tools/ptydrive.py" "$TSH" -o vi <<'END' +send echo hello\r +expect hello +send fc -e "$PWD/ed.sh"\r +expect fc-edited +send echo hi\x1bv\r +expect vi-edited +# An editor command that raises an exception must not leave the file +# behind either: `echo (` is a syntax error, raised past the unlink(). +send fc -e 'echo ('\r +send exit\r +END +} | sed -e "s|$PWD|WORK|g" -e 's/zash-fc\.[A-Za-z0-9]*/zash-fc.XXXX/' +# Neither editor may leave its file behind. +ls -A 'tmp dir$x' diff --git a/tests/linux/i-vi-edit.exp b/tests/linux/i-vi-edit.exp new file mode 100644 index 0000000..fb8d9c1 --- /dev/null +++ b/tests/linux/i-vi-edit.exp @@ -0,0 +1,10 @@ +$ echo visual 'echo one' +visual echo one +$ exit +$ echo edited 'echo two' +edited echo two +$ exit +$ echo keep me +keep me +$ exit +[status 0] diff --git a/tests/linux/i-vi-edit.sh b/tests/linux/i-vi-edit.sh new file mode 100644 index 0000000..c78756a --- /dev/null +++ b/tests/linux/i-vi-edit.sh @@ -0,0 +1,44 @@ +# Interactive: vi's `v` puts the line in $VISUAL, else $EDITOR. +# +# The editor here is a script that writes the line it was given back as a +# new command, so the test sees that the editor ran and what it was +# handed: the line being edited, on its own. +# +# `v` runs the editor through eval_string() while the outer command is +# half parsed, so under `make asan` this is also a regression test for a +# nested eval that frees the parse arena (see posix/trap-midtoken). +command -v python3 >/dev/null 2>&1 || exit 77 +cat >ed.sh <<'INS' +#!/bin/sh +printf "echo edited '%s'\n" "$(cat "$1")" >"$1" +INS +cat >vis.sh <<'INS' +#!/bin/sh +printf "echo visual '%s'\n" "$(cat "$1")" >"$1" +INS +chmod +x ed.sh vis.sh +# $VISUAL wins over $EDITOR, as POSIX says. +PS1='$ ' ENV='' HISTFILE='' EDITOR="$PWD/ed.sh" VISUAL="$PWD/vis.sh" \ + python3 "$TESTS/tools/ptydrive.py" "$TSH" -o vi <<'END' +send echo one\x1bv +send \r +expect visual echo one +send exit\r +END +# With no $VISUAL, $EDITOR is used. +PS1='$ ' ENV='' HISTFILE='' VISUAL='' EDITOR="$PWD/ed.sh" \ + python3 "$TESTS/tools/ptydrive.py" "$TSH" -o vi <<'END' +send echo two\x1b0wv +send \r +expect edited echo two +send exit\r +END +# A failed editor leaves the line alone. +PS1='$ ' ENV='' HISTFILE='' VISUAL='' EDITOR=false \ + python3 "$TESTS/tools/ptydrive.py" "$TSH" -o vi <<'END' +send echo keep me\x1bv +expect echo keep me +send \r +expect keep me +send exit\r +END diff --git a/tests/linux/i-vi.exp b/tests/linux/i-vi.exp index 6e121ed..891cde4 100644 --- a/tests/linux/i-vi.exp +++ b/tests/linux/i-vi.exp @@ -23,5 +23,25 @@ SHELL: ech: not found $ #echo comment $ echo done done +$ echo def +def +$ two three +SHELL: two: not found +$ ZZ ZZ two three +SHELL: ZZ: not found +$ echo yank +yank +$ abcdef +SHELL: abcdef: not found +$ echo bdef +bdef +$ echo apple +apple +$ echo banana +banana +$ echo apple +apple +$ echo apple +apple $ exit [status 0] diff --git a/tests/linux/i-vi.sh b/tests/linux/i-vi.sh index 7e1edaa..d5fb71f 100644 --- a/tests/linux/i-vi.sh +++ b/tests/linux/i-vi.sh @@ -25,5 +25,34 @@ expect ech count send echo comment\x1b# send echo done\r expect done +# `.` repeats the last change, insert mode and all +send echo abcdef\x1b0wx..\r +expect echo def +send echo one two three\x1b0dw.\r +expect two three +send echo one two three\x1b0cwZZ\x1bw.\r +expect ZZ ZZ two three +# `y` over an empty range, with nothing killed yet: nothing is pasted and +# no null buffer reaches memcpy (ASan sees that one). +send \x15echo yank\x1b0y0\r +expect echo yank +# ... and a count repeats it that many times, on top of the change's own +send echo abcdef\x1b0x3.\r +expect abcdef +# a motion is not a change: `.` still repeats the last real one +send echo abcdef\x1b0wx +send l. +send \r +expect echo bdef +# `/` typed over the previous pattern and backspaced to empty repeats the +# previous search, not a mix of the two patterns. +send echo apple\r +expect apple +send echo banana\r +expect banana +send \x1b/apple\r\r +expect echo apple +send \x1b/ban\x7f\x7f\x7f\r\r +expect echo apple send exit\r END |
