Added ssh completion tests:
- First argument shouldn't complete with commands - Tab should complete partial hostname To run the tests: $ cd test && ./runCompletion ssh.exp Added test library function: assert_complete_partial
This commit is contained in:
parent
362090a160
commit
67eedb203f
@ -42,4 +42,31 @@ expect {
|
|||||||
sync_after_int
|
sync_after_int
|
||||||
|
|
||||||
|
|
||||||
|
set test "First argument shouldn't complete with commands"
|
||||||
|
# NOTE: This test assumes the machine running this test has a command "bash"
|
||||||
|
# but no host named "bash" ...
|
||||||
|
set cmd "ssh bas"
|
||||||
|
send "$cmd\t"
|
||||||
|
expect -ex "$cmd"
|
||||||
|
expect {
|
||||||
|
-timeout 1
|
||||||
|
# In case multiple commands `bas*' are completed
|
||||||
|
-re "^\r\n.*bash.*\r\n/@$cmd$" { fail "$test" }
|
||||||
|
# In case the single command `bash' is completed
|
||||||
|
-re "h $" { fail "$test" }
|
||||||
|
-re ".+" { unresolved "$test" }
|
||||||
|
timeout { pass "$test" }
|
||||||
|
}; # expect
|
||||||
|
|
||||||
|
|
||||||
|
sync_after_int
|
||||||
|
|
||||||
|
|
||||||
|
set test "Tab should complete partial hostname"
|
||||||
|
assert_complete_partial [exec bash -c "compgen -A hostname"] "ssh"
|
||||||
|
|
||||||
|
|
||||||
|
sync_after_int
|
||||||
|
|
||||||
|
|
||||||
teardown
|
teardown
|
||||||
|
@ -56,9 +56,9 @@ proc assert_complete {expected cmd {test ""} {prompt /@} {size 20}} {
|
|||||||
send "$cmd\t"
|
send "$cmd\t"
|
||||||
if {[llength $expected] == 1} {
|
if {[llength $expected] == 1} {
|
||||||
expect -ex "$cmd"
|
expect -ex "$cmd"
|
||||||
# Assume second word is word to complete on.
|
# Assume second word is word to complete on.
|
||||||
set cur [lindex [split $cmd] 1]
|
set cur [lindex [split $cmd] 1]
|
||||||
# Remove second word from beginning of single item $expected
|
# Remove second word from beginning of single item $expected
|
||||||
if {[string first $cur $expected] == 0} {
|
if {[string first $cur $expected] == 0} {
|
||||||
set expected [string range $expected [string length $cur] end]
|
set expected [string range $expected [string length $cur] end]
|
||||||
}; # if
|
}; # if
|
||||||
@ -82,6 +82,33 @@ proc assert_complete {expected cmd {test ""} {prompt /@} {size 20}} {
|
|||||||
}; # assert_complete()
|
}; # assert_complete()
|
||||||
|
|
||||||
|
|
||||||
|
# Make sure a partial argument is completed.
|
||||||
|
# A completion is tried with `$partial', or if this is empty, the first
|
||||||
|
# character of the first item of `$expected'. Only the items from $expected,
|
||||||
|
# starting with this character are then expected as completions.
|
||||||
|
# @param list $expected List of all completions.
|
||||||
|
# @param string $cmd Command given to generate items
|
||||||
|
# @param string $test (optional) Test titel. Default is "$cmd<TAB> should show completions"
|
||||||
|
# @param integer $size (optional) Chunk size. Default is 20.
|
||||||
|
# @result boolean True if successful, False if not
|
||||||
|
proc assert_complete_partial {expected cmd {partial ""} {test ""} {prompt /@} {size 20}} {
|
||||||
|
if {$test == ""} {set test "$cmd should complete partial argument"}
|
||||||
|
if {[llength $expected] == 0} {
|
||||||
|
unresolved "$test"
|
||||||
|
} else {
|
||||||
|
set pick {}
|
||||||
|
foreach item $expected {
|
||||||
|
if {$partial == ""} {set partial [string range $item 0 0]}
|
||||||
|
# Only append item if starting with $partial
|
||||||
|
if {[string range $item 0 [expr [string length $partial] - 1]] == "$partial"} {
|
||||||
|
lappend pick $item
|
||||||
|
}; # if
|
||||||
|
}; # foreach
|
||||||
|
assert_complete $pick "$cmd $partial" $test $prompt $size
|
||||||
|
}; # if
|
||||||
|
}; # assert_complete_partial()
|
||||||
|
|
||||||
|
|
||||||
# Make sure any completions are returned
|
# Make sure any completions are returned
|
||||||
proc assert_complete_any {cmd {test ""} {prompt /@}} {
|
proc assert_complete_any {cmd {test ""} {prompt /@}} {
|
||||||
if {$test == ""} {set test "$cmd should show completions"}
|
if {$test == ""} {set test "$cmd should show completions"}
|
||||||
@ -201,13 +228,24 @@ proc match_items {items test {size 20}} {
|
|||||||
# Escape special regexp characters
|
# Escape special regexp characters
|
||||||
regsub -all {([\[\]\(\)\.\\\+])} $item {\\\1} item
|
regsub -all {([\[\]\(\)\.\\\+])} $item {\\\1} item
|
||||||
append expected $item
|
append expected $item
|
||||||
if {[llength $items] > 1} {append expected {\s+}}
|
if {[llength $items] > 1} {append expected {\s+}};
|
||||||
}; # for
|
}; # for
|
||||||
expect {
|
if {[llength $items] == 1} {
|
||||||
-re "$expected" { set result true }
|
expect {
|
||||||
default { set result false; break }
|
-timeout 1
|
||||||
timeout { set result false; break }
|
-re "$expected" { set result true }
|
||||||
}; # expect
|
"\r\n" { set result false; break }
|
||||||
|
default { set result false; break }
|
||||||
|
timeout { set result false; break }
|
||||||
|
}; # expect
|
||||||
|
} else {
|
||||||
|
expect {
|
||||||
|
-timeout 1
|
||||||
|
-re "$expected" { set result true }
|
||||||
|
default { set result false; break }
|
||||||
|
timeout { set result false; break }
|
||||||
|
}; # expect
|
||||||
|
}; # if
|
||||||
}; # for
|
}; # for
|
||||||
return $result
|
return $result
|
||||||
}; # match_items()
|
}; # match_items()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user