(testsuite) Fix ssh test with colon completions
Function `assert_complete()' is becoming hairy but let's wait untill other completions with other special characters come along before refactoring.
This commit is contained in:
parent
a07b5c5ffd
commit
c920661b5e
@ -8,7 +8,7 @@ proc completion_exit {} {
|
|||||||
|
|
||||||
|
|
||||||
proc completion_start {} {
|
proc completion_start {} {
|
||||||
global bash_versinfo_0 TESTDIR TOOL_EXECUTABLE spawn_id
|
global bash_versinfo_0 COMP_WORDBREAKS TESTDIR TOOL_EXECUTABLE spawn_id
|
||||||
set test "completion_start"
|
set test "completion_start"
|
||||||
set TESTDIR [pwd]
|
set TESTDIR [pwd]
|
||||||
|
|
||||||
@ -23,6 +23,7 @@ proc completion_start {} {
|
|||||||
assert_bash_exec {source $BASH_COMPLETION}
|
assert_bash_exec {source $BASH_COMPLETION}
|
||||||
# Fill global var `bash_versinfo_0' with bash major version number
|
# Fill global var `bash_versinfo_0' with bash major version number
|
||||||
assert_bash_exec {printf "%s" "${BASH_VERSINFO[0]}"} "" /@ bash_versinfo_0
|
assert_bash_exec {printf "%s" "${BASH_VERSINFO[0]}"} "" /@ bash_versinfo_0
|
||||||
|
assert_bash_exec {printf "%s" "$COMP_WORDBREAKS"} "" /@ COMP_WORDBREAKS
|
||||||
}; # completion_start()
|
}; # completion_start()
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ sync_after_int
|
|||||||
|
|
||||||
|
|
||||||
set test "First argument should complete partial hostname"
|
set test "First argument should complete partial hostname"
|
||||||
assert_complete_partial [get_hosts] ssh
|
assert_complete_partial [get_hosts] ssh "" $test /@ 20 [list "ltrim_colon_completions"]
|
||||||
|
|
||||||
|
|
||||||
sync_after_int
|
sync_after_int
|
||||||
|
@ -109,12 +109,16 @@ proc assert_bash_list {expected cmd {test ""} {prompt /@} {size 20}} {
|
|||||||
# doesn't end with whitespace. Specifying `cword' is only necessary if
|
# doesn't end with whitespace. Specifying `cword' is only necessary if
|
||||||
# this autodetection fails, e.g. when the last whitespace is escaped or
|
# this autodetection fails, e.g. when the last whitespace is escaped or
|
||||||
# quoted, e.g. "finger foo\ " or "finger 'foo "
|
# quoted, e.g. "finger foo\ " or "finger 'foo "
|
||||||
|
# @param list $filters (optional) List of filters to apply to this function to tweak
|
||||||
|
# the expected completions and argument-to-complete. Possible values:
|
||||||
|
# - "ltrim_colon_completions"
|
||||||
# @result boolean True if successful, False if not
|
# @result boolean True if successful, False if not
|
||||||
proc assert_complete {expected cmd {test ""} {prompt /@} {size 20} {cword ""}} {
|
proc assert_complete {expected cmd {test ""} {prompt /@} {size 20} {cword ""} {filters ""}} {
|
||||||
if {$test == ""} {set test "$cmd should show completions"}
|
if {$test == ""} {set test "$cmd should show completions"}
|
||||||
send "$cmd\t"
|
send "$cmd\t"
|
||||||
if {[llength $expected] == 1} {
|
if {[llength $expected] == 1} {
|
||||||
expect -ex "$cmd"
|
expect -ex "$cmd"
|
||||||
|
if {[lsearch -exact $filters "ltrim_colon_completions"] == -1} {
|
||||||
set cmds [split $cmd]
|
set cmds [split $cmd]
|
||||||
set cur ""; # Default to empty word to complete on
|
set cur ""; # Default to empty word to complete on
|
||||||
if {[llength $cmds] > 1} {
|
if {[llength $cmds] > 1} {
|
||||||
@ -125,12 +129,19 @@ proc assert_complete {expected cmd {test ""} {prompt /@} {size 20} {cword ""}} {
|
|||||||
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
|
||||||
|
}; # if
|
||||||
} else {
|
} else {
|
||||||
expect -ex "$cmd\r\n"
|
expect -ex "$cmd\r\n"
|
||||||
# Make sure expected items are unique
|
# Make sure expected items are unique
|
||||||
set expected [lsort -unique $expected]
|
set expected [lsort -unique $expected]
|
||||||
}; # if
|
}; # if
|
||||||
|
|
||||||
|
if {[lsearch -exact $filters "ltrim_colon_completions"] != -1} {
|
||||||
|
# If partial contains colon (:), remove partial from begin of items
|
||||||
|
# See also: bash_completion.__ltrim_colon_completions()
|
||||||
|
_ltrim_colon_completions cword expected
|
||||||
|
}; # if
|
||||||
|
|
||||||
if {[match_items $expected $test]} {
|
if {[match_items $expected $test]} {
|
||||||
if {[llength $expected] == 1} {
|
if {[llength $expected] == 1} {
|
||||||
pass "$test"
|
pass "$test"
|
||||||
@ -138,7 +149,12 @@ proc assert_complete {expected cmd {test ""} {prompt /@} {size 20} {cword ""}} {
|
|||||||
# Remove optional (partial) last argument-to-complete from `cmd',
|
# Remove optional (partial) last argument-to-complete from `cmd',
|
||||||
# E.g. "finger test@" becomes "finger"
|
# E.g. "finger test@" becomes "finger"
|
||||||
|
|
||||||
|
if {[lsearch -exact $filters "ltrim_colon_completions"] != -1} {
|
||||||
|
set cmd2 $cmd
|
||||||
|
} else {
|
||||||
set cmd2 [_remove_cword_from_cmd $cmd $cword]
|
set cmd2 [_remove_cword_from_cmd $cmd $cword]
|
||||||
|
}; # if
|
||||||
|
|
||||||
# Determine common prefix of completions
|
# Determine common prefix of completions
|
||||||
set common [::textutil::string::longestCommonPrefixList $expected]
|
set common [::textutil::string::longestCommonPrefixList $expected]
|
||||||
#if {[string length $common] > 0} {set common " $common"}
|
#if {[string length $common] > 0} {set common " $common"}
|
||||||
@ -249,8 +265,11 @@ proc assert_complete_dir {expected cmd dir {test ""} {size 20} {cword ""}} {
|
|||||||
# @param string $test (optional) Test titel. Default is "$cmd<TAB> should show completions"
|
# @param string $test (optional) Test titel. Default is "$cmd<TAB> should show completions"
|
||||||
# @param string $prompt (optional) Bash prompt. Default is "/@"
|
# @param string $prompt (optional) Bash prompt. Default is "/@"
|
||||||
# @param integer $size (optional) Chunk size. Default is 20.
|
# @param integer $size (optional) Chunk size. Default is 20.
|
||||||
|
# @param list $filters (optional) List of filters to apply to this function to tweak
|
||||||
|
# the expected completions and argument-to-complete.
|
||||||
|
# @see assert_complete()
|
||||||
# @result boolean True if successful, False if not
|
# @result boolean True if successful, False if not
|
||||||
proc assert_complete_partial {expected cmd {partial ""} {test ""} {prompt /@} {size 20}} {
|
proc assert_complete_partial {expected cmd {partial ""} {test ""} {prompt /@} {size 20} {filters ""}} {
|
||||||
if {$test == ""} {set test "$cmd should complete partial argument"}
|
if {$test == ""} {set test "$cmd should complete partial argument"}
|
||||||
if {[llength $expected] == 0} {
|
if {[llength $expected] == 0} {
|
||||||
unresolved "$test"
|
unresolved "$test"
|
||||||
@ -265,11 +284,36 @@ proc assert_complete_partial {expected cmd {partial ""} {test ""} {prompt /@} {s
|
|||||||
lappend pick $item
|
lappend pick $item
|
||||||
}; # if
|
}; # if
|
||||||
}; # foreach
|
}; # foreach
|
||||||
assert_complete $pick "$cmd $partial" $test $prompt $size $partial
|
assert_complete $pick "$cmd $partial" $test $prompt $size $partial $filters
|
||||||
}; # if
|
}; # if
|
||||||
}; # assert_complete_partial()
|
}; # assert_complete_partial()
|
||||||
|
|
||||||
|
|
||||||
|
# See also: bash_completion._ltrim_colon_completions
|
||||||
|
proc _ltrim_colon_completions {cword items} {
|
||||||
|
upvar 1 $cword cword_out
|
||||||
|
upvar 1 $items items_out
|
||||||
|
# If word-to-complete contains a colon,
|
||||||
|
# and bash-version < 4,
|
||||||
|
# or bash-version >= 4 and COMP_WORDBREAKS contains a colon
|
||||||
|
if {
|
||||||
|
[string first : $cword_out] > -1 && (
|
||||||
|
$::bash_versinfo_0 < 4 ||
|
||||||
|
($::bash_versinfo_0 >= 4 && [string first ":" $::COMP_WORDBREAKS] > -1)
|
||||||
|
)
|
||||||
|
} {
|
||||||
|
for {set i 0} {$i < [llength $items_out]} {incr i} {
|
||||||
|
set item [lindex $items_out $i]
|
||||||
|
if {[string first $cword_out $item] == 0} {
|
||||||
|
# Strip colon-prefix
|
||||||
|
lset items_out $i [string range $item [string length $cword_out] end]
|
||||||
|
}; # if
|
||||||
|
}; # for
|
||||||
|
#set cword_out ""
|
||||||
|
}; # if
|
||||||
|
}; # _ltrim_colon_completions()
|
||||||
|
|
||||||
|
|
||||||
# Make sure the bash environment hasn't changed between now and the last call
|
# Make sure the bash environment hasn't changed between now and the last call
|
||||||
# to `save_env()'.
|
# to `save_env()'.
|
||||||
# @param string $sed Sed commands to preprocess diff output.
|
# @param string $sed Sed commands to preprocess diff output.
|
||||||
@ -422,6 +466,7 @@ proc get_signals {} {
|
|||||||
proc match_items {items test {size 20}} {
|
proc match_items {items test {size 20}} {
|
||||||
# NOTE: `exec sort' is used instead of `lsort' to achieve exactly the
|
# NOTE: `exec sort' is used instead of `lsort' to achieve exactly the
|
||||||
# same sort order as in bash -- FVu, Wed Nov 25 22:25:28 CET 2009
|
# same sort order as in bash -- FVu, Wed Nov 25 22:25:28 CET 2009
|
||||||
|
#set items [list [exec sort << [join $items "\n"]]]
|
||||||
set items [exec sort << [join $items "\n"]]
|
set items [exec sort << [join $items "\n"]]
|
||||||
set result false
|
set result false
|
||||||
for {set i 0} {$i < [llength $items]} {set i [expr {$i + $size}]} {
|
for {set i 0} {$i < [llength $items]} {set i [expr {$i + $size}]} {
|
||||||
|
@ -8,7 +8,7 @@ proc unit_exit {} {
|
|||||||
|
|
||||||
|
|
||||||
proc unit_start {} {
|
proc unit_start {} {
|
||||||
global bash_versinfo_0 TESTDIR TOOL_EXECUTABLE spawn_id
|
global bash_versinfo_0 COMP_WORDBREAKS TESTDIR TOOL_EXECUTABLE spawn_id
|
||||||
set test "unit_start"
|
set test "unit_start"
|
||||||
set TESTDIR [pwd]
|
set TESTDIR [pwd]
|
||||||
|
|
||||||
@ -29,6 +29,7 @@ proc unit_start {} {
|
|||||||
assert_bash_exec {source $BASH_COMPLETION}
|
assert_bash_exec {source $BASH_COMPLETION}
|
||||||
# Fill global var `bash_versinfo_0' with bash major version number
|
# Fill global var `bash_versinfo_0' with bash major version number
|
||||||
assert_bash_exec {printf "%s" "${BASH_VERSINFO[0]}"} "" /@ bash_versinfo_0
|
assert_bash_exec {printf "%s" "${BASH_VERSINFO[0]}"} "" /@ bash_versinfo_0
|
||||||
|
assert_bash_exec {printf "%s" "$COMP_WORDBREAKS"} {} /@ COMP_WORDBREAKS
|
||||||
}; # unit_start()
|
}; # unit_start()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user