]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: add function to change directory reliable way
authorSami Kerola <kerolasa@iki.fi>
Sun, 22 Jun 2014 09:20:54 +0000 (10:20 +0100)
committerSami Kerola <kerolasa@iki.fi>
Fri, 18 Jul 2014 17:34:14 +0000 (18:34 +0100)
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>
tests/functions.sh

index 2a50de721ae4b7b10712574a3e899093c0ca98b5..6998343e1f9a368c1f2eabc2adce546e672d9d49 100644 (file)
@@ -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"