Port "test6" to littlecheck

It's related to `complete`, so put it in complete.fish
This commit is contained in:
Fabian Homborg 2020-02-08 10:55:59 +01:00
parent 109a8b07a7
commit 884f347be6
4 changed files with 184 additions and 185 deletions

View File

@ -168,3 +168,187 @@ complete -C'complete_test_function_desc ' | count
complete -c prev-arg-variable -f
complete -C'prev-arg-variable $HOME '
# Regression test for issue #3129. In previous versions these statements would
# cause an `assert()` to fire thus killing the shell.
complete -c pkill -o ''
#CHECKERR: complete: -o requires a non-empty string
complete -c pkill -l ''
#CHECKERR: complete: -l requires a non-empty string
complete -c pkill -s ''
#CHECKERR: complete: -s requires a non-empty string
# Test that conditions that add or remove completions don't deadlock, etc.
# We actually encountered some case that was effectively like this (Issue 2 in github)
complete --command AAAA -l abcd --condition 'complete -c AAAA -l efgh'
echo "AAAA:"
complete -C'AAAA -' | sort
#CHECK: AAAA:
#CHECK: --abcd
echo "AAAA:"
complete -C'AAAA -' | sort
#CHECK: AAAA:
#CHECK: --abcd
#CHECK: --efgh
complete --command BBBB -l abcd --condition 'complete -e --command BBBB -l abcd'
echo "BBBB:"
complete -C'BBBB -'
#CHECK: BBBB:
#CHECK: --abcd
echo "BBBB:"
complete -C'BBBB -'
#CHECK: BBBB:
#CHECK:
# Test that erasing completions works correctly
echo
function sort
# GNU sort is really stupid, a non-C locale seems to make it assume --dictionary-order
# If I wanted --dictionary-order, I would have specified --dictionary-order!
env LC_ALL=C sort $argv
end
complete -c CCCC -l bar
complete -c CCCC -l baz
complete -c CCCC -o bar
complete -c CCCC -o foo
complete -c CCCC -s a
complete -c CCCC -s b
echo "CCCC:"
complete -C'CCCC -' | sort
complete -c CCCC -l bar -e
#CHECK: CCCC:
#CHECK: --bar
#CHECK: --baz
#CHECK: -a
#CHECK: -b
#CHECK: -bar
#CHECK: -foo
echo "CCCC:"
complete -C'CCCC -' | sort
complete -c CCCC -o foo -e
#CHECK: CCCC:
#CHECK: --baz
#CHECK: -a
#CHECK: -b
#CHECK: -bar
#CHECK: -foo
echo "CCCC:"
complete -C'CCCC -' | sort
complete -c CCCC -s a -e
#CHECK: CCCC:
#CHECK: --baz
#CHECK: -a
#CHECK: -b
#CHECK: -bar
echo "CCCC:"
complete -C'CCCC -' | sort
complete -c CCCC -e
#CHECK: CCCC:
#CHECK: --baz
#CHECK: -b
#CHECK: -bar
echo "CCCC:"
complete -C'CCCC -' | sort
#CHECK: CCCC:
echo "Test that -- suppresses option completions"
complete -c TestDoubleDash -l TestDoubleDashOption
complete -C'TestDoubleDash -' | sort
#CHECK: Test that -- suppresses option completions
#CHECK: --TestDoubleDashOption
echo "Expect no output:" (complete -C'TestDoubleDash -- -' | sort)
#CHECK: Expect no output:
# fish seems to have always handled "exclusive" options strangely
# It seems to treat them the same as "old-style" (single-dash) long options
echo "Testing exclusive options"
#CHECK: Testing exclusive options
complete -c TestExclusive -x -s Q
complete -c TestExclusive -x -s W
complete -c TestExclusive -s A
echo "Expect -A -Q -W:" (complete -C'TestExclusive -' | sort | string join ' ')
#CHECK: Expect -A -Q -W: -A -Q -W
echo "Expect -AQ -AW:" (complete -C'TestExclusive -A' | sort | string join ' ')
#CHECK: Expect -AQ -AW: -AQ -AW
echo "Expect no output 1:" (complete -C'TestExclusive -Q')
#CHECK: Expect no output 1:
echo "Expect no output 2:" (complete -C'TestExclusive -W')
#CHECK: Expect no output 2:
# Test for optional arguments, like cp's --backup
complete -c TestOptionalArgument -l backup -f -a 'none all simple'
echo "Expect --backup --backup=:" (complete -C'TestOptionalArgument -' | sort | string join ' ')
#CHECK: Expect --backup --backup=: --backup --backup=
echo "Expect --backup=all --backup=none --backup=simple:" (complete -C'TestOptionalArgument --backup=' | sort | string join ' ')
#CHECK: Expect --backup=all --backup=none --backup=simple: --backup=all --backup=none --backup=simple
# Test that directory completions work correctly
if begin; rm -rf test6.tmp.dir; and mkdir test6.tmp.dir; end
pushd test6.tmp.dir
set -l dir (mktemp -d XXXXXXXX)
if complete -C$dir | grep "^$dir/.*Directory" >/dev/null
echo "implicit cd complete works"
else
echo "no implicit cd complete"
end
#CHECK: implicit cd complete works
if complete -C"command $dir" | grep "^$dir/.*Directory" >/dev/null
echo "implicit cd complete incorrect after 'command'"
else
echo "no implicit cd complete after 'command'"
end
#CHECK: no implicit cd complete after 'command'
popd
if begin
set -l PATH $PWD/test6.tmp.dir $PATH 2>/dev/null
complete -C$dir | grep "^$dir/.*Directory" >/dev/null
end
echo "incorrect implicit cd from PATH"
else
echo "PATH does not cause incorrect implicit cd"
end
#CHECK: PATH does not cause incorrect implicit cd
rm -rf test6.tmp.dir
else
echo "error: could not create temp environment" >&2
end
# Test command expansion with parened PATHs (#952)
begin
set -l parened_path $PWD/'test6.tmp2.(paren).dir'
set -l parened_subpath $parened_path/subdir
if not begin
rm -rf $parened_path
and mkdir $parened_path
and mkdir $parened_subpath
and ln -s /bin/ls $parened_path/'__test6_(paren)_command'
and ln -s /bin/ls $parened_subpath/'__test6_subdir_(paren)_command'
end
echo "error: could not create command expansion temp environment" >&2
end
# Verify that we can expand commands when PATH has parens
set -l PATH $parened_path $PATH
set -l completed (complete -C__test6_ | cut -f 1 -d \t)
if test "$completed" = '__test6_(paren)_command'
echo "Command completion with parened PATHs test passed"
else
echo "Command completion with parened PATHs test failed. Expected __test6_(paren)_command, got $completed" >&2
end
#CHECK: Command completion with parened PATHs test passed
# Verify that commands with intermediate slashes do NOT expand with respect to PATH
set -l completed (complete -Csubdir/__test6_subdir)
if test -z "$completed"
echo "Command completion with intermediate slashes passed"
else
echo "Command completion with intermediate slashes: should output nothing, instead got $completed" >&2
end
#CHECK: Command completion with intermediate slashes passed
rm -rf $parened_path
end

