fish-shell/tests/checks/wraps.fish
ridiculousfish 45b85d28bb Completion wrap chain visited set to store only wrapped command
The "wrap chain" refers to a sequence of commands which wrap other
commands, for completion purposes. One possibility is that a wrap chain
will produce a combinatorial explosion or even an infinite loop, so there
needs to be logic to prevent that. Part of that logic is encapsulated in a
visited set (wrap_chain_visited_set_t) to prevent exploring the same item
twice.

Prior to this change, we stored pairs (command, wrapped_command). But we
only really need to store the wrapped command. Switch to that.

One consequence is that if a command wraps another command in more than
one way, we won't explore both ways. This seems unlikely in practice.
2020-09-26 17:24:59 -07:00

42 lines
1.3 KiB
Fish

#RUN: %fish %s
# Validate some things about command wrapping.
set -g LANG C # For predictable error messages.
# This tests that we do not trigger a combinatorial explosion - see #5638.
# Ensure it completes successfully.
complete -c testcommand --wraps "testcommand x "
complete -c testcommand --wraps "testcommand y "
complete -c testcommand --no-files -a normal
complete -C'testcommand '
# CHECK: normal
# We get the same completion twice. TODO: fix this.
# CHECK: normal
# Test double wraps.
complete -c testcommand0 -x -a crosswalk
complete -c testcommand1 -x --wraps testcommand0
complete -c testcommand2 -x --wraps testcommand1
complete -C 'testcommand 0'
# CHECK: crosswalk
# This tests that a call to complete from within a completion doesn't trigger
# wrap chain explosion - #5638 again.
function testcommand2_complete
set -l tokens (commandline -opc) (commandline -ct)
set -e tokens[1]
echo $tokens 1>&2
end
complete -c testcommand2 -x -a "(testcommand2_complete)"
complete -c testcommand2 --wraps "testcommand2 from_wraps "
complete -C'testcommand2 explicit '
# CHECKERR: explicit
# CHECKERR: from_wraps explicit
complete -c recvar --wraps 'A=B recvar'
complete -C 'recvar '
# CHECKERR: <E> fish: completion reached maximum recursion depth, possible cycle?