Skip to content

Commit

Permalink
test: Add some _expand unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Mar 16, 2018
1 parent 3c4fc36 commit 3b8dfd3
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/unit/_expand.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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 {echo "$USER"} {} /@ _user
set _user [string trim $_user]
}

proc teardown {} {
assert_env_unmodified {
/COMPREPLY=/d
/cur=/d
}
}


setup home user


set test "function should run without errors"
assert_bash_exec {_expand > /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() { _expand; }; foo; unset foo} $test
sync_after_int


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

0 comments on commit 3b8dfd3

Please sign in to comment.