From 8fe677a6443cd959e5b1ed1fc29cc9025719c626 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 20 Aug 2014 00:01:06 -0700 Subject: [PATCH] Add `nvm_version_greater` --- nvm.sh | 10 +++++++++- test/fast/Unit tests/nvm_version_greater | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100755 test/fast/Unit tests/nvm_version_greater diff --git a/nvm.sh b/nvm.sh index 8d8133f..8860919 100644 --- a/nvm.sh +++ b/nvm.sh @@ -95,6 +95,14 @@ nvm_rc_version() { fi } +nvm_version_greater() { + local LHS + LHS=$(echo "$1" | awk -F. '{for (i=1;i<=NF;++i) printf "%010d",$i}') + local RHS + RHS=$(echo "$2" | awk -F. '{for (i=1;i<=NF;++i) printf "%010d",$i}') + [ $LHS \> $RHS ]; +} + nvm_version_dir() { local NVM_USE_NEW_DIR NVM_USE_NEW_DIR="$1" @@ -777,7 +785,7 @@ nvm() { echo "0.13.1" ;; "unload" ) - unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version > /dev/null 2>&1 + unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version nvm_version_greater > /dev/null 2>&1 unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1 ;; * ) diff --git a/test/fast/Unit tests/nvm_version_greater b/test/fast/Unit tests/nvm_version_greater new file mode 100755 index 0000000..8f8f551 --- /dev/null +++ b/test/fast/Unit tests/nvm_version_greater @@ -0,0 +1,10 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +nvm_version_greater 0.10.0 0.2.12 || die '"nvm_version_greater 0.10.0 0.2.12" did not return true' +! nvm_version_greater 0.10.0 0.20.12 || die '"nvm_version_greater 0.10.0 0.20.12" returned true' +! nvm_version_greater 0.10.0 0.10.0 || die '"nvm_version_greater" returned false for the same two versions' +