proc setup {} { save_env # NOTE: Changing dir to $SRCDIR is necessary because file locations in the # ssh config files (e.g. UserKnownHostsFile) are relative to $SRCDIR. assert_bash_exec {cd $SRCDIR/fixtures/scp} } proc teardown {} { assert_bash_exec {cd $TESTDIR} assert_env_unmodified { /BASH_LINENO=/d /BASH_SOURCE=/d /OLDPWD=/d } } setup set test "Tab should complete remote pwd" set host bash_completion # Retrieving home directory (host_pwd) from ssh-host `bash_completion' # yields error? if { [catch { exec -- ssh -o "Batchmode yes" -o "ConnectTimeout 1" $host pwd 2>> /dev/null } host_pwd] } { # Yes, retrieving pwd from ssh yields error; reset `host_pwd' # Indicate host pwd is unknown and test is unsupported # NOTE: To support this test, set the hostname "bash_completion" # in `$HOME/.ssh/config' or `/etc/ssh_config' set host_pwd "" unsupported $test } # Try completion set cmd "scp $host:" send "$cmd\t" sync_after_tab expect { -re "^$cmd$host_pwd.*$" { pass "$test" } -re /@ { unresolved "$test at prompt" } } sync_after_int set test "Tab should complete known-hosts" # Build string list of expected completions # Get hostnames and give them a colon (:) suffix # Hosts `gee' and `hus' are defined in ./fixtures/scp/config # Hosts `blah', `doo' and `ike' are defined in ./fixtures/scp/known_hosts set expected {} foreach host [get_hosts] { lappend expected "$host:" } lappend expected blah: doo: gee: hus: ike: # Append local filenames lappend expected config known_hosts "spaced\\ \\ conf" assert_complete $expected "scp -F config " $test sync_after_int set test "-F without space shouldn't error" # Try completion set cmd "scp -F" send "$cmd\t " expect { -re "^${cmd}bash: option requires an argument -- F" { fail "$test" } -re "^$cmd\r\n.*\r\n/@" { pass "$test" } -re /@ { unresolved "$test at prompt" } default { unresolved "$test" } } sync_after_int set test "Config file containing space should work" # Build string list of expected completions # Get hostnames and give them a colon (:) suffix set expected {} foreach host [get_hosts] { lappend expected "$host:" } # Hosts `gee', `hus' and `jar' are defined in "./fixtures/scp/spaced conf" # Hosts `blah', `doo' and `ike' are defined in ./fixtures/scp/known_hosts lappend expected blah: doo: gee: hus: ike: jar: # Append local filenames lappend expected config known_hosts "spaced\\ \\ conf" set cmd "scp -F 'spaced conf' " send "$cmd\t" expect -ex "$cmd\r\n" if {[match_items [lsort -unique $expected] -bash-sort]} { expect { -re /@ { pass "$test" } -re eof { unresolved "eof" } default { fail "$test" } } } sync_after_int assert_bash_exec {cd "$TESTDIR"} sync_after_int teardown