diff options
author | Freddy Vulto <fvulto@gmail.com> | 2010-01-24 10:32:41 +0100 |
---|---|---|
committer | Freddy Vulto <fvulto@gmail.com> | 2010-01-24 10:32:41 +0100 |
commit | dde071d0095fd21db7d2bafea4604feb9cc7b89d (patch) | |
tree | be531a160dcb96ae695676d00f3e5b365c363c98 | |
parent | e24fc84c8daa7288017a0e2403970235d0a4bc60 (diff) | |
download | bash-completion-dde071d0095fd21db7d2bafea4604feb9cc7b89d.tar.gz |
(testsuite) Fixed finger test
Added test suite function `get_known_hosts' which calls bash's `_known_hosts_real'.
Also the `finger' test "Tab should complete partial hostname" now skips hosts starting with character in COMP_WORDBREAKS leaving that to test for another test case.
See also: https://alioth.debian.org/tracker/?func=detail&atid=413095&aid=312220&group_id=100114
-rw-r--r-- | test/lib/completions/finger.exp | 19 | ||||
-rw-r--r-- | test/lib/library.exp | 14 |
2 files changed, 23 insertions, 10 deletions
diff --git a/test/lib/completions/finger.exp b/test/lib/completions/finger.exp index 4ad21cf0..31ce04fb 100644 --- a/test/lib/completions/finger.exp +++ b/test/lib/completions/finger.exp @@ -32,15 +32,20 @@ sync_after_int set test "Tab should complete partial hostname" # Build string list of hostnames, starting with the character of the first -# host. +# host, unless host starts with a COMP_WORDBREAKS character, e.g. a colon (:). +# Hosts starting with a COMP_WORDBREAKS character are left out because these +# are exceptional cases, requiring specific tests. set hosts {} set char "" -foreach h [get_hosts] { - if {$char == ""} {set char [string range $h 0 0]} - # Only append hostname if starting with $char - if {[string range $h 0 0] == "$char"} { - # Prefix hosts with username 'test@' - lappend hosts "test@$h" +foreach h [get_known_hosts] { + set first [string range $h 0 0] + if {$char == "" && [string first $first $COMP_WORDBREAKS] == -1} {set char $first} + if {$char != ""} { + # Only append hostname if starting with $char + if {$first == $char} { + # Prefix hosts with username 'test@' + lappend hosts "test@$h" + }; # if }; # if }; # foreach assert_complete $hosts "finger test@$char" $test diff --git a/test/lib/library.exp b/test/lib/library.exp index fe07dccf..ade7873d 100644 --- a/test/lib/library.exp +++ b/test/lib/library.exp @@ -7,15 +7,13 @@ package require textutil::string # Execute a bash command and make sure the exit status is successful. -# The command is expected to return no output. See `assert_bash_exec_out' if -# you want to catch output from the bash command. # If not, output the error message. # @param string $cmd Bash command line to execute. If empty string (""), the # exit status of the previously executed bash command will be # checked; specify `title' to adorn the error message. # @param string $title (optional) Command title. If empty, `cmd' is used. # @param string $prompt (optional) Bash prompt. Default is "/@" -# @param mixed $out (optional) Reference to variable to hold output. +# @param mixed $out (optional) Reference to (tcl) variable to hold output. # If variable equals -1 (default) the bash command is expected # to return no output. If variable equals 0, any output # from the bash command is disregarded. @@ -427,8 +425,18 @@ proc bash_sort {items} { }; # bash_sort() +# Get 'known' hostnames. Looks also in ssh's 'known_hosts' files. +# @return list Hostnames +# @see get_hosts() +proc get_known_hosts {} { + assert_bash_exec {_known_hosts_real ''; echo_array COMPREPLY} {} /@ result + return $result +}; # get_known_hosts() + + # Get hostnames # @return list Hostnames +# @see get_known_hosts() proc get_hosts {} { set hosts [exec bash -c "compgen -A hostname"] # NOTE: Circumventing var `avahi_hosts' and appending directly to `hosts' |