[Tests] improve debug output on failure

Jordan Harband 2022-12-27 21:41:26 -08:00
parent ce35311657
commit dc691121b8
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
1 changed files with 9 additions and 7 deletions

View File

@ -32,15 +32,17 @@ setup
npm install -g nop >/dev/null || die 'nvm_check_global_modules cannot be tested because `npm` cannot install the `nop` package'
message=$(nvm_check_global_modules)
[ ! -z "$message" ] || die "nvm_check_global_modules should have printed a notice when npm had global modules installed"
[ ! -z "$message" ] || die "nvm_check_global_modules should have printed a notice when npm had global modules installed; got:\n${message}"
if [ -n "${ORIGINAL_NVM_DIR}" ]; then
# Admit we're using NVM, just for this one test
message=$(NVM_DIR=$ORIGINAL_NVM_DIR nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm is managed by nvm"
message=$(NVM_DIR="${ORIGINAL_NVM_DIR}" nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm is managed by nvm; got:\n${message}"
fi
npm uninstall -g nop >/dev/null
message=$(nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed"
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed; got:\n${message}"
# Faking an installation of npm
mkdir -p "$npm_config_prefix/lib/node_modules/npm"
@ -49,7 +51,7 @@ cat <<'JSON' >"$npm_config_prefix/lib/node_modules/npm/package.json"
JSON
message=$(nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm had only itself installed as a global module"
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm had only itself installed as a global module; got:\n${message}"
# Faking the absence of npm
PATH=".:$PATH"
@ -57,7 +59,7 @@ touch npm
chmod +x npm
message=$(nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm was unavailable"
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm was unavailable; got:\n${message}"
cleanup