[Bash-completion-commits] [SCM] bash-completion branch, master, updated. ad1b60a3de12aa9490efa98ec4aee97f4ee3f469
Freddy Vulto
fvulto at gmail.com
Sun Jun 14 11:16:11 UTC 2009
The following commit has been merged in the master branch:
commit ad1b60a3de12aa9490efa98ec4aee97f4ee3f469
Author: Freddy Vulto <fvulto at gmail.com>
Date: Sun Jun 14 13:15:06 2009 +0200
Refactored xhost & alias completion tests
diff --git a/test/lib/completions/alias.exp b/test/lib/completions/alias.exp
index 8dd1439..e6b88d0 100644
--- a/test/lib/completions/alias.exp
+++ b/test/lib/completions/alias.exp
@@ -1,25 +1,13 @@
proc setup {} {
- set test setup
- set cmd "unalias -a"; # Remove all aliases
- send "$cmd\r"
- expect -ex "$cmd\r\n/@"
- set cmd "alias foo=bar"
- send "$cmd\r"
- expect -ex "$cmd\r\n/@"
- set cmd "alias bar='foo foo'"
- send "$cmd\r"
- expect -ex "$cmd\r\n/@"
-
+ assert_bash_exec "unalias -a"; # Remove all aliases
+ assert_bash_exec "alias foo=bar"
+ assert_bash_exec "alias bar='foo foo'"
save_env
}; # setup()
proc teardown {} {
- set test teardown
- set cmd "unalias -a"; # Remove all aliases
- send "$cmd\r"
- expect -ex "$cmd\r\n/@"
-
+ assert_bash_exec "unalias -a"; # Remove all aliases
assert_env_unmodified
}; # teardown()
@@ -30,13 +18,7 @@ setup
set test "Tab should complete alias"
# Try completion
set cmd "alias "
-send "$cmd\t"
-set expected "^$cmd\r\nbar +foo *\r\n/@$cmd$"
-expect {
- -re $expected { pass "$test" }
- -re /@ { unresolved "$test at prompt" }
- default { unresolved "$test" }
-}; # expect
+assert_complete {bar foo} $cmd $test
sync_after_int
diff --git a/test/lib/completions/xhost.exp b/test/lib/completions/xhost.exp
index d7f320d..584a5f7 100644
--- a/test/lib/completions/xhost.exp
+++ b/test/lib/completions/xhost.exp
@@ -12,197 +12,85 @@ setup
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
lappend hosts $h
}; # foreach
-set hosts [lsort -ascii $hosts]
-set hosts [join $hosts "\\s+"]
- # Try completion
-set cmd "xhost "
-send "$cmd\t"
-set expected "^$cmd\r\n$hosts\r\n/@$cmd$"
-expect {
- -re $expected { pass "$test" }
- -re /@ { unresolved "$test at prompt" }
- default { unresolved "$test" }
-}; # expect
+assert_complete $hosts "xhost " $test
sync_after_int
set test "Tab should complete partial hostname"
-
- # Build string list of hostnames, separated by regexp whitespace (\s+)
- # Example string: host1\s+host2\s+host3
-
+# Build string list of hostnames, starting with the character of the first hostname
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
lappend hosts $h
}; # if
}; # foreach
- # Try completion
-set cmd "xhost $char"
-send "$cmd\t"
- # Escape possible special regexp characters (+) in cmd
-regsub -all {([\+])} $cmd {\\\1} cmd
-if {[llength $hosts] == 1} {
- set expected "^xhost $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 "xhost $char" $test
sync_after_int
set test "Tab should complete hostnames prefixed with +"
-
- # Build string list of hostnames, separated by regexp whitespace (\s+) and
- # 'plus' (+) prefix
- # Example string: \+host1\s+\+host2\s+\+host3
-
+# Build string list of hostnames, prefixed with plus (+)
set hosts {}
foreach h [exec bash -c "compgen -A hostname"] {
- # Escape special regexp characters (+) in hostname
- regsub -all {([\+])} $h {\\\1} h
- lappend hosts $h
+ lappend hosts "+$h"
}; # foreach
-set hosts [lsort -ascii $hosts]
-set hosts "\\+[join $hosts "\\s+\\+"]"
- # Try completion
-set cmd "xhost +"
-send "$cmd\t"
- # Escape special regexp characters (+) in cmd
-regsub -all {([\+])} $cmd {\\\1} cmd
-set expected "^$cmd\r\n$hosts\r\n/@$cmd$"
-expect {
- -re $expected { pass "$test" }
- -re /@ { unresolved "$test at prompt" }
- default { unresolved "$test" }
-}; # expect
+assert_complete $hosts "xhost \+" $test
sync_after_int
set test "Tab should complete partial hostname prefixed with +"
-
- # 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 character of first host.
set hosts {}
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
- lappend hosts $h
+ lappend hosts "+$h"
}; # if
}; # foreach
- # Try completion
-set cmd "xhost +$char"
-send "$cmd\t"
-if {[llength $hosts] == 1} {
- set expected "^xhost \\+$hosts "
-} else {
- # Escape special regexp characters (+) in cmd
- regsub -all {([\+])} $cmd {\\\1} cmd
- 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 "xhost +$char"
sync_after_int
set test "Tab should complete hostnames prefixed with -"
-
- # Build string list of hostnames, separated by regexp whitespace (\s+) and
- # 'minus' (-) prefix
- # Example string: -host1\s+-host2\s+-host3
-
+ # Build string list of hostnames, prefix with minus (-)
set hosts {}
foreach h [exec bash -c "compgen -A hostname"] {
- # Escape special regexp characters (+) in hostname
- regsub -all {([\+])} $h {\\\1} h
- lappend hosts $h
+ lappend hosts "-$h"
}; # foreach
-set hosts [lsort -ascii $hosts]
-set hosts "-[join $hosts "\\s+-"]"
- # Try completion
-set cmd "xhost -"
-send "$cmd\t"
-set expected "^$cmd\r\n$hosts\r\n/@$cmd$"
-expect {
- -re $expected { pass "$test" }
- -re /@ { unresolved "$test at prompt" }
- default { unresolved "$test" }
-}; # expect
+assert_complete $hosts "xhost -" $test
sync_after_int
set test "Tab should complete partial hostname prefixed with -"
-
- # Build string list of hostnames, starting with the character of the first
- # host. Separate hostnames by regexp whitespace (\s+) and 'minus' (-)
- # prefix. Example string: -host1\s+-host2\s+-host3
-
+ # Build list of hostnames, starting with character of first host
set hosts {}
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
- lappend hosts $h
+ lappend hosts "-$h"
}; # if
}; # foreach
- # Try completion
-set cmd "xhost -$char"
-send "$cmd\t"
-if {[llength $hosts] == 1} {
- set expected "^xhost -$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 "xhost -$char" $test
sync_after_int
diff --git a/test/lib/library.exp b/test/lib/library.exp
index 1be3600..2f78b8c 100644
--- a/test/lib/library.exp
+++ b/test/lib/library.exp
@@ -71,7 +71,7 @@ proc assert_complete {expected cmd {test ""} {prompt /@} {size 20}} {
pass "$test"
} else {
expect {
- -re "$prompt$cmd$" { pass "$test" }
+ -ex "$prompt$cmd" { pass "$test" }
-re $prompt { unresolved "$test at prompt" }
-re eof { unresolved "eof" }
}; # expect
--
bash-completion
More information about the Bash-completion-commits
mailing list