diff options
Diffstat (limited to 'test/lib/completions/mount.exp')
-rw-r--r-- | test/lib/completions/mount.exp | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/test/lib/completions/mount.exp b/test/lib/completions/mount.exp new file mode 100644 index 00000000..38d93e3b --- /dev/null +++ b/test/lib/completions/mount.exp @@ -0,0 +1,121 @@ +# 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 $(_get_pword) < "$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 + + +assert_complete_any "mount -t " + + +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 + + +set test "Testing internal __linux_fstab_unescape function for mount" +# One round of slashes is for bash. +assert_bash_exec {var=one\'two\\040three\\} +assert_bash_exec {__linux_fstab_unescape var} +set cmd {echo $var} +send "$cmd\r" +expect { + -ex "$cmd\r\none'two three\\" { pass $test } +# default { fail $test } +} +sync_after_int +assert_bash_exec {unset var} + + +sync_after_int + + +# Begin testing through mnt (see setup_dummy_mnt). +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\ test\\p} +sync_after_int + +assert_complete {{/mnt/nice\ test\\path} {/mnt/nice\ test-path}} \ + {mnt /mnt/nice\ } "" /@ 20 {/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 + +assert_complete {/mnt/other\'test\ path} {mnt /mnt/other} +sync_after_int + +assert_complete {Ubuntu\ Karmic} {mnt -L Ubu} +sync_after_int + +assert_complete {Debian-it\'s\ awesome} {mnt -L Deb} +sync_after_int + +# This does not work. Proper support for this requires smarter parsing of +# $COMP_LINE and it's not worth doing just for mount. +#assert_complete {$'/mnt/nice\ntest-path'} {mnt $'/mnt/nice\n} +#sync_after_int + + +teardown |