diff --git a/test/completion/xhost.exp b/test/completion/xhost.exp new file mode 100644 index 00000000..e79abf5d --- /dev/null +++ b/test/completion/xhost.exp @@ -0,0 +1,6 @@ +source "lib/completions/xhost.exp" + +# TODO: Dynamic loading of completions. After the tests have the first time and +# real completion is installed, the tests can be run a second time. +# +# source "lib/completions/ssh.exp" diff --git a/test/lib/completions/xhost.exp b/test/lib/completions/xhost.exp new file mode 100644 index 00000000..c6e8284a --- /dev/null +++ b/test/lib/completions/xhost.exp @@ -0,0 +1,99 @@ +proc setup {} { + save_env +}; # setup() + + +proc teardown {} { + assert_env_unmodified +}; # teardown() + + +setup + + +set test "Tab should complete hostnames" + + # Build string list of hostnames, separated by regexp whitespace (\s+) + # Example string: host1\s+host2\s+host3 + +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 + + +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 + +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" + # 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 + + +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 + +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 + + +sync_after_int + + +teardown