Add iojs support to `nvm_remote_version`

master
Jordan Harband 2015-01-13 02:22:22 -08:00
parent d70f0357f5
commit 58ab2c3128
2 changed files with 28 additions and 7 deletions

8
nvm.sh
View File

@ -207,8 +207,12 @@ nvm_remote_version() {
local PATTERN local PATTERN
PATTERN="$1" PATTERN="$1"
local VERSION local VERSION
VERSION="$(nvm_ls_remote "$PATTERN" | tail -n1)" if nvm_is_iojs_version "$PATTERN"; then
echo "$VERSION" VERSION="$(nvm_ls_remote_iojs "$PATTERN")"
else
VERSION="$(nvm_ls_remote "$PATTERN")"
fi
echo "$VERSION" | tail -n1
if [ "_$VERSION" = '_N/A' ]; then if [ "_$VERSION" = '_N/A' ]; then
return 3 return 3

View File

@ -3,7 +3,7 @@
die () { echo $@ ; cleanup ; exit 1; } die () { echo $@ ; cleanup ; exit 1; }
cleanup() { cleanup() {
unset -f nvm_ls_remote unset -f nvm_ls_remote nvm_ls_remote_iojs
} }
. ../../../nvm.sh . ../../../nvm.sh
@ -11,25 +11,42 @@ cleanup() {
nvm_ls_remote() { nvm_ls_remote() {
echo "N/A" echo "N/A"
} }
OUTPUT="$(nvm_remote_version foo)" OUTPUT="$(nvm_remote_version foo)"
EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)" EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A" [ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A"
[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE" [ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE"
nvm_ls_remote_iojs() {
echo "N/A"
}
OUTPUT="$(nvm_remote_version iojs-foo)"
EXIT_CODE="$(nvm_remote_version iojs-foo >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A"
[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE"
nvm_ls_remote() { nvm_ls_remote() {
echo "test output" echo "test output"
echo "more test output" echo "more test output"
echo "pattern received: _$1_" echo "pattern received: _$1_"
} }
OUTPUT="$(nvm_remote_version foo)" OUTPUT="$(nvm_remote_version foo)"
EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)" EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_pattern received: _foo_" ] \ [ "_$OUTPUT" = "_pattern received: _foo_" ] \
|| die "nvm_remote_version foo did not return last line only of nvm_ls_remote foo; got $OUTPUT" || die "nvm_remote_version foo did not return last line only of nvm_ls_remote foo; got $OUTPUT"
[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version foo did not exit with 0, got $EXIT_CODE" [ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version foo did not exit with 0, got $EXIT_CODE"
nvm_ls_remote_iojs() {
echo "test iojs output"
echo "more iojs test output"
echo "iojs pattern received: _$1_"
}
OUTPUT="$(nvm_remote_version iojs-foo)"
EXIT_CODE="$(nvm_remote_version iojs-foo >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_iojs pattern received: _iojs-foo_" ] \
|| die "nvm_remote_version iojs-foo did not return last line only of nvm_ls_remote_iojs foo; got $OUTPUT"
[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version iojs-foo did not exit with 0, got $EXIT_CODE"
cleanup cleanup