(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).
This commit is contained in:
Freddy Vulto 2010-10-31 17:51:14 +01:00
parent 50dd6c7ac6
commit 83bcd69557
3 changed files with 70 additions and 23 deletions

View File

@ -101,7 +101,7 @@ assert_bash_exec "cd $dir" "" $prompt
set cmd "scp -F 'spaced conf' " set cmd "scp -F 'spaced conf' "
send "$cmd\t" send "$cmd\t"
expect -ex "$cmd\r\n" expect -ex "$cmd\r\n"
if {[match_items [lsort -unique $expected] $test]} { if {[match_items [lsort -unique $expected] -bash-sort]} {
expect { expect {
-re $prompt { pass "$test" } -re $prompt { pass "$test" }
-re eof { unresolved "eof" } -re eof { unresolved "eof" }

View File

@ -2,6 +2,7 @@
# NOTE: DejaGnu has an old `unknown' procedure which unfortunately disables # NOTE: DejaGnu has an old `unknown' procedure which unfortunately disables
# tcl auto-loading. # tcl auto-loading.
source [file join [info library] init.tcl] source [file join [info library] init.tcl]
package require cmdline
package require textutil::string 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. # Make sure the expected list matches the real list, as returned by executing
# @param list $expected # the specified bash command.
# @param string $cmd Command given to generate items # Specify `-sort' if the real list is sorted.
# @param string $test (optional) Test title. Default is "$cmd<TAB> should show completions" # @param list $expected Expected list items
# @param string $prompt (optional) Bash prompt. Default is "/@" # @param string $cmd Bash command to execute in order to generate real list
# @param integer $size (optional) Chunk size. Default is 20. # items
# @result boolean True if successful, False if not # @param string $test Test title. Becomes "$cmd should show expected output"
proc assert_bash_list {expected cmd {test ""} {prompt /@} {size 20}} { # 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 {$test == ""} {set test "$cmd should show expected output"}
if {[llength $expected] == 0} { if {[llength $expected] == 0} {
assert_no_output $cmd $test $prompt assert_no_output $cmd $test $prompt
} else { } else {
send "$cmd\r" send "$cmd\r"
expect -ex "$cmd\r\n" expect -ex "$cmd\r\n"
if {$arg(sort)} {set bash_sort "-bash-sort"} else {set bash_sort ""}
if {[match_items $expected $test $prompt $size]} { if {[
match_items $expected $bash_sort -chunk-size $arg(chunk-size) \
-prompt $prompt
]} {
expect { expect {
-re $prompt { pass "$test" } -re $prompt { pass "$test" }
-re eof { unresolved "eof" } -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}} { # Make sure the expected list matches the real list, as returned by executing
set prompt "/$dir/@" # 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_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 sync_after_int $prompt
assert_bash_exec {cd "$TESTDIR"} 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 _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} { if {[llength $expected] == 1} {
pass "$test" pass "$test"
} else { } 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 # Break items into chunks because `expect' seems to have a limited buffer size
# @param list $items # @param list $items Expected list items
# @param integer $size Chunk size # @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 # @result boolean True if successful, False if not
proc match_items {items test {prompt /@} {size 20}} { proc match_items {items {args {}}} {
set items [bash_sort $items] 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 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}]} {
# For chunks > 1, allow leading whitespace # For chunks > 1, allow leading whitespace

View File

@ -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 # 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 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} 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 sync_after_int
@ -38,7 +38,7 @@ foreach host $hosts {
} }
# Call _known_hosts # Call _known_hosts
set cmd {unset COMPREPLY; _known_hosts_real -acF fixtures/_known_hosts_real/config 'user@'; echo_array COMPREPLY} 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 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 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 # Call _known_hosts
set cmd {unset COMPREPLY; _known_hosts_real -aF fixtures/_known_hosts_real/config ''; echo_array COMPREPLY} 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 sync_after_int
assert_bash_exec "unset -v COMP_KNOWN_HOSTS_WITH_HOSTFILE" assert_bash_exec "unset -v COMP_KNOWN_HOSTS_WITH_HOSTFILE"