[Bash-completion-commits] [SCM] bash-completion branch, master, updated. dde071d0095fd21db7d2bafea4604feb9cc7b89d

Freddy Vulto fvulto at gmail.com
Sun Jan 24 09:35:14 UTC 2010


The following commit has been merged in the master branch:
commit dde071d0095fd21db7d2bafea4604feb9cc7b89d
Author: Freddy Vulto <fvulto at gmail.com>
Date:   Sun Jan 24 10:32:41 2010 +0100

    (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

diff --git a/test/lib/completions/finger.exp b/test/lib/completions/finger.exp
index 4ad21cf..31ce04f 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 fe07dcc..ade7873 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'

-- 
bash-completion



More information about the Bash-completion-commits mailing list