From 12ca8f260725274631ba0b68ba9056b09cdc56c8 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 20 Feb 2015 13:35:49 -0800 Subject: [PATCH] Add `nvm_is_alias` unit tests. Fixes 670. --- nvm.sh | 3 ++- test/fast/Unit tests/nvm_is_alias | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 test/fast/Unit tests/nvm_is_alias diff --git a/nvm.sh b/nvm.sh index 0a9b586..24ff367 100644 --- a/nvm.sh +++ b/nvm.sh @@ -13,7 +13,8 @@ nvm_has() { } nvm_is_alias() { - command alias "$1" > /dev/null 2>&1 + # this is intentionally not "command alias" so it works in zsh. + \alias "$1" > /dev/null 2>&1 } nvm_get_latest() { diff --git a/test/fast/Unit tests/nvm_is_alias b/test/fast/Unit tests/nvm_is_alias new file mode 100755 index 0000000..b5cf305 --- /dev/null +++ b/test/fast/Unit tests/nvm_is_alias @@ -0,0 +1,20 @@ +#!/bin/sh + +cleanup () { unalias foo; unalias grep; } +die () { echo $@ ; cleanup ; exit 1; } + +. ../../../nvm.sh + +alias foo='bar' +nvm_is_alias foo || die '"nvm_is_alias foo" was not true' + +! nvm_is_alias nvm_is_alias || die '"nvm_is_alias nvm_is_alias was not false' + +alias grep='grep' +unalias grep || die '"unalias grep" failed' +! nvm_is_alias grep || die '"nvm_is_alias grep" with unaliased grep was not false' + +alias grep='grep' +nvm_is_alias grep || die '"nvm_is_alias grep" with aliased grep was not true' + +cleanup