From 9068dda1107328b87ac1b9c7fefaaffd0cc9297a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 19 Aug 2014 01:53:39 -0700 Subject: [PATCH] Adding `nvm_version_dir` --- nvm.sh | 13 +++++++++++++ test/fast/Unit tests/nvm_version_dir | 11 +++++++++++ 2 files changed, 24 insertions(+) create mode 100755 test/fast/Unit tests/nvm_version_dir diff --git a/nvm.sh b/nvm.sh index 98e6228..67794cb 100644 --- a/nvm.sh +++ b/nvm.sh @@ -95,6 +95,19 @@ nvm_rc_version() { fi } +nvm_version_dir() { + local NVM_USE_NEW_DIR + NVM_USE_NEW_DIR="$1" + if [ -z "$NVM_USE_NEW_DIR" ] || [ "$NVM_USE_NEW_DIR" = "new" ]; then + echo "$NVM_DIR/versions" + elif [ "$NVM_USE_NEW_DIR" = "old" ]; then + echo "$NVM_DIR" + else + echo "unknown version dir" >&2 + return 3 + fi +} + nvm_version_path() { local VERSION VERSION="$1" diff --git a/test/fast/Unit tests/nvm_version_dir b/test/fast/Unit tests/nvm_version_dir new file mode 100755 index 0000000..fb070ce --- /dev/null +++ b/test/fast/Unit tests/nvm_version_dir @@ -0,0 +1,11 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +[ "$(nvm_version_dir)" = "$NVM_DIR/versions" ] || die '"nvm_version_dir" did not return new dir path' +[ "$(nvm_version_dir new)" = "$(nvm_version_dir)" ] || die '"nvm_version_dir new" did not return new dir path' +[ "$(nvm_version_dir old)" = "$NVM_DIR" ] || die '"nvm_version_dir old" did not return old dir path' +[ "$(nvm_version_dir foo 2>&1)" = "unknown version dir" ] || die '"nvm_version_dir foo" did not error out' +