summaryrefslogtreecommitdiff
path: root/test/lib/completions/scp.exp
blob: 1497a7fbe802d69ea3a8b62fc147ade43e1ecb8d (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
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 `hut' 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: hut: 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