diff options
author | Sami Kerola | 2014-06-22 11:20:54 +0200 |
---|---|---|
committer | Sami Kerola | 2014-07-18 19:34:14 +0200 |
commit | 723c70434bd307522530e203e70dd113842cb474 (patch) | |
tree | c4709db61063068392380bd0dab096bd4961198d /tests/functions.sh | |
parent | rename: allow renaming in subdirectories (diff) | |
download | kernel-qcow2-util-linux-723c70434bd307522530e203e70dd113842cb474.tar.gz kernel-qcow2-util-linux-723c70434bd307522530e203e70dd113842cb474.tar.xz kernel-qcow2-util-linux-723c70434bd307522530e203e70dd113842cb474.zip |
tests: add function to change directory reliable way
Without arguments bash cd will move to $HOME. Ensure also that when
directory is assumed to be changed the current directory and intented
destination are the same location.
Reference: http://www.spinics.net/lists/util-linux-ng/msg09509.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'tests/functions.sh')
-rw-r--r-- | tests/functions.sh | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/functions.sh b/tests/functions.sh index 2a50de721..6998343e1 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -31,6 +31,20 @@ function ts_canonicalize { fi } +function ts_cd { + if [ $# -eq 0 ]; then + ts_failed "ul_cd: not enough arguments" + fi + DEST=$(readlink -f "$1" 2>/dev/null) + if [ "x$DEST" = "x" ] || [ ! -d "$DEST" ]; then + ts_failed "ul_cd: $1: no such directory" + fi + cd "$DEST" 2>/dev/null || ts_failed "ul_cd: $1: cannot change directory" + if [ "$PWD" != "$DEST" ]; then + ts_failed "ul_cd: $PWD is not $DEST" + fi +} + function ts_report { if [ "$TS_PARALLEL" == "yes" ]; then echo "$TS_TITLE $1" |