diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/__expand_tilde_by_ref.exp | 16 | ||||
-rw-r--r-- | test/unit/_count_args.exp | 14 | ||||
-rw-r--r-- | test/unit/_filedir.exp | 82 | ||||
-rw-r--r-- | test/unit/_get_comp_words_by_ref.exp | 47 | ||||
-rw-r--r-- | test/unit/_get_cword.exp | 58 | ||||
-rw-r--r-- | test/unit/_known_hosts_real.exp | 34 | ||||
-rw-r--r-- | test/unit/_parse_help.exp | 73 | ||||
-rw-r--r-- | test/unit/_tilde.exp | 51 | ||||
-rw-r--r-- | test/unit/compgen.exp | 19 |
9 files changed, 270 insertions, 124 deletions
diff --git a/test/unit/__expand_tilde_by_ref.exp b/test/unit/__expand_tilde_by_ref.exp index d4a75d11..abd549cb 100644 --- a/test/unit/__expand_tilde_by_ref.exp +++ b/test/unit/__expand_tilde_by_ref.exp @@ -8,14 +8,14 @@ proc setup {home user} { set _home [string trim $_home] assert_bash_exec {echo "$USER"} {} /@ _user set _user [string trim $_user] -}; # setup() +} proc teardown {} { assert_env_unmodified { /var=/d } -}; # teardown() +} setup home user @@ -37,7 +37,7 @@ sync_after_int set test "~user should return /home/user" -set cmd [format {var="~%s"; __expand_tilde_by_ref var; printf "%%s" "$var"} $user] +set cmd [format {var="~%s"; __expand_tilde_by_ref var; printf "%%s\n" "$var"} $user] assert_bash_list "$home" $cmd $test @@ -45,7 +45,7 @@ sync_after_int set test "~/foo should return /home/user/foo" -set cmd {var='~/foo'; __expand_tilde_by_ref var; printf "%s" "$var"} +set cmd {var='~/foo'; __expand_tilde_by_ref var; printf "%s\n" "$var"} assert_bash_list "$home/foo" $cmd $test @@ -53,7 +53,7 @@ sync_after_int set test "~user/bar should return /home/user/bar" -set cmd [format {var="~%s/bar"; __expand_tilde_by_ref var; printf "%%s" "$var"} $user] +set cmd [format {var="~%s/bar"; __expand_tilde_by_ref var; printf "%%s\n" "$var"} $user] assert_bash_list "$home/bar" $cmd $test @@ -61,7 +61,7 @@ sync_after_int set test "~user/\$HOME should return /home/user/\$HOME" -set cmd [format {var="~%s/\$HOME"; __expand_tilde_by_ref var; printf "%%s" "$var"} $user] +set cmd [format {var="~%s/\$HOME"; __expand_tilde_by_ref var; printf "%%s\n" "$var"} $user] assert_bash_list "$home/\$HOME" $cmd $test @@ -69,7 +69,7 @@ sync_after_int set test "'~user/a b' should return '/home/user/a b'" -set cmd [format {var="~%s/a b"; __expand_tilde_by_ref var; printf "%%s" "$var"} $user] +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 @@ -77,7 +77,7 @@ sync_after_int set test "~user/* should return /home/user/*" -set cmd [format {var="~%s/*"; __expand_tilde_by_ref var; printf "%%s" "$var"} $user] +set cmd [format {var="~%s/*"; __expand_tilde_by_ref var; printf "%%s\n" "$var"} $user] assert_bash_list "$home/\*" $cmd $test diff --git a/test/unit/_count_args.exp b/test/unit/_count_args.exp index da61bdb6..b615cab8 100644 --- a/test/unit/_count_args.exp +++ b/test/unit/_count_args.exp @@ -1,7 +1,7 @@ proc setup {} { assert_bash_exec {unset COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS} save_env -}; # setup() +} proc teardown {} { @@ -12,7 +12,7 @@ proc teardown {} { d } } -}; # teardown() +} setup @@ -26,7 +26,7 @@ sync_after_int set test "a b| should set args to 1"; # | = cursor position -set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=3; _count_args; echo -n $args} +set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=3; _count_args; echo $args} assert_bash_list 1 $cmd $test @@ -34,7 +34,7 @@ sync_after_int set test "a b|c should set args to 1"; # | = cursor position -set cmd {COMP_WORDS=(a bc); COMP_CWORD=1; COMP_LINE='a bc'; COMP_POINT=3; _count_args; echo -n $args} +set cmd {COMP_WORDS=(a bc); COMP_CWORD=1; COMP_LINE='a bc'; COMP_POINT=3; _count_args; echo $args} assert_bash_list 1 $cmd $test @@ -42,7 +42,7 @@ sync_after_int set test "a b c| should set args to 2"; # | = cursor position -set cmd {COMP_WORDS=(a b c); COMP_CWORD=2; COMP_LINE='a b c'; COMP_POINT=4; _count_args; echo -n $args} +set cmd {COMP_WORDS=(a b c); COMP_CWORD=2; COMP_LINE='a b c'; COMP_POINT=4; _count_args; echo $args} assert_bash_list 2 $cmd $test @@ -50,7 +50,7 @@ sync_after_int set test "a b| c should set args to 1"; # | = cursor position -set cmd {COMP_WORDS=(a b c); COMP_CWORD=1; COMP_LINE='a b c'; COMP_POINT=3; _count_args; echo -n $args} +set cmd {COMP_WORDS=(a b c); COMP_CWORD=1; COMP_LINE='a b c'; COMP_POINT=3; _count_args; echo $args} assert_bash_list 1 $cmd $test @@ -58,7 +58,7 @@ sync_after_int set test "a b -c| d should set args to 2"; # | = cursor position -set cmd {COMP_WORDS=(a b -c d); COMP_CWORD=2; COMP_LINE='a b -c d'; COMP_POINT=6; _count_args; echo -n $args} +set cmd {COMP_WORDS=(a b -c d); COMP_CWORD=2; COMP_LINE='a b -c d'; COMP_POINT=6; _count_args; echo $args} assert_bash_list 2 $cmd $test diff --git a/test/unit/_filedir.exp b/test/unit/_filedir.exp index 204d31cf..de494084 100644 --- a/test/unit/_filedir.exp +++ b/test/unit/_filedir.exp @@ -20,17 +20,17 @@ proc setup {} { # directories containing `*' or `\' aren't allowed on Cygwin/Windows if {! [is_cygwin]} { # Create directory `a*b' - assert_bash_exec {(cd fixtures/_filedir && [ ! -d a\*b ] && mkdir a\*b && touch a\*b/j || true)} + 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 fixtures/_filedir && [ ! -d a\\b ] && mkdir a\\b && touch a\\b/g || true)} + 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 fixtures/_filedir && rm -- a\\b/g && rmdir a\\b/ || true)} - assert_bash_exec {(cd fixtures/_filedir && rm -- a\*b/j && 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 _g} @@ -56,7 +56,7 @@ foreach name {f f2} { set test "completing $name ab/ should return e" set cmd "$name ab/" - assert_complete_dir e $cmd "fixtures/_filedir" $test + assert_complete_dir e $cmd "$::srcdir/fixtures/_filedir" $test sync_after_int @@ -64,7 +64,7 @@ foreach name {f f2} { set test "completing $name a\\ b/ should return i" set cmd "$name a\\ b/" - assert_complete_dir i $cmd "fixtures/_filedir" $test + assert_complete_dir i $cmd "$::srcdir/fixtures/_filedir" $test sync_after_int @@ -72,7 +72,7 @@ foreach name {f f2} { set test "completing $name a\\\'b/ should return c" set cmd "$name a\\\'b/" - assert_complete_dir c $cmd "fixtures/_filedir" $test + assert_complete_dir c $cmd "$::srcdir/fixtures/_filedir" $test sync_after_int @@ -80,7 +80,7 @@ foreach name {f f2} { set test "completing $name a\\\"b/ should return d"; #" set cmd "$name a\\\"b/"; #" - assert_complete_dir d $cmd "fixtures/_filedir" $test + assert_complete_dir d $cmd "$::srcdir/fixtures/_filedir" $test sync_after_int @@ -88,8 +88,8 @@ foreach name {f f2} { set test "completing $name a\\\$b/ should return h" set cmd "$name a\\\$b/" - assert_complete_dir "\b\b\b\b\b$::TESTDIR/fixtures/_filedir/a\\\\\$b/h" \ - $cmd "fixtures/_filedir" $test + assert_complete_dir "\b\b\b\b\b$::srcdirabs/fixtures/_filedir/a\\\\\$b/h" \ + $cmd "$::srcdir/fixtures/_filedir" $test sync_after_int @@ -101,7 +101,7 @@ foreach name {f f2} { if {! [is_cygwin]} { set test "completing $name a\\\\b/ should return g" set cmd "$name a\\\\b/" - assert_complete_dir g $cmd "fixtures/_filedir" $test + assert_complete_dir g $cmd "$TESTDIR/tmp" $test sync_after_int @@ -110,7 +110,7 @@ foreach name {f f2} { set test "completing $name a\\&b/ should return f" set cmd "$name a\\&b/" - assert_complete_dir f $cmd "fixtures/_filedir" $test + assert_complete_dir f $cmd "$::srcdir/fixtures/_filedir" $test sync_after_int @@ -118,7 +118,7 @@ foreach name {f f2} { set test "completing $name a\$ should return a\\\$b/" set cmd "$name a\$" - assert_complete_dir "\b\\\\\$b/" $cmd "fixtures/_filedir" $test + assert_complete_dir "\b\\\\\$b/" $cmd "$::srcdir/fixtures/_filedir" $test -nospace sync_after_int @@ -132,21 +132,21 @@ foreach name {f f2} { [lindex $::BASH_VERSINFO 2] < 35 )} { set cmd "$name 'ab/" - assert_complete_dir {e'} $cmd "fixtures/_filedir" + assert_complete_dir {e'} $cmd "$::srcdir/fixtures/_filedir" sync_after_int set cmd "$name 'a b/" - assert_complete_dir {i'} $cmd "fixtures/_filedir" + assert_complete_dir {i'} $cmd "$::srcdir/fixtures/_filedir" sync_after_int set cmd "$name 'a\"b/"; #" - assert_complete_dir {d'} $cmd "fixtures/_filedir" + assert_complete_dir {d'} $cmd "$::srcdir/fixtures/_filedir" sync_after_int @@ -154,9 +154,9 @@ foreach name {f f2} { set cmd "$name 'a\$b/" if {[lindex $::BASH_VERSINFO 0] == 4} { - assert_complete_dir {h'} $cmd "fixtures/_filedir" + assert_complete_dir {h'} $cmd "$::srcdir/fixtures/_filedir" } else { - assert_complete_dir "\b\b\b\b$::TESTDIR/fixtures/_filedir/a\$b/h'" $cmd "fixtures/_filedir" + assert_complete_dir "\b\b\b\b$::srcdirabs/fixtures/_filedir/a\$b/h'" $cmd "$::srcdir/fixtures/_filedir" } @@ -166,8 +166,8 @@ foreach name {f f2} { # Execute these tests only when not running on Cygwin/Windows, because # directories containing `*' or `\' aren't allowed on Cygwin/Windows if {! [is_cygwin]} { - set cmd "$name 'a\\b/" - assert_complete_dir {g'} $cmd "fixtures/_filedir" + set cmd "$name '$TESTDIR/tmp/a\\b/" + assert_complete_dir {g'} $cmd "$TESTDIR/tmp" sync_after_int @@ -175,63 +175,63 @@ foreach name {f f2} { set cmd "$name 'a&b/" - assert_complete_dir {f'} $cmd "fixtures/_filedir" + assert_complete_dir {f'} $cmd "$::srcdir/fixtures/_filedir" sync_after_int set cmd "$name \"ab/"; #" - assert_complete_dir {e"} $cmd "fixtures/_filedir"; #" + assert_complete_dir {e"} $cmd "$::srcdir/fixtures/_filedir"; #" sync_after_int set cmd "$name \"a b/"; #" - assert_complete_dir {i"} $cmd "fixtures/_filedir"; #" + assert_complete_dir {i"} $cmd "$::srcdir/fixtures/_filedir"; #" sync_after_int set cmd "$name \"a'b/"; #" - assert_complete_dir {c"} $cmd "fixtures/_filedir"; #" + assert_complete_dir {c"} $cmd "$::srcdir/fixtures/_filedir"; #" sync_after_int set cmd "$name \"a\\\"b/"; #" - assert_complete_dir {d"} $cmd "fixtures/_filedir"; #" + assert_complete_dir {d"} $cmd "$::srcdir/fixtures/_filedir"; #" sync_after_int set cmd "$name \"a\\\$b/"; #" - assert_complete_dir "\b\b\b\b\b$::TESTDIR/fixtures/_filedir/a\\\\\$b/h\\\"" $cmd "fixtures/_filedir" + assert_complete_dir "\b\b\b\b\b$::srcdirabs/fixtures/_filedir/a\\\\\$b/h\\\"" $cmd "$::srcdir/fixtures/_filedir" sync_after_int set cmd "$name \"a\\b/"; #" - assert_complete_dir "\b\b\bb/e\\\"" $cmd "fixtures/_filedir" + assert_complete_dir "\b\b\bb/e\\\"" $cmd "$::srcdir/fixtures/_filedir" sync_after_int set cmd "$name \"a\\\\b/"; #" - assert_complete_dir {g"} $cmd "fixtures/_filedir"; #" + assert_complete_dir {g"} $cmd "$TESTDIR/tmp"; #" sync_after_int set cmd "$name \"a&b/"; #" - assert_complete_dir {f"} $cmd "fixtures/_filedir"; #" + assert_complete_dir {f"} $cmd "$::srcdir/fixtures/_filedir"; #" sync_after_int @@ -242,23 +242,27 @@ foreach name {f f2} { set test "completing with filter '.e1' should show completions" -assert_complete_dir {ee.e1 foo/ gg.e1} "g " "fixtures/_filedir/ext" $test +assert_complete_dir {ee.e1 foo/ gg.e1 ii.E1} "g " "$::srcdir/fixtures/_filedir/ext" $test sync_after_int -set test "completing f aé should return g when LC_CTYPE=C" -# Backup/set LC_CTYPE -assert_bash_exec {OLD_CTYPE=$LC_CTYPE; LC_CTYPE=C} -if {[lindex $::BASH_VERSINFO 0] > 3} { - assert_complete_dir g "f aé/" "fixtures/_filedir" +set test "completing f aé should return g" +# Execute this test only on bash >= 4 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 { + [lindex $::BASH_VERSINFO 0] >= 4 && + [string first "UTF-8" $::LC_CTYPE] != -1 && + [string first 5.44 [exp_version]] != 0 +} { + assert_complete_dir g "f aé/" "$::srcdir/fixtures/_filedir" } else { - assert_complete_dir "\b\b\b\b$'a\\\\303\\\\251/g'" "f aé/" \ - "fixtures/_filedir" + unsupported "$test" } -# Restore LC_CTYPE -assert_bash_exec {[[ $OLD_CTYPE ]] && LC_CTYPE=$OLD_CTYPE || unset LC_CTYPE} sync_after_int diff --git a/test/unit/_get_comp_words_by_ref.exp b/test/unit/_get_comp_words_by_ref.exp index 22561e7f..2ddcef23 100644 --- a/test/unit/_get_comp_words_by_ref.exp +++ b/test/unit/_get_comp_words_by_ref.exp @@ -1,7 +1,7 @@ proc setup {} { assert_bash_exec {unset COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS} save_env -}; # setup() +} proc teardown {} { @@ -15,7 +15,7 @@ proc teardown {} { d } } -}; # teardown() +} setup @@ -105,7 +105,7 @@ if { set cmd {COMP_WORDS=(a "'" b c); COMP_CWORD=3} } else { set cmd {COMP_WORDS=(a "'b c"); COMP_CWORD=1} -}; # if +} append cmd {; COMP_LINE="a 'b c"; COMP_POINT=6; _get_comp_words_by_ref cur prev; echo "$cur $prev"} send "$cmd\r" expect -ex "$cmd\r\n" @@ -118,7 +118,7 @@ expect { [lindex $::BASH_VERSINFO 2] < 35 } {xfail "$test"} {fail "$test"} } -}; # expect +} sync_after_int @@ -133,7 +133,7 @@ if { set cmd {COMP_WORDS=(a "\"" b c); COMP_CWORD=3} } else { set cmd {COMP_WORDS=(a "\"b c"); COMP_CWORD=1} -}; # if +} append cmd {; COMP_LINE="a \"b c"; COMP_POINT=6} assert_bash_exec $cmd set cmd {_get_comp_words_by_ref cur prev; echo "$cur $prev"}; @@ -148,7 +148,7 @@ expect { [lindex $::BASH_VERSINFO 2] < 35 } {xfail "$test"} {fail "$test"} } -}; # expect +} sync_after_int @@ -161,7 +161,7 @@ if {[lindex $::BASH_VERSINFO 0] <= 3} { } else { set cmd {add_comp_wordbreak_char :; COMP_WORDS=(a b : c); COMP_CWORD=3} set expected {"c :"} -}; # if +} append cmd {; COMP_LINE='a b:c'; COMP_POINT=5} # NOTE: Split-send cmd to prevent backspaces (\008) in output assert_bash_exec $cmd $test @@ -177,7 +177,7 @@ if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a "b:c"); COMP_CWORD=1} } else { set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3} -}; # if +} append cmd {; COMP_LINE='a b:c'; COMP_POINT=5} assert_bash_exec $cmd $test set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"} @@ -192,7 +192,7 @@ if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a b c:); COMP_CWORD=2} } else { set cmd {COMP_WORDS=(a b c :); COMP_CWORD=3} -}; # if +} append cmd {; COMP_LINE='a b c:'; COMP_POINT=6} assert_bash_exec $cmd $test set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"} @@ -202,6 +202,21 @@ assert_bash_list {"c: b"} $cmd $test sync_after_int +set test {a b:c | with WORDBREAKS -= :}; # | = cursor position +if {[lindex $::BASH_VERSINFO 0] <= 3} { + set cmd {COMP_WORDS=(a b:c ''); COMP_CWORD=2} +} else { + set cmd {COMP_WORDS=(a b : c ''); COMP_CWORD=4} +} +append cmd {; COMP_LINE='a b:c '; COMP_POINT=6} +assert_bash_exec $cmd $test +set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"} +assert_bash_list {" b:c"} $cmd $test + + +sync_after_int + + set test {a :| with WORDBREAKS -= : should return :}; # | = cursor position set cmd {COMP_WORDS=(a :); COMP_CWORD=1; COMP_LINE='a :'; COMP_POINT=3} assert_bash_exec $cmd @@ -217,7 +232,7 @@ if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a "b::"); COMP_CWORD=1} } else { set cmd {COMP_WORDS=(a b ::); COMP_CWORD=2} -}; # if +} append cmd {; COMP_LINE='a b::'; COMP_POINT=5} assert_bash_exec $cmd set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"} @@ -232,7 +247,7 @@ sync_after_int set test "a -n| should return -n"; # | = cursor position set cmd {COMP_WORDS=(a -n); COMP_CWORD=1; COMP_LINE='a -n'; COMP_POINT=4} assert_bash_exec $cmd -set cmd {_get_comp_words_by_ref cur; printf %s $cur} +set cmd {_get_comp_words_by_ref cur; printf "%s\n" $cur} assert_bash_list -n $cmd $test @@ -256,7 +271,7 @@ if {[lindex $::BASH_VERSINFO] <= 3} { } else { set cmd {COMP_WORDS=(a b = c); COMP_CWORD=3} set expected c -}; # if +} append cmd {; COMP_LINE='a b=c'; COMP_POINT=5} assert_bash_exec $cmd set cmd {_get_comp_words_by_ref cur prev; echo "$cur"} @@ -286,7 +301,7 @@ expect { -ex "\$(b c/@" { pass "$test" } # Expected failure on bash-4 -ex "c/@" { xfail "$test" } -}; # expect +} sync_after_int @@ -303,7 +318,7 @@ expect { -ex "\$(b c\\ d/@" { pass "$test" } # Expected failure on bash-4 -ex "c\\ d/@" { xfail "$test" } -}; # expect +} sync_after_int @@ -318,7 +333,7 @@ if { set cmd {COMP_WORDS=(a "'" b "&" c); COMP_CWORD=4} } else { set cmd {COMP_WORDS=(a "'b&c"); COMP_CWORD=1} -}; # if +} append cmd {; COMP_LINE="a 'b&c"; COMP_POINT=6} assert_bash_exec $cmd set cmd {_get_comp_words_by_ref cur prev; printf %s "$cur"} @@ -333,7 +348,7 @@ expect { [lindex $::BASH_VERSINFO 2] < 35 } {xfail "$test"} {fail "$test"} } -}; # expect +} sync_after_int diff --git a/test/unit/_get_cword.exp b/test/unit/_get_cword.exp index 1e6e9bfb..ce749cec 100644 --- a/test/unit/_get_cword.exp +++ b/test/unit/_get_cword.exp @@ -1,7 +1,7 @@ proc setup {} { assert_bash_exec {unset COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS} save_env -}; # setup() +} proc teardown {} { @@ -12,7 +12,7 @@ proc teardown {} { d } } -}; # teardown() +} setup @@ -30,7 +30,7 @@ sync_after_int set test "a b| should return b"; # | = cursor position -set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=3; _get_cword} +set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=3; _get_cword; echo} assert_bash_list b $cmd $test @@ -65,7 +65,7 @@ sync_after_int set test "a b|c should return b"; # | = cursor position -set cmd {COMP_WORDS=(a bc); COMP_CWORD=1; COMP_LINE='a bc'; COMP_POINT=3; _get_cword} +set cmd {COMP_WORDS=(a bc); COMP_CWORD=1; COMP_LINE='a bc'; COMP_POINT=3; _get_cword; echo} assert_bash_list b $cmd $test @@ -73,7 +73,7 @@ sync_after_int set test {a b\ c| should return b\ c}; # | = cursor position -set cmd {COMP_WORDS=(a 'b\ c'); COMP_CWORD=1; COMP_LINE='a b\ c'; COMP_POINT=6; _get_cword} +set cmd {COMP_WORDS=(a 'b\ c'); COMP_CWORD=1; COMP_LINE='a b\ c'; COMP_POINT=6; _get_cword; echo} assert_bash_list {"b\\ c"} $cmd $test @@ -81,7 +81,7 @@ sync_after_int set test {a b\| c should return b\ }; # | = cursor position -set cmd {COMP_WORDS=(a 'b\ c'); COMP_CWORD=1; COMP_LINE='a b\ c'; COMP_POINT=4; _get_cword} +set cmd {COMP_WORDS=(a 'b\ c'); COMP_CWORD=1; COMP_LINE='a b\ c'; COMP_POINT=4; _get_cword; echo} assert_bash_list {"b\\"} $cmd $test @@ -89,7 +89,7 @@ sync_after_int set test {a "b\| should return "b\ }; # | = cursor position -set cmd {COMP_WORDS=(a '"b\'); COMP_CWORD=1; COMP_LINE='a "b\'; COMP_POINT=5; _get_cword} +set cmd {COMP_WORDS=(a '"b\'); COMP_CWORD=1; COMP_LINE='a "b\'; COMP_POINT=5; _get_cword; echo} assert_bash_list {"\"b\\"} $cmd $test @@ -105,7 +105,7 @@ if { set cmd {COMP_WORDS=(a "'" b c); COMP_CWORD=3} } else { set cmd {COMP_WORDS=(a "'b c"); COMP_CWORD=1} -}; # if +} append cmd {; COMP_LINE="a 'b c"; COMP_POINT=6; _get_cword} send "$cmd\r" expect -ex "$cmd\r\n" @@ -118,7 +118,7 @@ expect { [lindex $::BASH_VERSINFO 2] < 35 } {xfail "$test"} {fail "$test"} } -}; # expect +} sync_after_int @@ -133,7 +133,7 @@ if { set cmd {COMP_WORDS=(a "\"" b c); COMP_CWORD=3} } else { set cmd {COMP_WORDS=(a "\"b c"); COMP_CWORD=1} -}; # if +} append cmd {; COMP_LINE="a \"b c"; COMP_POINT=6; _get_cword}; send "$cmd\r" expect -ex "$cmd\r\n" @@ -146,7 +146,7 @@ expect { [lindex $::BASH_VERSINFO 2] < 35 } {xfail "$test"} {fail "$test"} } -}; # expect +} sync_after_int @@ -159,8 +159,8 @@ if {[lindex $::BASH_VERSINFO 0] <= 3} { } else { set cmd {add_comp_wordbreak_char :; COMP_WORDS=(a b : c); COMP_CWORD=3} set expected c -}; # if -append cmd {; COMP_LINE='a b:c'; COMP_POINT=5; _get_cword} +} +append cmd {; COMP_LINE='a b:c'; COMP_POINT=5; _get_cword; echo} assert_bash_list $expected $cmd $test @@ -172,8 +172,8 @@ if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a "b:c"); COMP_CWORD=1} } else { set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3} -}; # if -append cmd {; COMP_LINE='a b:c'; COMP_POINT=5; _get_cword :} +} +append cmd {; COMP_LINE='a b:c'; COMP_POINT=5; _get_cword :; echo} assert_bash_list b:c $cmd $test @@ -185,8 +185,8 @@ if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a b c:); COMP_CWORD=2} } else { set cmd {COMP_WORDS=(a b c :); COMP_CWORD=3} -}; # if -append cmd {; COMP_LINE='a b c:'; COMP_POINT=6; _get_cword :} +} +append cmd {; COMP_LINE='a b c:'; COMP_POINT=6; _get_cword :; echo} assert_bash_list c: $cmd $test @@ -194,7 +194,7 @@ sync_after_int set test {a :| with WORDBREAKS -= : should return :}; # | = cursor position -set cmd {COMP_WORDS=(a :); COMP_CWORD=1; COMP_LINE='a :'; COMP_POINT=3; _get_cword :} +set cmd {COMP_WORDS=(a :); COMP_CWORD=1; COMP_LINE='a :'; COMP_POINT=3; _get_cword :; echo} assert_bash_list : $cmd $test @@ -206,8 +206,8 @@ if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a "b::"); COMP_CWORD=1} } else { set cmd {COMP_WORDS=(a b ::); COMP_CWORD=2} -}; # if -append cmd {; COMP_LINE='a b::'; COMP_POINT=5; _get_cword :} +} +append cmd {; COMP_LINE='a b::'; COMP_POINT=5; _get_cword :; echo} assert_bash_list b:: $cmd $test @@ -217,7 +217,7 @@ sync_after_int # This test makes sure `_get_cword' doesn't use `echo' to return it's value, # because -n might be interpreted by `echo' and thus will not be returned. set test "a -n| should return -n"; # | = cursor position -set cmd {COMP_WORDS=(a -n); COMP_CWORD=1; COMP_LINE='a -n'; COMP_POINT=4; _get_cword} +set cmd {COMP_WORDS=(a -n); COMP_CWORD=1; COMP_LINE='a -n'; COMP_POINT=4; _get_cword; echo} assert_bash_list -n $cmd $test @@ -225,7 +225,7 @@ sync_after_int set test {a b>c| should return c}; # | = cursor position -set cmd {COMP_WORDS=(a b \> c); COMP_CWORD=3; COMP_LINE='a b>c'; COMP_POINT=5; _get_cword} +set cmd {COMP_WORDS=(a b \> c); COMP_CWORD=3; COMP_LINE='a b>c'; COMP_POINT=5; _get_cword; echo} assert_bash_list c $cmd $test @@ -239,8 +239,8 @@ if {[lindex $::BASH_VERSINFO] <= 3} { } else { set cmd {COMP_WORDS=(a b = c); COMP_CWORD=3} set expected c -}; # if -append cmd {; COMP_LINE='a b=c'; COMP_POINT=5; _get_cword} +} +append cmd {; COMP_LINE='a b=c'; COMP_POINT=5; _get_cword; echo} assert_bash_list $expected $cmd $test @@ -248,7 +248,7 @@ sync_after_int set test {a *| should return *}; # | = cursor position -set cmd {COMP_WORDS=(a \*); COMP_CWORD=1; COMP_LINE='a *'; COMP_POINT=4; _get_cword} +set cmd {COMP_WORDS=(a \*); COMP_CWORD=1; COMP_LINE='a *'; COMP_POINT=4; _get_cword; echo} assert_bash_list * $cmd $test @@ -264,7 +264,7 @@ expect { -ex "\$(b c/@" { pass "$test" } # Expected failure on bash-4 -ex "c/@" { xfail "$test" } -}; # expect +} sync_after_int @@ -279,7 +279,7 @@ expect { -ex "\$(b c\\ d/@" { pass "$test" } # Expected failure on bash-4 -ex "c\\ d/@" { xfail "$test" } -}; # expect +} sync_after_int @@ -294,7 +294,7 @@ if { set cmd {COMP_WORDS=(a "'" b "&" c); COMP_CWORD=4} } else { set cmd {COMP_WORDS=(a "'b&c"); COMP_CWORD=1} -}; # if +} append cmd {; COMP_LINE="a 'b&c"; COMP_POINT=6; _get_cword} send "$cmd\r" expect -ex "$cmd\r\n" @@ -307,7 +307,7 @@ expect { [lindex $::BASH_VERSINFO 2] < 35 } {xfail "$test"} {fail "$test"} } -}; # expect +} sync_after_int diff --git a/test/unit/_known_hosts_real.exp b/test/unit/_known_hosts_real.exp index 152cf885..604b2d5e 100644 --- a/test/unit/_known_hosts_real.exp +++ b/test/unit/_known_hosts_real.exp @@ -1,6 +1,9 @@ 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 -}; # setup() +} proc teardown {} { @@ -8,7 +11,8 @@ proc teardown {} { /COMPREPLY=/d /OLDHOME=/d } -}; # teardown() + assert_bash_exec {cd $TESTDIR} +} setup @@ -17,10 +21,10 @@ setup set test "Hosts should be put in COMPREPLY" set hosts [get_hosts] # Hosts `gee', `hus' and `jar' are defined in ./fixtures/_known_hosts_real/config - # doo, ike, jub, 10.0.0.1, kyl and 100.0.0.2 in ./fixtures/_known_hosts_real/known_hosts -lappend hosts doo gee hus ike jar jub kyl 10.0.0.1 100.0.0.2 + # 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 +assert_bash_list $hosts $cmd $test -sort sync_after_int @@ -29,16 +33,16 @@ sync_after_int set test "Hosts should have username prefix and colon suffix" set hosts [get_hosts] # Hosts `gee', `hus' and `jar' are defined in ./fixtures/_known_hosts_real/config - # doo, ike jub, 10.0.0.1, kyl and 100.0.0.2 in ./fixtures/_known_hosts_real/known_hosts -lappend hosts doo gee hus ike jar jub kyl 10.0.0.1 100.0.0.2 + # 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:" -}; # foreach +} # 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 +assert_bash_list $expected $cmd $test -sort sync_after_int @@ -66,7 +70,7 @@ expect { -re "^$hosts_config\r\n/@$" { fail "$test (known hosts file)" } -re /@ { unresolved "$test at prompt" } default { unresolved "$test" } -}; # expect +} sync_after_int @@ -79,7 +83,7 @@ set hosts [get_hosts] lappend hosts two three set hosts [join [bash_sort $hosts] "\\s+"] # Setup environment -set cmd {OLDHOME=$HOME; HOME=$TESTDIR} +set cmd {OLDHOME=$HOME; HOME=$SRCDIRABS} send "$cmd\r" expect -ex "$cmd\r\n/@" # Call _known_hosts @@ -89,7 +93,7 @@ expect -ex "$cmd\r\n" expect { -re "^$hosts\r\n/@$" { pass "$test" } default { unresolved "$test" } -}; # expect +} # Teardown environment set cmd {HOME=$OLDHOME} send "$cmd\r" @@ -103,11 +107,11 @@ 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 and 100.0.0.2 in ./fixtures/_known_hosts_real/known_hosts -lappend hosts doo gee hus ike jar jub kyl 10.0.0.1 100.0.0.2 + # 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 +assert_bash_list $hosts $cmd $test -sort sync_after_int assert_bash_exec "unset -v COMP_KNOWN_HOSTS_WITH_HOSTFILE" diff --git a/test/unit/_parse_help.exp b/test/unit/_parse_help.exp new file mode 100644 index 00000000..4beb28d2 --- /dev/null +++ b/test/unit/_parse_help.exp @@ -0,0 +1,73 @@ +# By Stephen Gildea, October 2010. + +proc setup {} { + save_env +} + +proc teardown {} { + assert_env_unmodified { + /declare -f fn/d + } +} + +setup + + +set cmd {fn() { printf '%s\n' ""; }; _parse_help fn} +assert_bash_list "" $cmd "empty" +sync_after_int + +set cmd {fn() { printf '%s\n' "no dashes here"; }; _parse_help fn} +assert_bash_list "" $cmd "no dashes" +sync_after_int + +set cmd {fn() { printf '%s\n' "internal-dash"; }; _parse_help fn} +assert_bash_list "" $cmd "internal dash 1" +sync_after_int + +set cmd {fn() { printf '%s\n' "no -leading-dashes"; }; _parse_help fn} +assert_bash_list "" $cmd "no leading dash" +sync_after_int + +set cmd {fn() { printf '%s\n' "-one dash"; }; _parse_help fn} +assert_bash_list "-one" $cmd "one dash" +sync_after_int + +set cmd {fn() { printf '%s\n' " -space dash"; }; _parse_help fn} +assert_bash_list "-space" $cmd "one dash after space" +sync_after_int + +set cmd {fn() { printf '%s\n' "-one -two dashes"; }; _parse_help fn} +assert_bash_list "-one\n-two" $cmd "two dashes, space-separated" +sync_after_int + +set cmd {fn() { printf '%s\n' "-one,-t dashes"; }; _parse_help fn} +assert_bash_list "-one\n-t" $cmd "two dashes, comma-separated" +sync_after_int + +set cmd {fn() { printf '%s\n' "-one dash-inside"; }; _parse_help fn} +assert_bash_list "-one" $cmd "internal dash 2" +sync_after_int + +set cmd {fn() { printf '%s\n' "--long-arg=value"; }; _parse_help fn} +assert_bash_list "--long-arg" $cmd "value stripped" +sync_after_int + +set cmd {fn() { printf '%s\n' "--long-arg=-value"; }; _parse_help fn} +assert_bash_list "--long-arg" $cmd "value not seen as option" +sync_after_int + +set cmd {fn() { printf '%s\n' "--long-arg=-value,--opt2=val"; }; _parse_help fn} +assert_bash_list "--long-arg\n--opt2" $cmd "two options with values" +sync_after_int + +set cmd {fn() { printf '%s\n' "-m,--mirror"; }; _parse_help fn} +assert_bash_list "-m\n--mirror" $cmd "short + long" +sync_after_int + +set cmd {fn() { printf '%s\n' "-T/--upload-file"; }; _parse_help fn} +assert_bash_list "-T\n--upload-file" $cmd "short + long, slash separated" +sync_after_int + + +teardown diff --git a/test/unit/_tilde.exp b/test/unit/_tilde.exp new file mode 100644 index 00000000..2e22b848 --- /dev/null +++ b/test/unit/_tilde.exp @@ -0,0 +1,51 @@ +# @param string $part Reference to variable to hold partial unique username +# @param string $full Reference to variable to hold full unique username +proc setup {part full} { + upvar $part _part + upvar $full _full + + assert_bash_exec {compgen -u} {} /@ users + find_unique_completion_pair $users _part _full + save_env +} + + +proc teardown {} { + assert_env_unmodified { + /COMPREPLY=/d + } +} + + +setup part full + + +set test "function should run without errors" +assert_bash_exec {_tilde > /dev/null} $test + + +sync_after_int + + +set test "function should not pollute environment" +# NOTE: A possible environment pollution is detected by assert_env_modified() in teardown() +assert_bash_exec {foo() { local aa="~"; _tilde "$aa"; }; foo; unset foo} $test + + +sync_after_int + + +set test "~full should complete to ~full unmodified" +set cmd [format {_tilde "~%s"; printf "%%s\n" "${COMPREPLY[@]}"} $full] +assert_bash_list "~$full" $cmd $test + + +sync_after_int + + +set test "~part should complete to ~full" +set cmd [format {_tilde "~%s"; printf "%%s\n" "${COMPREPLY[@]}"} $part] +assert_bash_list "~$full" $cmd $test + + +teardown diff --git a/test/unit/compgen.exp b/test/unit/compgen.exp index 6673bf0e..6e6f79c6 100644 --- a/test/unit/compgen.exp +++ b/test/unit/compgen.exp @@ -1,11 +1,11 @@ proc setup {} { save_env -}; # setup() +} proc teardown {} { assert_env_unmodified {/OLDPWD/d} -}; # teardown() +} setup @@ -17,10 +17,9 @@ if {[lindex $::BASH_VERSINFO 0] <= 3} { } else { set test {compgen -f a\\\'b/ on bash-4 should return a\'b/c}; set cmd {compgen -f a\\\'b/} -}; # if -set dir fixtures/compgen -set prompt "/$dir/@" -assert_bash_exec "cd $dir" "" $prompt +} +set dir $::srcdir/fixtures/compgen +assert_bash_exec "cd $dir" send "$cmd\r" expect -ex "$cmd\r\n" expect { @@ -37,13 +36,13 @@ expect { if {[lindex $::BASH_VERSINFO 0] <= 3 } \ {pass $test} else {fail $test} } - -re $prompt { pass "$test" } + -re /@ { pass "$test" } -re eof { unresolved "eof" } -}; # expect -sync_after_int $prompt +} +sync_after_int assert_bash_exec {cd "$TESTDIR"} -#assert_bash_list_dir {a\\\'b/c} $cmd fixtures/compgen +#assert_bash_list_dir {a\\\'b/c} $cmd $::srcdir/fixtures/compgen sync_after_int |