fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes Altmanningertests: filter control sequences only when interactive1e858eae3

master
2.7 KiB91 linesraw
1#RUN: %fish %s
2# Validate some things about command wrapping.
3
4set -g LANG C # For predictable error messages.
5
6# This tests that we do not trigger a combinatorial explosion - see #5638.
7# Ensure it completes successfully.
8complete -c testcommand --wraps "testcommand x "
9complete -c testcommand --wraps "testcommand y "
10complete -c testcommand --no-files -a normal
11complete -C'testcommand '
12# CHECK: normal
13
14# Test double wraps.
15complete -c testcommand0 -x -a crosswalk
16complete -c testcommand1 -x --wraps testcommand0
17complete -c testcommand2 -x --wraps testcommand1
18complete -C 'testcommand 0'
19# CHECK: crosswalk
20
21# This tests that a call to complete from within a completion doesn't trigger
22# wrap chain explosion - #5638 again.
23function testcommand2_complete
24    set -l tokens (commandline -xpc) (commandline -ct)
25    set -e tokens[1]
26    echo $tokens 1>&2
27end
28
29complete -c testcommand2 -x -a "(testcommand2_complete)"
30complete -c testcommand2 --wraps "testcommand2 from_wraps "
31complete -C'testcommand2 explicit '
32# CHECKERR: explicit
33# CHECKERR: from_wraps explicit
34
35# Test that prefixing with a variable assignment works - see #7344.
36complete -c recvar --exclusive -a recvar_comp
37complete -c recvar --wraps 'A=B recvar'
38complete -C 'recvar '
39# CHECK: recvar_comp
40
41# Test that completions do not perform subcommands.
42# That is, `FOO=(launch_missiles) command<tab>` does not launch any missiles.
43set -g missile_count 0
44function launch_missiles
45    set -g missile_count (math "$missile_count + 1")
46end
47
48# Ensure missile launching work.
49launch_missiles
50echo $missile_count
51# CHECK: 1
52
53set -g GOOD global_good
54set -g BAD global_bad
55
56function do_print_good_bad
57    echo "GOOD:$GOOD"
58    echo "BAD:$BAD"
59end
60complete -c print_good_bad -x -a '(do_print_good_bad)'
61complete -C 'print_good_bad '
62# CHECK: BAD:global_bad
63# CHECK: GOOD:global_good
64
65# Key check is completions should expand GOOD but not BAD,
66# because GOOD is just a string but BAD contains a cmdsub
67# which may do arbitrary things.
68complete -C 'GOOD=local_good BAD=(launch_missiles) print_good_bad '
69# CHECK: BAD:
70# CHECK: GOOD:local_good
71
72# Completion should not have launched any missiles.
73echo $missile_count
74# CHECK: 1
75
76# Torture test with a bunch of variable assignments.
77# Note this tests the existing behavior when there's conflicts
78# (innermost wrapped command wins) but it's not clear that this is desirable.
79function show_vars
80    echo "AAA:$AAA"
81    echo "BBB:$BBB"
82    echo "CCC:$CCC"
83end
84complete -c show_vars_cmd0 -x -a '(show_vars)'
85complete -c show_vars_cmd1 -x --wraps 'AAA=aaa show_vars_cmd0'
86complete -c show_vars_cmd2 -x --wraps 'AAA=nope BBB=bbb show_vars_cmd1'
87complete -c show_vars_cmd3 -x --wraps 'BBB=nope show_vars_cmd2'
88complete -C 'CCC=ccc show_vars_cmd3 '
89# CHECK: AAA:aaa
90# CHECK: BBB:bbb
91# CHECK: CCC:ccc