diff --git a/test/lib/library.exp b/test/lib/library.exp index 491da212..9cd77c99 100644 --- a/test/lib/library.exp +++ b/test/lib/library.exp @@ -633,10 +633,17 @@ proc get_known_hosts {{cword ''}} { # Get hostnames +# @param list $args Options: +# --unsorted Do not sort unique. Default is sort unique. # @return list Hostnames # @see get_known_hosts() -proc get_hosts {} { - set hosts [exec bash -c "compgen -A hostname | sort -u"] +proc get_hosts {{args {}}} { + array set arg [::cmdline::getoptions args { + {unsorted "do not sort unique"} + }] + set sort "| sort -u" + if {$arg(unsorted)} {set sort ""} + set hosts [exec bash -c "compgen -A hostname $sort"] # NOTE: Circumventing var `avahi_hosts' and appending directly to `hosts' # causes an empty element to be inserted in `hosts'. # -- FVu, Fri Jul 17 23:11:46 CEST 2009 diff --git a/test/unit/_known_hosts_real.exp b/test/unit/_known_hosts_real.exp index 604b2d5e..0e381fa7 100644 --- a/test/unit/_known_hosts_real.exp +++ b/test/unit/_known_hosts_real.exp @@ -19,7 +19,7 @@ setup set test "Hosts should be put in COMPREPLY" -set hosts [get_hosts] +set hosts [get_hosts -unsorted] # Hosts `gee', `hus' and `jar' are defined in ./fixtures/_known_hosts_real/config # doo, ike, jub, 10.0.0.1, kyl, 100.0.0.2, 10.10.0.3, blah, and bunch of IPv6 test cases in ./fixtures/_known_hosts_real/known_hosts lappend hosts blah doo gee hus ike jar jub kyl 10.0.0.1 100.0.0.2 10.10.0.3 fd00:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:5555 fe80::123:0xff:dead:beef%eth0 1111:2222:3333:4444:5555:6666:xxxx:abab 11xx:2222:3333:4444:5555:6666:xxxx:abab ::42 @@ -31,7 +31,7 @@ sync_after_int set test "Hosts should have username prefix and colon suffix" -set hosts [get_hosts] +set hosts [get_hosts -unsorted] # Hosts `gee', `hus' and `jar' are defined in ./fixtures/_known_hosts_real/config # doo, ike, jub, 10.0.0.1, kyl, 100.0.0.2, 10.10.0.3, blah, and bunch of IPv6 test cases in ./fixtures/_known_hosts_real/known_hosts lappend hosts blah doo gee hus ike jar jub kyl 10.0.0.1 100.0.0.2 10.10.0.3 fd00:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:5555 fe80::123:0xff:dead:beef%eth0 1111:2222:3333:4444:5555:6666:xxxx:abab 11xx:2222:3333:4444:5555:6666:xxxx:abab ::42 @@ -49,7 +49,7 @@ sync_after_int set test "Files containing consecutive spaces should work" -set hosts [get_hosts] +set hosts [get_hosts -unsorted] set hosts_orig $hosts # Hosts `gee' and `hus' are defined in `./fixtures/_known_hosts_real/spaced conf' # Host `two' is defined in ./fixtures/_known_hosts_real/known_hosts2 @@ -77,7 +77,7 @@ sync_after_int set test "Files starting with tilde (~) should work" -set hosts [get_hosts] +set hosts [get_hosts -unsorted] # Host `two' is defined in ./fixtures/_known_hosts_real/known_hosts2 # Host `three' is defined in ./fixtures/_known_hosts_real/known_hosts3 lappend hosts two three