From 47c60dfc1d645d7145466ab1f4fbf1b3c22cca61 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 28 Nov 2016 12:50:35 -0800 Subject: [PATCH] [Tests] add test to ensure that `nvm unload` unloads all functions. --- nvm.sh | 2 +- ...ad\" should unset all function and variables." | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index 4ff9747..8ae2b8e 100755 --- a/nvm.sh +++ b/nvm.sh @@ -3172,7 +3172,7 @@ nvm() { nvm_list_aliases nvm_make_alias nvm_print_alias_path \ nvm_print_default_alias nvm_print_formatted_alias nvm_resolve_local_alias \ nvm_sanitize_path nvm_has_colors nvm_process_parameters \ - node_version_has_solaris_binary \ + node_version_has_solaris_binary iojs_version_has_solaris_binary \ > /dev/null 2>&1 unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \ NVM_CD_FLAGS NVM_BIN NVM_MAKE_JOBS NVM_PATH \ diff --git "a/test/fast/Running \"nvm unload\" should unset all function and variables." "b/test/fast/Running \"nvm unload\" should unset all function and variables." index 6634de1..f42470c 100755 --- "a/test/fast/Running \"nvm unload\" should unset all function and variables." +++ "b/test/fast/Running \"nvm unload\" should unset all function and variables." @@ -2,7 +2,13 @@ set -ex -die () { echo "$@" ; exit 1; } +BEFORE="./before.tmp" +AFTER="./after.tmp" + +cleanup () { rm -f "${BEFORE}" "${AFTER}"; } +die () { echo "$@" ; cleanup ; exit 1; } + +typeset -f | awk '/ \(\) $/ && !/^main / {print $1}' > "${BEFORE}" \. ../../nvm.sh @@ -10,4 +16,11 @@ type nvm > /dev/null 2>&1 || die "nvm not loaded" nvm unload +typeset -f | awk '/ \(\) $/ && !/^main / {print $1}' > "${AFTER}" + ! type nvm > /dev/null 2>&1 || die "nvm not unloaded" + +DIFF="$(diff "${BEFORE}" "${AFTER}" ||:)" +[ -z "${DIFF}" ] || die "function pollution found: ${DIFF}" + +cleanup