Skip to content

Commit

Permalink
test: Add assert_complete_homedir, use in dpkg and ls
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Mar 16, 2018
1 parent 6927248 commit ec85ac4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
11 changes: 1 addition & 10 deletions test/lib/completions/dpkg.exp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@ if {[assert_exec {dpkg --get-selections | command grep \[\[:space:\]\]install$ |
sync_after_int


set test "dpkg -i ~part should complete to ~full/ if home dir exists"
# https://bugs.debian.org/864691
# Create list of users, having existing home dir
assert_bash_exec {for u in $(compgen -u); do \
eval test -d ~$u && echo $u; unset u; done} {} /@ users
if {![find_unique_completion_pair $users part full]} {
untested "Not running, no suitable test user found: $test"
} else {
assert_complete "~$full/" "dpkg -i ~$part" $test -nospace
}
assert_complete_homedir "dpkg -i"
sync_after_int


Expand Down
10 changes: 1 addition & 9 deletions test/lib/completions/ls.exp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@ if {[assert_exec {ls --help} "" "" "unsupported"]} {
sync_after_int


set test "~part should complete to ~full/ if home dir exists"
# Create list of users, having existing home dir
assert_bash_exec {for u in $(compgen -u); do \
eval test -d ~$u && echo $u; unset u; done} {} /@ users
if {![find_unique_completion_pair $users part full]} {
untested "Not running, no suitable test user found: $test"
} else {
assert_complete "~$full/" "ls ~$part" $test -nospace
}
assert_complete_homedir "ls"
sync_after_int


Expand Down
18 changes: 18 additions & 0 deletions test/lib/library.exp
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,24 @@ proc assert_no_output {{cmd} {test ""} {prompt /@}} {
}


# Check that ~part completes to ~full/ if home dir exists.
# @param string $cmd The command to attempt home dir completion for.
# @param string $test Optional parameter with test name.
# @param string $prompt (optional) Bash prompt. Default is "/@"
proc assert_complete_homedir {{cmd} {test ""} {prompt /@}} {
if {[string length $test] == 0} {
set test "$cmd should complete ~part to ~full/ if home dir exists"
}
assert_bash_exec {for u in $(compgen -u); do \
eval test -d ~$u && echo $u; unset u; done} {} /@ users
if {![find_unique_completion_pair $users part full]} {
untested "Not running, no suitable test user found: $test"
} else {
assert_complete "~$full/" "$cmd ~$part" $test -nospace
}
}


# Source/run file with additional tests if completion for the specified command
# is installed in bash, and the command is available.
# @param string $command Command to check completion availability for.
Expand Down

0 comments on commit ec85ac4

Please sign in to comment.