summaryrefslogtreecommitdiff
path: root/test/lib/completions/cd.exp
blob: 6f36c881e5a157c996306a30f00503ea5e121b05 (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
proc setup {} {
    save_env
}


proc teardown {} {
    assert_env_unmodified {/OLDPWD=/d}
}


setup


set test "Tab should complete"
assert_complete {"bar bar.d/" foo.d/} "cd $::srcdir/fixtures/shared/default/" $test


sync_after_int


set test "Tab should complete cd at cursor position"
    # Try completion
set cmd "cd $::srcdir/fixtures/shared/default/foo"
append cmd \002\002\002; # \002 = ^B = Move cursor left in bash emacs mode
#append cmd \033\0133D; # Escape-[-D = Cursor left
send "$cmd\t"
expect {
    -re "cd $::srcdir/fixtures/shared/default/foo\b\b\b\r\n(\.svn/ +|)bar bar.d/ +foo.d/ *(\.svn/ *|)\r\n/@cd $::srcdir/fixtures/shared/default/foo\b\b\b$" { pass "$test" }
	-re "^cd $::srcdir/fixtures/shared/default/foo\b\b\bfoo.d/foo\b\b\b$" { fail "$test: Wrong cursor position" }
    -re /@ { unresolved "$test at prompt" }
    default { unresolved "$test" }
}


sync_after_int


set test "Tab should complete CDPATH"
    # Set CDPATH
assert_bash_exec "declare -p CDPATH &>/dev/null && OLDCDPATH=\$CDPATH || :"
assert_bash_exec "CDPATH=\$PWD";
assert_complete "$::srcdir/fixtures/shared/default/foo.d/" \
    "cd $::srcdir/fixtures/shared/default/fo" $test -nospace -expect-cmd-minus fo
sync_after_int

assert_bash_exec "unset CDPATH"
# Assuming no subdirs here
assert_bash_exec "cd $::srcdir/fixtures/shared/default/foo.d"
assert_no_complete "cd " "cd shouldn't complete when there are no subdirs or CDPATH"
sync_after_int

    # Reset PWD and CDPATH
assert_bash_exec "cd \"\$OLDPWD\""
assert_bash_exec "declare -p OLDCDPATH &>/dev/null && CDPATH=\$OLDCDPATH || unset CDPATH && unset OLDCDPATH"


teardown