[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 83bcd69557bcdecb6a6e2b42d5482dfb9e0d65b7
Freddy Vulto
fvulto at gmail.com
Sun Oct 31 16:52:38 UTC 2010
The following commit has been merged in the master branch:
commit 83bcd69557bcdecb6a6e2b42d5482dfb9e0d65b7
Author: Freddy Vulto <fvulto at gmail.com>
Date: Sun Oct 31 17:51:14 2010 +0100
(testsuite) Fix _parse_help for LANG=POSIX
Steps to reproduce the problem:
$ LANG=POSIX ./run unit/_parse_help.exp
...
Running ./unit/_parse_help.exp ...
FAIL: short + long
FAIL: short + long, slash separated
Cause:
When comparing list items, `assert_bash_list()' expects the real list to be
sorted, whereas the output of `_parse_help' is unsorted.
These particular two tests were failing because they suffered the
following LANG-dependant sort-difference:
$ cat t.txt
-m
--n
$ LANG=en_US.UTF-8 sort t.txt
-m
--n
$ LANG=POSIX sort t.txt
--n
-m
Solution:
Made to default for `assert_bash_list' more-intuitive: unsorted, and added an
option `-sort' to explicitly enable sorting.
I felt uncomfortable adding yet another optional argument, so I seized this
opportunity to move subsequent optional arguments to single optional arguments.
E.g.:
assert_bash_list {expected cmd {test ""} {prompt /@} {size 20}} {
has now become:
# ...
# @param list $args Options:
# -nosort Compare list unsorted. Default is sorted
# -prompt Bash prompt. Default is `/@'
# -chunk-size N Compare list N items at a time. Default
# is 20.
assert_bash_list {expected cmd test {args {}}
(and the `test' argument has become mandatory).
diff --git a/test/lib/completions/scp.exp b/test/lib/completions/scp.exp
index 4ab514d..57c41b8 100644
--- a/test/lib/completions/scp.exp
+++ b/test/lib/completions/scp.exp
@@ -101,7 +101,7 @@ assert_bash_exec "cd $dir" "" $prompt
set cmd "scp -F 'spaced conf' "
send "$cmd\t"
expect -ex "$cmd\r\n"
-if {[match_items [lsort -unique $expected] $test]} {
+if {[match_items [lsort -unique $expected] -bash-sort]} {
expect {
-re $prompt { pass "$test" }
-re eof { unresolved "eof" }
diff --git a/test/lib/library.exp b/test/lib/library.exp
index c5265cc..b68f413 100644
--- a/test/lib/library.exp
+++ b/test/lib/library.exp
@@ -2,6 +2,7 @@
# NOTE: DejaGnu has an old `unknown' procedure which unfortunately disables
# tcl auto-loading.
source [file join [info library] init.tcl]
+package require cmdline
package require textutil::string
@@ -72,22 +73,37 @@ proc assert_bash_type {command} {
}
-# Make sure the expected list is returned by executing the specified command.
-# @param list $expected
-# @param string $cmd Command given to generate items
-# @param string $test (optional) Test title. Default is "$cmd<TAB> should show completions"
-# @param string $prompt (optional) Bash prompt. Default is "/@"
-# @param integer $size (optional) Chunk size. Default is 20.
-# @result boolean True if successful, False if not
-proc assert_bash_list {expected cmd {test ""} {prompt /@} {size 20}} {
+# Make sure the expected list matches the real list, as returned by executing
+# the specified bash command.
+# Specify `-sort' if the real list is sorted.
+# @param list $expected Expected list items
+# @param string $cmd Bash command to execute in order to generate real list
+# items
+# @param string $test Test title. Becomes "$cmd should show expected output"
+# if empty string.
+# @param list $args Options:
+# -sort Compare list sorted. Default is unsorted
+# -prompt Bash prompt. Default is `/@'
+# -chunk-size N Compare list N items at a time. Default
+# is 20.
+proc assert_bash_list {expected cmd test {args {}}} {
+ array set arg [::cmdline::getoptions args {
+ {sort "compare list sorted"}
+ {prompt.arg /@ "bash prompt"}
+ {chunk-size.arg 20 "compare N list items at a time"}
+ }]
+ set prompt $arg(prompt)
if {$test == ""} {set test "$cmd should show expected output"}
if {[llength $expected] == 0} {
assert_no_output $cmd $test $prompt
} else {
send "$cmd\r"
expect -ex "$cmd\r\n"
-
- if {[match_items $expected $test $prompt $size]} {
+ if {$arg(sort)} {set bash_sort "-bash-sort"} else {set bash_sort ""}
+ if {[
+ match_items $expected $bash_sort -chunk-size $arg(chunk-size) \
+ -prompt $prompt
+ ]} {
expect {
-re $prompt { pass "$test" }
-re eof { unresolved "eof" }
@@ -99,10 +115,29 @@ proc assert_bash_list {expected cmd {test ""} {prompt /@} {size 20}} {
}
-proc assert_bash_list_dir {expected cmd dir {test ""} {prompt /@} {size 20}} {
- set prompt "/$dir/@"
+# Make sure the expected list matches the real list, as returned by executing
+# the specified bash command within the specified directory.
+# Specify `-sort' if the real list is sorted.
+# @param list $expected Expected list items
+# @param string $cmd Bash command to generate real list items
+# @param string $dir Directory to execute $cmd within
+# @param string $test Test title. Becomes "$cmd should show expected output"
+# if empty string.
+# @param list $args Options:
+# -sort Compare list sorted. Default is unsorted
+# -prompt Bash prompt. Default is `/$dir/@'
+# -chunk-size N Compare list N items at a time. Default
+# is 20.
+proc assert_bash_list_dir {expected cmd dir test {args {}}} {
+ array set arg [::cmdline::getoptions args {
+ {sort "compare list sorted"}
+ {prompt.arg "/$dir/@" "bash prompt"}
+ {chunk-size.arg 20 "compare N list items at a time"}
+ }]
+ if {$arg(sort)} {set arg_sort "-sort"} else {set arg_sort ""}
assert_bash_exec "cd $dir" "" $prompt
- assert_bash_list $expected $cmd $test $prompt $size
+ assert_bash_list $expected $cmd $test $arg_sort \
+ -chunk-size $arg(chunk-size) -prompt $prompt
sync_after_int $prompt
assert_bash_exec {cd "$TESTDIR"}
}
@@ -160,7 +195,7 @@ proc assert_complete {expected cmd {test ""} {prompt /@} {size 20} {cword ""} {f
_ltrim_colon_completions cword expected
}
- if {[match_items $expected $test $prompt $size]} {
+ if {[match_items $expected -bash-sort -chunk-size $size -prompt $prompt]} {
if {[llength $expected] == 1} {
pass "$test"
} else {
@@ -602,13 +637,25 @@ proc is_cygwin {} {
}
-# Expect items.
+# Expect items, a limited number (20) at a time.
# Break items into chunks because `expect' seems to have a limited buffer size
-# @param list $items
-# @param integer $size Chunk size
+# @param list $items Expected list items
+# @param list $args Options:
+# -bash-sort Compare list bash-sorted. Default is
+# unsorted
+# -prompt PROMPT Bash prompt. Default is `/@'
+# -chunk-size CHUNK-SIZE Compare list CHUNK-SIZE items at
+# a time. Default is 20.
# @result boolean True if successful, False if not
-proc match_items {items test {prompt /@} {size 20}} {
- set items [bash_sort $items]
+proc match_items {items {args {}}} {
+ array set arg [::cmdline::getoptions args {
+ {bash-sort "compare list sorted"}
+ {prompt.arg "/@" "bash prompt"}
+ {chunk-size.arg 20 "compare N list items at a time"}
+ }]
+ set prompt $arg(prompt)
+ set size $arg(chunk-size)
+ if {$arg(bash-sort)} {set items [bash_sort $items]}
set result false
for {set i 0} {$i < [llength $items]} {set i [expr {$i + $size}]} {
# For chunks > 1, allow leading whitespace
diff --git a/test/unit/_known_hosts_real.exp b/test/unit/_known_hosts_real.exp
index c23a9ce..3276edb 100644
--- a/test/unit/_known_hosts_real.exp
+++ b/test/unit/_known_hosts_real.exp
@@ -20,7 +20,7 @@ set hosts [get_hosts]
# 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
set cmd {unset COMPREPLY; _known_hosts_real -aF fixtures/_known_hosts_real/config ''; echo_array COMPREPLY}
-assert_bash_list $hosts $cmd $test
+assert_bash_list $hosts $cmd $test -sort
sync_after_int
@@ -38,7 +38,7 @@ foreach host $hosts {
}
# Call _known_hosts
set cmd {unset COMPREPLY; _known_hosts_real -acF fixtures/_known_hosts_real/config 'user@'; echo_array COMPREPLY}
-assert_bash_list $expected $cmd $test
+assert_bash_list $expected $cmd $test -sort
sync_after_int
@@ -107,7 +107,7 @@ set hosts [get_hosts_avahi]
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
# Call _known_hosts
set cmd {unset COMPREPLY; _known_hosts_real -aF fixtures/_known_hosts_real/config ''; echo_array COMPREPLY}
-assert_bash_list $hosts $cmd $test
+assert_bash_list $hosts $cmd $test -sort
sync_after_int
assert_bash_exec "unset -v COMP_KNOWN_HOSTS_WITH_HOSTFILE"
--
bash-completion
More information about the Bash-completion-commits
mailing list