summaryrefslogtreecommitdiffhomepage
path: root/tests/linux/i-fc-tmpdir.sh
blob: a6177b0cdd3b842456a296549046a835e4d6c915 (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
# 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'