View File

@ -1,3 +0,0 @@
complete: -o requires a non-empty string
complete: -l requires a non-empty string
complete: -s requires a non-empty string

View File

@ -1,135 +0,0 @@
# vim: set filetype=fish:
# Regression test for issue #3129. In previous versions these statements would
# cause an `assert()` to fire thus killing the shell.
complete -c pkill -o ''
complete -c pkill -l ''
complete -c pkill -s ''
# Test that conditions that add or remove completions don't deadlock, etc.
# We actually encountered some case that was effectively like this (Issue 2 in github)
complete --command AAAA -l abcd --condition 'complete -c AAAA -l efgh'
echo "AAAA:"
complete -C'AAAA -' | sort
echo "AAAA:"
complete -C'AAAA -' | sort
complete --command BBBB -l abcd --condition 'complete -e --command BBBB -l abcd'
echo "BBBB:"
complete -C'BBBB -'
echo "BBBB:"
complete -C'BBBB -'
# Test that erasing completions works correctly
echo
function sort
# GNU sort is really stupid, a non-C locale seems to make it assume --dictionary-order
# If I wanted --dictionary-order, I would have specified --dictionary-order!
env LC_ALL=C sort $argv
end
complete -c CCCC -l bar
complete -c CCCC -l baz
complete -c CCCC -o bar
complete -c CCCC -o foo
complete -c CCCC -s a
complete -c CCCC -s b
echo "CCCC:"
complete -C'CCCC -' | sort
complete -c CCCC -l bar -e
echo "CCCC:"
complete -C'CCCC -' | sort
complete -c CCCC -o foo -e
echo "CCCC:"
complete -C'CCCC -' | sort
complete -c CCCC -s a -e
echo "CCCC:"
complete -C'CCCC -' | sort
complete -c CCCC -e
echo "CCCC:"
complete -C'CCCC -' | sort
echo "Test that -- suppresses option completions"
complete -c TestDoubleDash -l TestDoubleDashOption
complete -C'TestDoubleDash -' | sort
echo "Expect no output:" (complete -C'TestDoubleDash -- -' | sort)
# fish seems to have always handled "exclusive" options strangely
# It seems to treat them the same as "old-style" (single-dash) long options
echo "Testing exclusive options"
complete -c TestExclusive -x -s Q
complete -c TestExclusive -x -s W
complete -c TestExclusive -s A
echo "Expect -A -Q -W:" (complete -C'TestExclusive -' | sort | string join ' ')
echo "Expect -AQ -AW:" (complete -C'TestExclusive -A' | sort | string join ' ')
echo "Expect no output 1:" (complete -C'TestExclusive -Q')
echo "Expect no output 2:" (complete -C'TestExclusive -W')
# Test for optional arguments, like cp's --backup
complete -c TestOptionalArgument -l backup -f -a 'none all simple'
echo "Expect --backup --backup=:" (complete -C'TestOptionalArgument -' | sort | string join ' ')
echo "Expect --backup=all --backup=none --backup=simple:" (complete -C'TestOptionalArgument --backup=' | sort | string join ' ')
# Test that directory completions work correctly
if begin; rm -rf test6.tmp.dir; and mkdir test6.tmp.dir; end
pushd test6.tmp.dir
set -l dir (mktemp -d XXXXXXXX)
if complete -C$dir | grep "^$dir/.*Directory" >/dev/null
echo "implicit cd complete works"
else
echo "no implicit cd complete"
end
if complete -C"command $dir" | grep "^$dir/.*Directory" >/dev/null
echo "implicit cd complete incorrect after 'command'"
else
echo "no implicit cd complete after 'command'"
end
popd
if begin
set -l PATH $PWD/test6.tmp.dir $PATH 2>/dev/null
complete -C$dir | grep "^$dir/.*Directory" >/dev/null
end
echo "incorrect implicit cd from PATH"
else
echo "PATH does not cause incorrect implicit cd"
end
rm -rf test6.tmp.dir
else
echo "error: could not create temp environment" >&2
end
# Test command expansion with parened PATHs (#952)
begin
set -l parened_path $PWD/'test6.tmp2.(paren).dir'
set -l parened_subpath $parened_path/subdir
if not begin
rm -rf $parened_path
and mkdir $parened_path
and mkdir $parened_subpath
and ln -s /bin/ls $parened_path/'__test6_(paren)_command'
and ln -s /bin/ls $parened_subpath/'__test6_subdir_(paren)_command'
end
echo "error: could not create command expansion temp environment" >&2
end
# Verify that we can expand commands when PATH has parens
set -l PATH $parened_path $PATH
set -l completed (complete -C__test6_ | cut -f 1 -d \t)
if test "$completed" = '__test6_(paren)_command'
echo "Command completion with parened PATHs test passed"
else
echo "Command completion with parened PATHs test failed. Expected __test6_(paren)_command, got $completed" >&2
end
# Verify that commands with intermediate slashes do NOT expand with respect to PATH
set -l completed (complete -Csubdir/__test6_subdir)
if test -z "$completed"
echo "Command completion with intermediate slashes passed"
else
echo "Command completion with intermediate slashes: should output nothing, instead got $completed" >&2
end
rm -rf $parened_path
end

View File

@ -1,47 +0,0 @@
AAAA:
--abcd
AAAA:
--abcd
--efgh
BBBB:
--abcd
BBBB:
CCCC:
--bar
--baz
-a
-b
-bar
-foo
CCCC:
--baz
-a
-b
-bar
-foo
CCCC:
--baz
-a
-b
-bar
CCCC:
--baz
-b
-bar
CCCC:
Test that -- suppresses option completions
--TestDoubleDashOption
Expect no output:
Testing exclusive options
Expect -A -Q -W: -A -Q -W
Expect -AQ -AW: -AQ -AW
Expect no output 1:
Expect no output 2:
Expect --backup --backup=: --backup --backup=
Expect --backup=all --backup=none --backup=simple: --backup=all --backup=none --backup=simple
implicit cd complete works
no implicit cd complete after 'command'
PATH does not cause incorrect implicit cd
Command completion with parened PATHs test passed
Command completion with intermediate slashes passed