diff --git a/test/common.sh b/test/common.sh index a7ca5e0..054f007 100644 --- a/test/common.sh +++ b/test/common.sh @@ -33,3 +33,26 @@ fi echo $PORT } + +# Emulate GNU readlink's behavior on non-GNU readlink (e.g. MacOSX / BSD's) +# Credit to https://stackoverflow.com/a/1116890 +function gnureadlink() { + TARGET_FILE=$1 + + cd `dirname $TARGET_FILE` + TARGET_FILE=`basename $TARGET_FILE` + + # Iterate down a (possible) chain of symlinks + while [ -L "$TARGET_FILE" ] + do + TARGET_FILE=`readlink $TARGET_FILE` + cd `dirname $TARGET_FILE` + TARGET_FILE=`basename $TARGET_FILE` + done + + # Compute the canonicalized name by finding the physical path + # for the directory we're in and appending the target file. + PHYS_DIR=`pwd -P` + RESULT=$PHYS_DIR/$TARGET_FILE + echo $RESULT +} diff --git a/test/run-unittest.sh b/test/run-unittest.sh index 5f27b93..b0f29a5 100755 --- a/test/run-unittest.sh +++ b/test/run-unittest.sh @@ -41,7 +41,7 @@ for script in $(ls $CURR_DIR/*.sh); do if [[ ! "$script" =~ $FILTER ]]; then continue; fi - if [ "$script" = "$(readlink -f ${BASH_SOURCE[0]})" ] || [ "$(basename $script)" = "common.sh" ]; then continue; fi + if [ "$script" = "$(gnureadlink ${BASH_SOURCE[0]})" ] || [ "$(basename $script)" = "common.sh" ]; then continue; fi if [ -e $script.min_frontend ] && [ ! -z "$FRONTEND" ] && [ ${FRONTEND} \< $(cat $script.min_frontend) ]; then continue; fi log "Running $script..." DUB=$DUB DC=$DC CURR_DIR="$CURR_DIR" $script || logError "Script failure."