summaryrefslogtreecommitdiffhomepage
path: root/tests/linux/i-vi-edit.sh
blob: c78756a906fd5ce005f5f958d0dffb2a90c5e31e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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