aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/test6.in
blob: 0d6ef487874f62e8f7f6758d1bc4d5b1992ac2e5 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# vim: set filetype=fish:

# 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

# 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 ^/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