[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 33118de1f6416f13fe473a2c9fc2bc38e11a7fe7
Freddy Vulto
fvulto at gmail.com
Sun Jun 14 10:20:15 UTC 2009
The following commit has been merged in the master branch:
commit 33118de1f6416f13fe473a2c9fc2bc38e11a7fe7
Author: Freddy Vulto <fvulto at gmail.com>
Date: Sun Jun 14 12:18:24 2009 +0200
Refactored finger test
diff --git a/test/lib/completions/finger.exp b/test/lib/completions/finger.exp
index c49073a..93ee9ed 100644
--- a/test/lib/completions/finger.exp
+++ b/test/lib/completions/finger.exp
@@ -12,134 +12,62 @@ setup
set test "Tab should complete usernames"
-
- # Build string list of usernames, separated by regexp whitespace (\s+)
- # Example string: user1\s+user2\s+user3
-
+# Build string list of usernames
set users {}
foreach u [exec bash -c "compgen -A user"] {
- # Escape special regexp characters (+) in username
- regsub -all {([\+])} $u {\\\1} h
lappend users $u
}; # foreach
-set users [lsort -ascii $users]
-set users [join $users "\\s+"]
- # Try completion
-set cmd "finger "
-send "$cmd\t"
-set expected "^$cmd\r\n$users\r\n/@$cmd$"
-expect {
- -re $expected { pass "$test" }
- -re /@ { unresolved "$test at prompt" }
- default { unresolved "$test" }
-}; # expect
+assert_complete $users "finger " $test
sync_after_int
set test "Tab should complete partial username"
-
- # Build string list of usernames, starting with the character of the first
- # username. Separate usernames by regexp whitespace (\s+) and 'plus' (+)
- # prefix. Example string: \+user1\s+\+user2\s+\+user3
-
+# Build string list of usernames, starting with the character of the
+# first username.
set users {}
set char ""
foreach u [exec bash -c "compgen -A user"] {
if {$char == ""} {set char [string range $u 0 0]}
# Only append username if starting with $char
if {[string range $u 0 0] == "$char"} {
- # Escape possible special regexp characters (+) in username
- regsub -all {([\+])} $u {\\\1} u
lappend users $u
}; # if
}; # foreach
- # Try completion
-set cmd "finger $char"
-send "$cmd\t"
-if {[llength $users] == 1} {
- set expected "^finger $users"
-} else {
- set users [lsort -ascii $users]
- set users [join $users "\\s+"]
- set expected "^$cmd\r\n$users\r\n/@$cmd$"
-}; # if
-expect {
- -re $expected { pass "$test" }
- -re /@ { unresolved "$test at prompt" }
- default { unresolved "$test" }
-}; # expect
+assert_complete $users "finger $char" $test
sync_after_int
set test "Tab should complete hostnames"
-
- # Build string list of hostnames, separated by regexp whitespace (\s+)
- # Example string: host1\s+host2\s+host3
-
+# Build string list of hostnames
set hosts {}
foreach h [exec bash -c "compgen -A hostname"] {
- # Escape special regexp characters (+) in hostname
- regsub -all {([\+])} $h {\\\1} h
# Prefix hosts with username 'test@'
lappend hosts "test@$h"
}; # foreach
- # Try completion
-set cmd "finger test@"
-send "$cmd\t"
-if {[llength $hosts] == 1} {
- set expected "^$cmd$hosts "
-} else {
- set hosts [lsort -ascii $hosts]
- set hosts [join $hosts "\\s+"]
- set expected "^$cmd\r\n$hosts\r\n/@$cmd$"
-}; # if
-expect {
- -re $expected { pass "$test" }
- -re /@ { unresolved "$test at prompt" }
- default { unresolved "$test" }
-}; # expect
+assert_complete $hosts "finger test@" $test
sync_after_int
set test "Tab should complete partial hostname"
-
- # Build string list of hostnames, starting with the character of the first
- # host. Separate hostnames by regexp whitespace (\s+) and 'plus' (+)
- # prefix. Example string: \+host1\s+\+host2\s+\+host3
-
+# Build string list of hostnames, starting with the character of the first
+# host.
set hosts {}
set char ""
foreach h [exec bash -c "compgen -A hostname"] {
if {$char == ""} {set char [string range $h 0 0]}
# Only append hostname if starting with $char
if {[string range $h 0 0] == "$char"} {
- # Escape special regexp characters (+) in hostname
- regsub -all {([\+])} $h {\\\1} h
# Prefix hosts with username 'test@'
lappend hosts "test@$h"
}; # if
}; # foreach
- # Try completion
-set cmd "finger test@$char"
-send "$cmd\t"
-if {[llength $hosts] == 1} {
- set expected "^finger $hosts"
-} else {
- set hosts [lsort -ascii $hosts]
- set hosts [join $hosts "\\s+"]
- set expected "^$cmd\r\n$hosts\r\n/@$cmd$"
-}; # if
-expect {
- -re $expected { pass "$test" }
- -re /@ { unresolved "$test at prompt" }
- default { unresolved "$test" }
-}; # expect
+assert_complete $hosts "finger test@$char" $test
sync_after_int
diff --git a/test/lib/library.exp b/test/lib/library.exp
index 55a01b3..1be3600 100644
--- a/test/lib/library.exp
+++ b/test/lib/library.exp
@@ -54,13 +54,28 @@ proc assert_bash_type {command} {
proc assert_complete {expected cmd {test ""} {prompt /@} {size 20}} {
if {$test == ""} {set test "$cmd should show completions"}
send "$cmd\t"
- expect -ex "$cmd\r\n"
+ if {[llength $expected] == 1} {
+ expect -ex "$cmd"
+ # Assume second word is word to complete on.
+ set cur [lindex [split $cmd] 1]
+ # Remove second word from beginning of single item $expected
+ if {[string first $cur $expected] == 0} {
+ set expected [string range $expected [string length $cur] end]
+ }; # if
+ } else {
+ expect -ex "$cmd\r\n"
+ }; # if
+
if {[match_items $expected $test]} {
- expect {
- -re "$prompt$cmd$" { pass "$test" }
- -re $prompt { unresolved "$test at prompt" }
- -re eof { unresolved "eof" }
- }
+ if {[llength $expected] == 1} {
+ pass "$test"
+ } else {
+ expect {
+ -re "$prompt$cmd$" { pass "$test" }
+ -re $prompt { unresolved "$test at prompt" }
+ -re eof { unresolved "eof" }
+ }; # expect
+ }; # if
} else {
fail "$test"
}; # if
@@ -159,6 +174,7 @@ proc assert_exec {cmd {stdout ''} {test ''}} {
# @param integer $size Chunk size
# @result boolean True if successful, False if not
proc match_items {items test {size 20}} {
+ set items [lsort -ascii $items]
set result false
for {set i 0} {$i < [llength $items]} {set i [expr {$i + $size}]} {
set expected ""
@@ -166,7 +182,8 @@ proc match_items {items test {size 20}} {
set item "[lindex $items [expr {$i + $j}]]"
# Escape special regexp characters
regsub -all {([\[\]\(\)\.\\\+])} $item {\\\1} item
- set expected "${expected}$item\\s+"
+ append expected $item
+ if {[llength $items] > 1} {append expected {\s+}}
}; # for
expect {
-re "$expected" { set result true }
--
bash-completion
More information about the Bash-completion-commits
mailing list