diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/__expand_tilde_by_ref.exp | 65 | ||||
-rw-r--r-- | test/unit/_expand.exp | 33 | ||||
-rw-r--r-- | test/unit/_filedir.exp | 124 | ||||
-rw-r--r-- | test/unit/_get_comp_words_by_ref.exp | 91 | ||||
-rw-r--r-- | test/unit/_get_cword.exp | 37 | ||||
-rw-r--r-- | test/unit/_known_hosts_real.exp | 171 |
6 files changed, 0 insertions, 521 deletions
diff --git a/test/unit/__expand_tilde_by_ref.exp b/test/unit/__expand_tilde_by_ref.exp deleted file mode 100644 index 5569fe37..00000000 --- a/test/unit/__expand_tilde_by_ref.exp +++ /dev/null @@ -1,65 +0,0 @@ -# @param string $out Reference to variable to hold value of bash environment -# variable $HOME. -proc setup {home user} { - upvar $home _home - upvar $user _user - save_env - assert_bash_exec {echo "$HOME"} {} /@ _home - set _home [string trim $_home] - assert_bash_exec {id -un 2>/dev/null || echo "$USER"} {} /@ _user - set _user [string trim $_user] -} - - -proc teardown {} { - assert_env_unmodified { - /var=/d - } -} - - -setup home user - - -set test "~user should return $home" -set cmd [format {var="~%s"; __expand_tilde_by_ref var; printf "%%s\n" "$var"} $user] -assert_bash_list "$home" $cmd $test -sync_after_int - -set test "~/foo should return $home/foo" -set cmd {var='~/foo'; __expand_tilde_by_ref var; printf "%s\n" "$var"} -assert_bash_list "$home/foo" $cmd $test -sync_after_int - -set test "~user/bar should return $home/bar" -set cmd [format {var="~%s/bar"; __expand_tilde_by_ref var; printf "%%s\n" "$var"} $user] -assert_bash_list "$home/bar" $cmd $test -sync_after_int - -set test "~user/\$HOME should return $home/\$HOME" -set cmd [format {var="~%s/\$HOME"; __expand_tilde_by_ref var; printf "%%s\n" "$var"} $user] -assert_bash_list "$home/\$HOME" $cmd $test -sync_after_int - -set test "'~user/a b' should return '$home/a b'" -set cmd [format {var="~%s/a b"; __expand_tilde_by_ref var; printf "%%s\n" "$var"} $user] -assert_bash_list [list [format {%s/a b} $home]] $cmd $test -sync_after_int - -set test "~user/* should return $home/*" -set cmd [format {var="~%s/*"; __expand_tilde_by_ref var; printf "%%s\n" "$var"} $user] -assert_bash_list "$home/\*" $cmd $test -sync_after_int - -set test "'~user;echo hello' should return '~user;echo hello' (not expanded)" -set cmd [format {var="~%s;echo hello"; __expand_tilde_by_ref var; printf "%%s\n" "$var"} $user] -assert_bash_list [format "~%s;echo hello" $user] $cmd $test -sync_after_int - -set test "'~user/a;echo hello' should return '$home/a;echo hello'" -set cmd [format {var="~%s/a;echo hello"; __expand_tilde_by_ref var; printf "%%s\n" "$var"} $user] -assert_bash_list "$home/a;echo hello" $cmd $test -sync_after_int - - -teardown diff --git a/test/unit/_expand.exp b/test/unit/_expand.exp deleted file mode 100644 index 59dbed58..00000000 --- a/test/unit/_expand.exp +++ /dev/null @@ -1,33 +0,0 @@ -proc setup {home user} { - upvar $home _home - upvar $user _user - save_env - assert_bash_exec {echo "$HOME"} {} /@ _home - set _home [string trim $_home] - assert_bash_exec {id -un 2>/dev/null || echo "$USER"} {} /@ _user - set _user [string trim $_user] -} - -proc teardown {} { - assert_env_unmodified { - /COMPREPLY=/d - /cur=/d - } -} - - -setup home user - - -set test "~$user should set $home to COMPREPLY" -set cmd [format {cur="~%s" ; _expand ; printf "%%s\n" "$COMPREPLY"} $user] -assert_bash_list "$home" $cmd $test -sync_after_int - -set test "~$user/a should set $home/a to cur" -set cmd [format {cur="~%s/a" ; _expand ; printf "%%s\n" "$cur"} $user] -assert_bash_list "$home/a" $cmd $test -sync_after_int - - -teardown diff --git a/test/unit/_filedir.exp b/test/unit/_filedir.exp deleted file mode 100644 index 1de49504..00000000 --- a/test/unit/_filedir.exp +++ /dev/null @@ -1,124 +0,0 @@ -proc setup {} { - assert_bash_exec {unset COMPREPLY cur} - assert_bash_exec {unset -f _f} - save_env - # Declare bash completion function `_f' - assert_bash_exec { \ - _f() { local cur=$(_get_cword); unset COMPREPLY; _filedir; }; \ - complete -F _f f \ - } - # Declare bash completion function `_f2' with `-o filenames' active. - assert_bash_exec { \ - complete -F _f -o filenames f2 \ - } - # Create directories `a"b', `a*b', and `a\b' only when not running on - # Cygwin/Windows (`"', `*', or `\' aren't allowed in filenames there) - if {! [is_cygwin]} { - # Create directory `a"b' - assert_bash_exec {(cd $TESTDIR/tmp && [ ! -d a\"b ] && mkdir a\"b && touch a\"b/d || true)} - # Create directory `a*b' - assert_bash_exec {(cd $TESTDIR/tmp && [ ! -d a\*b ] && mkdir a\*b && touch a\*b/j || true)} - # Create directory `a\b' - assert_bash_exec {(cd $TESTDIR/tmp && [ ! -d a\\b ] && mkdir a\\b && touch a\\b/g || true)} - } -} - - -proc teardown {} { - if {! [is_cygwin]} { - assert_bash_exec {(cd $TESTDIR/tmp && rm -- a\"b/d && rmdir a\"b/ || true)} - assert_bash_exec {(cd $TESTDIR/tmp && rm -- a\\b/g && rmdir a\\b/ || true)} - assert_bash_exec {(cd $TESTDIR/tmp && rm -- a\*b/j && rmdir a\*b/ || true)} - } - assert_bash_exec {unset COMPREPLY cur} - assert_bash_exec {unset -f _f} - assert_bash_exec {complete -r f} - assert_env_unmodified { - /OLDPWD/d - /OLD_CTYPE/d - } -} - - -setup - - -foreach name {f f2} { - - set test "completing $name a\\\$b/ should return h" - if {[info exists ::env(CI)] && [info exists ::env(DIST)] && $::env(DIST) == "centos6"} { - xfail $test - } else { - set cmd "$name a\\\$b/" - assert_complete_dir h $cmd "$::srcdir/fixtures/_filedir" $test - sync_after_int - } - - if {! [is_cygwin]} { # Illegal characters in file/dir names - set test "completing $name a\\\"b/ should return d"; #" - set cmd "$name a\\\"b/"; #" - assert_complete_dir d $cmd "$TESTDIR/tmp" $test - sync_after_int - - set test "completing $name a\\\\b/ should return g" - set cmd "$name a\\\\b/" - assert_complete_dir g $cmd "$TESTDIR/tmp" $test - sync_after_int - } - - if {! [is_cygwin]} { # Illegal characters in file/dir names - set cmd "$name 'a\"b/"; #" - assert_complete_dir {d'} $cmd "$TESTDIR/tmp" - sync_after_int - - set cmd "$name '$TESTDIR/tmp/a\\b/" - assert_complete_dir {g'} $cmd "$TESTDIR/tmp" - sync_after_int - } - - if {! [is_cygwin]} { # Illegal characters in file/dir names - set cmd "$name \"a\\\"b/"; #" - assert_complete_dir {d"} $cmd "$TESTDIR/tmp"; #" - sync_after_int - } - - if {[info exists ::env(CI)] && [info exists ::env(DIST)] && $::env(DIST) == "centos6"} { - xfail "$name \"a\\\$b/ should show completions" - } else { - set cmd "$name \"a\\\$b/"; #" - assert_complete_dir {h"} $cmd "$::srcdir/fixtures/_filedir"; #" - sync_after_int - } - - set cmd "$name \"a\\b/"; #" - assert_complete_dir "\b\b\bb/e\\\"" $cmd "$::srcdir/fixtures/_filedir" - sync_after_int - - set cmd "$name \"a\\\\b/"; #" - assert_complete_dir {g"} $cmd "$TESTDIR/tmp"; #" - sync_after_int - - set cmd "$name \\\[x" - assert_complete_dir {\[x\]} $cmd "$::srcdir/fixtures/_filedir/brackets" - sync_after_int - -}; # foreach - -set test "completing f aé should return g" -# Execute this test only with LC_CTYPE matching *UTF-8* -# See also: http://www.mail-archive.com/bash-completion-devel\ -# @lists.alioth.debian.org/msg02265.html -# Don't execute this test on expect-5.44 cause it will segfault -# See also: Alioth #312792 -if { - [string first "UTF-8" $::LC_CTYPE] != -1 && - [string first 5.44 [exp_version]] != 0 -} { - assert_complete_dir g "f aé/" "$::srcdir/fixtures/_filedir" -} else { - unsupported "$test" -} -sync_after_int - - -teardown diff --git a/test/unit/_get_comp_words_by_ref.exp b/test/unit/_get_comp_words_by_ref.exp deleted file mode 100644 index a0e1886b..00000000 --- a/test/unit/_get_comp_words_by_ref.exp +++ /dev/null @@ -1,91 +0,0 @@ -proc setup {} { - assert_bash_exec {unset COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS} - save_env -} - - -proc teardown {} { - assert_bash_exec { \ - unset COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS cur prev words cword \ - cur2 prev2 words2 cword2 \ - } - # Delete 'COMP_WORDBREAKS' occupying two lines - assert_env_unmodified { - /COMP_WORDBREAKS=/{N - d - } - } -} - - -setup - - -# See also ./lib/completions/alias.exp. Here `_get_cword' is actually tested -# by moving the cursor left into the current word. - -set test {unknown argument should raise error} -set cmd {_get_comp_words_by_ref dummy} -assert_bash_list {"bash_completion: _get_comp_words_by_ref: `dummy': unknown argument"} $cmd $test -sync_after_int - -set test "a b| to all vars"; # | = cursor position -set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=3} -assert_bash_exec $cmd -set cmd { \ - _get_comp_words_by_ref words cword prev cur; echo "${words[@]} $cword $cur $prev" \ -} -assert_bash_list {"a b 1 b a"} $cmd $test -sync_after_int - -set test "a b| to alternate vars"; # | = cursor position -set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=3;} -assert_bash_exec $cmd -set cmd {_get_comp_words_by_ref -c cur2 -p prev2 -w words2 -i cword2} -assert_bash_exec $cmd -set cmd {echo "$cur2 $prev2 ${words2[@]} $cword2"} -assert_bash_list {"b a a b 1"} $cmd $test -sync_after_int - -set test "a b| to alternate vars"; # | = cursor position -set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=3;} -assert_bash_exec $cmd -set cmd {_get_comp_words_by_ref -c cur2 -p prev2 -w words2 -i cword2} -assert_bash_exec $cmd -set cmd {echo "$cur2 $prev2 ${words2[@]} $cword2"} -assert_bash_list {"b a a b 1"} $cmd $test -sync_after_int - -set test {a b : c| with WORDBREAKS -= :}; # | = cursor position -set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3; COMP_LINE='a b : c'; COMP_POINT=7} -assert_bash_exec $cmd $test -set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"} -assert_bash_list {"a b : c"} $cmd $test -sync_after_int - -set test {a b: c| with WORDBREAKS -= :}; # | = cursor position -set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3} -append cmd {; COMP_LINE='a b: c'; COMP_POINT=6} -assert_bash_exec $cmd $test -set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"} -assert_bash_list {"a b: c"} $cmd $test -sync_after_int - -set test {a b :c| with WORDBREAKS -= :}; # | = cursor position -set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3} -append cmd {; COMP_LINE='a b :c'; COMP_POINT=6} -assert_bash_exec $cmd $test -set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"} -assert_bash_list {"a b :c"} $cmd $test -sync_after_int - -set test {a b\ :c| with WORDBREAKS -= :}; # | = cursor position -set cmd {COMP_WORDS=(a "b\\ " : c); COMP_CWORD=3} -append cmd {; COMP_LINE='a b\ :c'; COMP_POINT=7} -assert_bash_exec $cmd $test -set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"} -assert_bash_list {a "b\\ :c"} $cmd $test -sync_after_int - - -teardown diff --git a/test/unit/_get_cword.exp b/test/unit/_get_cword.exp deleted file mode 100644 index 91bcb44e..00000000 --- a/test/unit/_get_cword.exp +++ /dev/null @@ -1,37 +0,0 @@ -proc setup {} { - assert_bash_exec {unset COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS} - save_env -} - - -proc teardown {} { - assert_bash_exec {unset COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS} - # Delete 'COMP_WORDBREAKS' occupying two lines - assert_env_unmodified { - /COMP_WORDBREAKS=/{N - d - } - /_scp_path_esc=/d - } -} - - -setup - - -# See also ./lib/completions/alias.exp. Here `_get_cword' is actually tested -# by moving the cursor left into the current word. - -set test "index shouldn't drop below 0" -set dir $::srcdir/fixtures/_get_cword -set cmd "scp" -send "$cmd ääää§ se\t\r\n" -expect { - -re "index: substring expression < 0" { fail "$test" } - -re /@ { pass "$test" } - default { unresolved "$test" } -} -sync_after_int - - -teardown diff --git a/test/unit/_known_hosts_real.exp b/test/unit/_known_hosts_real.exp deleted file mode 100644 index 01b09b6b..00000000 --- a/test/unit/_known_hosts_real.exp +++ /dev/null @@ -1,171 +0,0 @@ -proc setup {} { - # NOTE: Changing dir to $SRCDIR is necessary because file locations in the - # ssh config files (e.g. UserKnownHostsFile) are relative to $SRCDIR. - assert_bash_exec {cd $SRCDIR} - save_env -} - - -proc teardown {} { - assert_env_unmodified { - /COMPREPLY=/d - /OLDHOME=/d - } - assert_bash_exec {cd $TESTDIR} -} - - -setup - - -set test "Hosts should be put in COMPREPLY" -set hosts [get_hosts -unsorted] -# Hosts `gee', `hus' and `jar' are defined in -# ./fixtures/_known_hosts_real/config -# 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 -set cmd {unset COMPREPLY; _known_hosts_real -aF fixtures/_known_hosts_real/config ''; echo_array COMPREPLY} -assert_bash_list $hosts $cmd $test -sort -sync_after_int - -set test "Hosts should have username prefix and colon suffix" -set hosts [get_hosts -unsorted] -# Hosts `gee', `hus' and `jar' are defined in -# ./fixtures/_known_hosts_real/config -# 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 -set hosts [lsort -ascii $hosts] -set expected {} -foreach host $hosts { - lappend expected "user@$host:" -} -# Call _known_hosts -set cmd {unset COMPREPLY; _known_hosts_real -acF fixtures/_known_hosts_real/config 'user@'; echo_array COMPREPLY} -assert_bash_list $expected $cmd $test -sort -sync_after_int - -set test "Files containing consecutive spaces should work" -set hosts [get_hosts -unsorted] -set hosts_orig $hosts -# Hosts `gee' and `hus' are defined in -#`./fixtures/_known_hosts_real/spaced conf' -# Hosts `two*' are defined in ./fixtures/_known_hosts_real/known_hosts2 -lappend hosts gee hus two two2 two3 two4 -set hosts_config $hosts -# Hosts `doo' and `ike' are defined in -# `./fixtures/_known_hosts_/spaced known_hosts' -lappend hosts doo ike -set hosts [join [bash_sort $hosts ] "\\s+"] -set hosts_orig [join [bash_sort $hosts_orig ] "\\s+"] -set hosts_config [join [bash_sort $hosts_config] "\\s+"] -# Call _known_hosts -set cmd {unset COMPREPLY; _known_hosts_real -aF 'fixtures/_known_hosts_real/spaced conf' ''; echo_array COMPREPLY} -send "$cmd\r" -expect -ex "$cmd\r\n" -expect { - -re "^$hosts\r\n/@$" { pass "$test" } - -re "^$hosts_orig\r\n/@$" { fail "$test (config file)" } - -re "^$hosts_config\r\n/@$" { fail "$test (known hosts file)" } - -re /@ { unresolved "$test at prompt" } - default { unresolved "$test" } -} -sync_after_int - -set test "Files starting with tilde (~) should work" -set hosts [get_hosts -unsorted] -# Hosts `two*' are defined in ./fixtures/_known_hosts_real/known_hosts2 -# Host `three' is defined in ./fixtures/_known_hosts_real/known_hosts3 -# Host `four' is defined in ./fixtures/_known_hosts_real/known_hosts4 -lappend hosts two two2 two3 two4 three four -set hosts [join [bash_sort $hosts] "\\s+"] -# Setup environment -set cmd {OLDHOME=$HOME; HOME=$SRCDIRABS} -send "$cmd\r" -expect -ex "$cmd\r\n/@" -# Call _known_hosts -set cmd {unset COMPREPLY; _known_hosts_real -aF fixtures/_known_hosts_real/config_tilde ''; echo_array COMPREPLY} -send "$cmd\r" -expect -ex "$cmd\r\n" -expect { - -re "^$hosts\r\n/@$" { pass "$test" } - default { unresolved "$test" } -} -# Teardown environment -set cmd {HOME=$OLDHOME} -send "$cmd\r" -expect -ex "$cmd\r\n/@" -sync_after_int - -set test "Empty COMP_KNOWN_HOSTS_WITH_HOSTFILE should omit HOSTFILE" -assert_bash_exec "COMP_KNOWN_HOSTS_WITH_HOSTFILE=" -set hosts [get_hosts_avahi] -# Hosts `gee', `hus' and `jar' are defined in -# ./fixtures/_known_hosts_real/config -# 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 -# Call _known_hosts -set cmd {unset COMPREPLY; _known_hosts_real -aF fixtures/_known_hosts_real/config ''; echo_array COMPREPLY} -assert_bash_list $hosts $cmd $test -sort -sync_after_int -assert_bash_exec "unset -v COMP_KNOWN_HOSTS_WITH_HOSTFILE" -sync_after_int - -set test "Included config files should work" -set hosts [get_hosts -unsorted] -# Host 'recursion' is defined in -# ./fixtures/_known_hosts_real/config_include_recursion -# Host 'relative_path' is defined in -# ./fixtures/_known_hosts_real/.ssh/config_relative_path -lappend hosts recursion relative_path -set hosts [join [bash_sort $hosts] "\\s+"] -# Setup environment -# Redefined HOME to handle relative path inclusions on $HOME/.ssh -set cmd {OLDHOME=$HOME; HOME="$SRCDIRABS/fixtures/_known_hosts_real"} -send "$cmd\r" -expect -ex "$cmd\r\n/@" -# Call _known_hosts -set cmd {unset COMPREPLY; _known_hosts_real -aF fixtures/_known_hosts_real/config_include ''; echo_array COMPREPLY} -send "$cmd\r" -expect -ex "$cmd\r\n" -expect { - -re "^$hosts\r\n/@$" { pass "$test" } - default { unresolved "$test" } -} -# Teardown environment -set cmd {HOME=$OLDHOME} -send "$cmd\r" -expect -ex "$cmd\r\n/@" -sync_after_int - -set test "IPv6 filtering should work" -set hosts "127.0.0.1 localhost" -assert_bash_exec "COMP_KNOWN_HOSTS_WITH_HOSTFILE=" -set cmd {unset COMPREPLY; _known_hosts_real -4F fixtures/_known_hosts_real/localhost_config ''; echo_array COMPREPLY} -assert_bash_list $hosts $cmd $test -sort -sync_after_int -assert_bash_exec "unset -v COMP_KNOWN_HOSTS_WITH_HOSTFILE" -sync_after_int - -set test "IPv4 filtering should work" -set hosts "::1 localhost" -assert_bash_exec "COMP_KNOWN_HOSTS_WITH_HOSTFILE=" -set cmd {unset COMPREPLY; _known_hosts_real -6F fixtures/_known_hosts_real/localhost_config ''; echo_array COMPREPLY} -assert_bash_list $hosts $cmd $test -sort -sync_after_int -assert_bash_exec "unset -v COMP_KNOWN_HOSTS_WITH_HOSTFILE" -sync_after_int - -set test "IPv4+IPv6 filtering should work" -set hosts "localhost" -assert_bash_exec "COMP_KNOWN_HOSTS_WITH_HOSTFILE=" -set cmd {unset COMPREPLY; _known_hosts_real -46F fixtures/_known_hosts_real/localhost_config ''; echo_array COMPREPLY} -assert_bash_list $hosts $cmd $test -sort -sync_after_int -assert_bash_exec "unset -v COMP_KNOWN_HOSTS_WITH_HOSTFILE" -sync_after_int - - -teardown |