Refactored xhost & alias completion tests
This commit is contained in:
parent
33118de1f6
commit
ad1b60a3de
@ -1,25 +1,13 @@
|
|||||||
proc setup {} {
|
proc setup {} {
|
||||||
set test setup
|
assert_bash_exec "unalias -a"; # Remove all aliases
|
||||||
set cmd "unalias -a"; # Remove all aliases
|
assert_bash_exec "alias foo=bar"
|
||||||
send "$cmd\r"
|
assert_bash_exec "alias bar='foo foo'"
|
||||||
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/@"
|
|
||||||
|
|
||||||
save_env
|
save_env
|
||||||
}; # setup()
|
}; # setup()
|
||||||
|
|
||||||
|
|
||||||
proc teardown {} {
|
proc teardown {} {
|
||||||
set test teardown
|
assert_bash_exec "unalias -a"; # Remove all aliases
|
||||||
set cmd "unalias -a"; # Remove all aliases
|
|
||||||
send "$cmd\r"
|
|
||||||
expect -ex "$cmd\r\n/@"
|
|
||||||
|
|
||||||
assert_env_unmodified
|
assert_env_unmodified
|
||||||
}; # teardown()
|
}; # teardown()
|
||||||
|
|
||||||
@ -30,13 +18,7 @@ setup
|
|||||||
set test "Tab should complete alias"
|
set test "Tab should complete alias"
|
||||||
# Try completion
|
# Try completion
|
||||||
set cmd "alias "
|
set cmd "alias "
|
||||||
send "$cmd\t"
|
assert_complete {bar foo} $cmd $test
|
||||||
set expected "^$cmd\r\nbar +foo *\r\n/@$cmd$"
|
|
||||||
expect {
|
|
||||||
-re $expected { pass "$test" }
|
|
||||||
-re /@ { unresolved "$test at prompt" }
|
|
||||||
default { unresolved "$test" }
|
|
||||||
}; # expect
|
|
||||||
|
|
||||||
|
|
||||||
sync_after_int
|
sync_after_int
|
||||||
|
@ -12,197 +12,85 @@ setup
|
|||||||
|
|
||||||
|
|
||||||
set test "Tab should complete hostnames"
|
set test "Tab should complete hostnames"
|
||||||
|
# Build string list of hostnames
|
||||||
# Build string list of hostnames, separated by regexp whitespace (\s+)
|
|
||||||
# Example string: host1\s+host2\s+host3
|
|
||||||
|
|
||||||
set hosts {}
|
set hosts {}
|
||||||
foreach h [exec bash -c "compgen -A hostname"] {
|
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
|
}; # foreach
|
||||||
set hosts [lsort -ascii $hosts]
|
assert_complete $hosts "xhost " $test
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
sync_after_int
|
sync_after_int
|
||||||
|
|
||||||
|
|
||||||
set test "Tab should complete partial hostname"
|
set test "Tab should complete partial hostname"
|
||||||
|
# Build string list of hostnames, starting with the character of the first hostname
|
||||||
# Build string list of hostnames, separated by regexp whitespace (\s+)
|
|
||||||
# Example string: host1\s+host2\s+host3
|
|
||||||
|
|
||||||
set hosts {}
|
set hosts {}
|
||||||
set char ""
|
set char ""
|
||||||
foreach h [exec bash -c "compgen -A hostname"] {
|
foreach h [exec bash -c "compgen -A hostname"] {
|
||||||
if {$char == ""} {set char [string range $h 0 0]}
|
if {$char == ""} {set char [string range $h 0 0]}
|
||||||
# Only append hostname if starting with $char
|
# Only append hostname if starting with $char
|
||||||
if {[string range $h 0 0] == "$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
|
}; # if
|
||||||
}; # foreach
|
}; # foreach
|
||||||
# Try completion
|
assert_complete $hosts "xhost $char" $test
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
sync_after_int
|
sync_after_int
|
||||||
|
|
||||||
|
|
||||||
set test "Tab should complete hostnames prefixed with +"
|
set test "Tab should complete hostnames prefixed with +"
|
||||||
|
# Build string list of hostnames, prefixed with plus (+)
|
||||||
# Build string list of hostnames, separated by regexp whitespace (\s+) and
|
|
||||||
# 'plus' (+) prefix
|
|
||||||
# Example string: \+host1\s+\+host2\s+\+host3
|
|
||||||
|
|
||||||
set hosts {}
|
set hosts {}
|
||||||
foreach h [exec bash -c "compgen -A hostname"] {
|
foreach h [exec bash -c "compgen -A hostname"] {
|
||||||
# Escape special regexp characters (+) in hostname
|
lappend hosts "+$h"
|
||||||
regsub -all {([\+])} $h {\\\1} h
|
|
||||||
lappend hosts $h
|
|
||||||
}; # foreach
|
}; # foreach
|
||||||
set hosts [lsort -ascii $hosts]
|
assert_complete $hosts "xhost \+" $test
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
sync_after_int
|
sync_after_int
|
||||||
|
|
||||||
|
|
||||||
set test "Tab should complete partial hostname prefixed with +"
|
set test "Tab should complete partial hostname prefixed with +"
|
||||||
|
# Build string list of hostnames, starting with character of first host.
|
||||||
# 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
|
|
||||||
|
|
||||||
set hosts {}
|
set hosts {}
|
||||||
foreach h [exec bash -c "compgen -A hostname"] {
|
foreach h [exec bash -c "compgen -A hostname"] {
|
||||||
if {$char == ""} {set char [string range $h 0 0]}
|
if {$char == ""} {set char [string range $h 0 0]}
|
||||||
# Only append hostname if starting with $char
|
# Only append hostname if starting with $char
|
||||||
if {[string range $h 0 0] == "$char"} {
|
if {[string range $h 0 0] == "$char"} {
|
||||||
# Escape special regexp characters (+) in hostname
|
lappend hosts "+$h"
|
||||||
regsub -all {([\+])} $h {\\\1} h
|
|
||||||
lappend hosts $h
|
|
||||||
}; # if
|
}; # if
|
||||||
}; # foreach
|
}; # foreach
|
||||||
# Try completion
|
assert_complete $hosts "xhost +$char"
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
sync_after_int
|
sync_after_int
|
||||||
|
|
||||||
|
|
||||||
set test "Tab should complete hostnames prefixed with -"
|
set test "Tab should complete hostnames prefixed with -"
|
||||||
|
# Build string list of hostnames, prefix with minus (-)
|
||||||
# Build string list of hostnames, separated by regexp whitespace (\s+) and
|
|
||||||
# 'minus' (-) prefix
|
|
||||||
# Example string: -host1\s+-host2\s+-host3
|
|
||||||
|
|
||||||
set hosts {}
|
set hosts {}
|
||||||
foreach h [exec bash -c "compgen -A hostname"] {
|
foreach h [exec bash -c "compgen -A hostname"] {
|
||||||
# Escape special regexp characters (+) in hostname
|
lappend hosts "-$h"
|
||||||
regsub -all {([\+])} $h {\\\1} h
|
|
||||||
lappend hosts $h
|
|
||||||
}; # foreach
|
}; # foreach
|
||||||
set hosts [lsort -ascii $hosts]
|
assert_complete $hosts "xhost -" $test
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
sync_after_int
|
sync_after_int
|
||||||
|
|
||||||
|
|
||||||
set test "Tab should complete partial hostname prefixed with -"
|
set test "Tab should complete partial hostname prefixed with -"
|
||||||
|
# Build list of hostnames, starting with character of first host
|
||||||
# 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
|
|
||||||
|
|
||||||
set hosts {}
|
set hosts {}
|
||||||
foreach h [exec bash -c "compgen -A hostname"] {
|
foreach h [exec bash -c "compgen -A hostname"] {
|
||||||
if {$char == ""} {set char [string range $h 0 0]}
|
if {$char == ""} {set char [string range $h 0 0]}
|
||||||
# Only append hostname if starting with $char
|
# Only append hostname if starting with $char
|
||||||
if {[string range $h 0 0] == "$char"} {
|
if {[string range $h 0 0] == "$char"} {
|
||||||
# Escape special regexp characters (+) in hostname
|
lappend hosts "-$h"
|
||||||
regsub -all {([\+])} $h {\\\1} h
|
|
||||||
lappend hosts $h
|
|
||||||
}; # if
|
}; # if
|
||||||
}; # foreach
|
}; # foreach
|
||||||
# Try completion
|
assert_complete $hosts "xhost -$char" $test
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
sync_after_int
|
sync_after_int
|
||||||
|
@ -71,7 +71,7 @@ proc assert_complete {expected cmd {test ""} {prompt /@} {size 20}} {
|
|||||||
pass "$test"
|
pass "$test"
|
||||||
} else {
|
} else {
|
||||||
expect {
|
expect {
|
||||||
-re "$prompt$cmd$" { pass "$test" }
|
-ex "$prompt$cmd" { pass "$test" }
|
||||||
-re $prompt { unresolved "$test at prompt" }
|
-re $prompt { unresolved "$test at prompt" }
|
||||||
-re eof { unresolved "eof" }
|
-re eof { unresolved "eof" }
|
||||||
}; # expect
|
}; # expect
|
||||||
|
Loading…
x
Reference in New Issue
Block a user