bash-completion/test/unit/__expand_tilde_by_ref.exp
Freddy Vulto 11da957e45 (testsuite) `match_items()' matches on bash-prompt
Also made `match_items()' more strict about matching
space/newline/prompt after the last item.

Added options to match_items():
- end-newline
- end-prompt
- end-space
and transferred them to other functions.

Function `assert_complete()' now has a `-nospace' option to explicitly
disallow a space after a completion...

Function `assert_bash_list()' now expects a single item to be followed
by a newline.
2010-11-17 23:36:58 +01:00

88 lines
2.0 KiB
Plaintext

# @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 {echo "$USER"} {} /@ _user
set _user [string trim $_user]
}
proc teardown {} {
assert_env_unmodified {
/var=/d
}
}
setup home user
set test "function should run without errors"
assert_bash_exec {__expand_tilde_by_ref > /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="~"; __expand_tilde_by_ref aa; }; foo; unset foo} $test
sync_after_int
set test "~user should return /home/user"
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/user/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/user/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/user/\$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/user/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/user/*"
set cmd [format {var="~%s/*"; __expand_tilde_by_ref var; printf "%%s\n" "$var"} $user]
assert_bash_list "$home/\*" $cmd $test
sync_after_int
teardown