summaryrefslogtreecommitdiff
path: root/test/lib/completions/scp.exp
blob: efe2b686149a469a62423ab341d5468f7d221b5f (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
109
110
111
112
113
114
115
116
117
118
119
120
121
proc setup {} {
    save_env
}; # setup()


proc teardown {} {
    assert_env_unmodified {
        /BASH_LINENO=/d
        /BASH_SOURCE=/d
        /OLDPWD=/d
    }
}; # teardown()


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
}; # if


    # Try completion
set cmd "scp $host:"
send "$cmd\t"
sync_after_tab
expect {
    -re "^$cmd$host_pwd.*$" { pass "$test" }
    -re /@ { unresolved "$test at prompt" }
}; # expect


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 `doo' and `ike' are defined in ./fixtures/scp/known_hosts
set expected {}
foreach host [get_hosts] {
    lappend expected "$host:"
}; # foreach
lappend expected doo: gee: hus: ike:
    # Append local filenames
lappend expected config known_hosts "spaced\\ \\ conf"
set dir fixtures/scp
assert_complete_dir $expected "scp -F config " $dir


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" }
}; # expect


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:"
}; # foreach
    # Hosts `gee', `hus' and `jar' are defined in "./fixtures/scp/spaced  conf"
    # Hosts `doo' and `ike' are defined in ./fixtures/scp/known_hosts
lappend expected doo: gee: hus: ike: jar:
    # Append local filenames
lappend expected config known_hosts "spaced\\ \\ conf"
set dir fixtures/scp
#assert_complete_dir $expected "scp -F 'spaced  conf' " $dir
set prompt "/$dir/@"
assert_bash_exec "cd $dir" "" $prompt
set cmd "scp -F 'spaced  conf' "
send "$cmd\t"
expect -ex "$cmd\r\n"
if {[match_items [lsort -unique $expected] $test]} {
    expect {
        -re $prompt { pass "$test" }
        -re eof { unresolved "eof" }
    }; # expect
} else {
    # Expected failure (known bug) because of bash-4 bug in quoted words:
    # http://www.mail-archive.com/bug-bash@gnu.org/msg06095.html
    if {[lindex $::BASH_VERSINFO 0] >= 4} {xfail "$test"} {fail "$test"}
}; # if
sync_after_int $prompt
assert_bash_exec {cd "$TESTDIR"}


sync_after_int


teardown