Skip to content

Commit dc69112

Browse files
committed
[Tests] improve debug output on failure
1 parent ce35311 commit dc69112

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

test/install_script/nvm_check_global_modules

+9-7
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ setup
3232

3333
npm install -g nop >/dev/null || die 'nvm_check_global_modules cannot be tested because `npm` cannot install the `nop` package'
3434
message=$(nvm_check_global_modules)
35-
[ ! -z "$message" ] || die "nvm_check_global_modules should have printed a notice when npm had global modules installed"
35+
[ ! -z "$message" ] || die "nvm_check_global_modules should have printed a notice when npm had global modules installed; got:\n${message}"
3636

37-
# Admit we're using NVM, just for this one test
38-
message=$(NVM_DIR=$ORIGINAL_NVM_DIR nvm_check_global_modules)
39-
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm is managed by nvm"
37+
if [ -n "${ORIGINAL_NVM_DIR}" ]; then
38+
# Admit we're using NVM, just for this one test
39+
message=$(NVM_DIR="${ORIGINAL_NVM_DIR}" nvm_check_global_modules)
40+
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm is managed by nvm; got:\n${message}"
41+
fi
4042

4143
npm uninstall -g nop >/dev/null
4244
message=$(nvm_check_global_modules)
43-
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed"
45+
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed; got:\n${message}"
4446

4547
# Faking an installation of npm
4648
mkdir -p "$npm_config_prefix/lib/node_modules/npm"
@@ -49,15 +51,15 @@ cat <<'JSON' >"$npm_config_prefix/lib/node_modules/npm/package.json"
4951
JSON
5052

5153
message=$(nvm_check_global_modules)
52-
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm had only itself installed as a global module"
54+
[ -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}"
5355

5456
# Faking the absence of npm
5557
PATH=".:$PATH"
5658
touch npm
5759
chmod +x npm
5860

5961
message=$(nvm_check_global_modules)
60-
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm was unavailable"
62+
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm was unavailable; got:\n${message}"
6163

6264

6365
cleanup

0 commit comments

Comments
 (0)