summaryrefslogtreecommitdiff
path: root/test/lib/completions/mount.exp
blob: bcb95ba430551b898fbab4edd1b33b8ac5b0a8e6 (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
# mount completion from fstab can't be tested directly because it
# (correctly) uses absolute paths. So we create a custom completion which
# reads from a file in our text fixture instead.
proc setup_dummy_mnt {} {
    assert_bash_exec {unset COMPREPLY cur}
    assert_bash_exec {unset -f _mnt}

    global TESTDIR
    assert_bash_exec { \
        _mnt() { \
            local cur=$(_get_cword); \
            _linux_fstab < "$TESTDIR/fixtures/mount/test-fstab"; \
        }; \
        complete -F _mnt mnt \
    }
}


proc teardown_dummy_mnt {} {
    assert_bash_exec {unset COMPREPLY cur}
    assert_bash_exec {unset -f _mnt}
    assert_bash_exec {complete -r mnt}
}


proc setup {} {
    save_env
    setup_dummy_mnt
}


proc teardown {} {
    teardown_dummy_mnt
    assert_env_unmodified
}


setup


assert_complete_any "mount "


sync_after_int


set test "Check completing nfs mounts"
set expected [list /test/path /test/path2 /second/path]
set cmd "mount mocksrv:/"
assert_bash_exec {OLDPATH="$PATH"; PATH="$TESTDIR/fixtures/mount/bin:$PATH";}
# This needs an explicit cword param or will output "unresolved".
assert_complete $expected $cmd $test "/@" 20 "/"
sync_after_int
assert_bash_exec {PATH="$OLDPATH"; unset -v OLDPATH}


sync_after_int


assert_complete {/mnt/nice\ test-path} {mnt /mnt/nice\ test-p}
sync_after_int

assert_complete {/mnt/nice\$test-path} {mnt /mnt/nice\$test-p}
sync_after_int

assert_complete {/mnt/nice\ test\\path} {mnt /mnt/nice\ test\\p}
sync_after_int

assert_complete {/mnt/nice\ test-path} {mnt /mnt/nice\ }
sync_after_int

assert_complete {/mnt/nice\$test-path} {mnt /mnt/nice\$}
sync_after_int

assert_complete {'/mnt/nice\ test-path'} {mnt '/mnt/nice\ }
sync_after_int


teardown