2015-01-24 10:38:50 +08:00
|
|
|
#!/bin/sh
|
2015-02-08 10:50:10 +08:00
|
|
|
puts() (IFS=" "; printf %s\\n "$*" ;)
|
2015-01-24 10:38:50 +08:00
|
|
|
|
|
|
|
cleanup () {
|
|
|
|
rm -rf "$npm_config_prefix/lib" >/dev/null 2>&1
|
|
|
|
unset npm_config_prefix
|
|
|
|
|
2015-02-03 10:42:12 +08:00
|
|
|
rm -f npm
|
|
|
|
PATH="$ORIGINAL_PATH"
|
|
|
|
|
2015-02-08 10:50:10 +08:00
|
|
|
unset -f setup cleanup die
|
2015-02-03 10:42:12 +08:00
|
|
|
unset message ORIGINAL_PATH
|
2015-01-24 10:38:50 +08:00
|
|
|
}
|
2015-02-08 10:50:10 +08:00
|
|
|
|
|
|
|
die () { puts "!! $@" ; cleanup ; exit 1; }
|
2015-01-24 10:38:50 +08:00
|
|
|
|
|
|
|
NVM_ENV=testing . ../../install.sh
|
|
|
|
|
|
|
|
setup () {
|
2015-02-03 10:42:12 +08:00
|
|
|
ORIGINAL_PATH="$PATH"
|
|
|
|
|
2015-01-24 10:38:50 +08:00
|
|
|
npm_config_prefix="$(pwd)"
|
|
|
|
export npm_config_prefix
|
|
|
|
mkdir -p "$npm_config_prefix/lib"
|
|
|
|
}
|
|
|
|
|
|
|
|
setup
|
|
|
|
|
2015-02-08 10:50:10 +08:00
|
|
|
|
2015-02-08 10:53:53 +08:00
|
|
|
npm install -g nop >/dev/null || die 'nvm_check_global_modules cannot be tested because `npm` cannot install the `nop` package'
|
2015-01-24 10:38:50 +08:00
|
|
|
message=$(nvm_check_global_modules)
|
2015-02-08 10:50:10 +08:00
|
|
|
[ ! -z "$message" ] || {
|
|
|
|
puts '-- `npm --version`: '"$(npm --version)"
|
|
|
|
puts '-- `npm list -g`:'
|
|
|
|
npm list -g --depth=0
|
|
|
|
puts '-- Printed message:'
|
|
|
|
puts "'''$message'''"
|
|
|
|
|
|
|
|
die "nvm_check_global_modules should have printed a notice when npm had global modules installed" ;}
|
|
|
|
|
2015-01-24 10:38:50 +08:00
|
|
|
|
2015-02-05 06:39:57 +08:00
|
|
|
npm uninstall -g nop >/dev/null
|
2015-01-24 10:38:50 +08:00
|
|
|
message=$(nvm_check_global_modules)
|
2015-02-08 10:50:10 +08:00
|
|
|
[ -z "$message" ] || {
|
|
|
|
puts '-- `npm --version`: '"$(npm --version)"
|
|
|
|
puts '-- `npm list -g`:'
|
|
|
|
npm list -g --depth=0
|
|
|
|
puts '-- Printed message:'
|
|
|
|
puts "'''$message'''"
|
|
|
|
|
|
|
|
die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed" ;}
|
|
|
|
|
2015-01-24 10:38:50 +08:00
|
|
|
|
|
|
|
# Faking an installation of npm
|
|
|
|
mkdir -p "$npm_config_prefix/lib/node_modules/npm"
|
|
|
|
cat <<'JSON' >"$npm_config_prefix/lib/node_modules/npm/package.json"
|
|
|
|
{ "name": "npm", "version": "0.0.1fake" }
|
|
|
|
JSON
|
|
|
|
|
|
|
|
message=$(nvm_check_global_modules)
|
2015-02-08 10:50:10 +08:00
|
|
|
[ -z "$message" ] || {
|
|
|
|
puts '-- `which npm`: ' "$(which npm)"
|
|
|
|
puts '-- `npm --version`: ' "$(npm --version)"
|
|
|
|
puts '-- `npm list -g`:'
|
|
|
|
npm list -g --depth=0
|
|
|
|
puts '-- Printed message:'
|
|
|
|
puts "'''$message'''"
|
|
|
|
|
|
|
|
die "nvm_check_global_modules should not have printed a notice when npm had only itself installed as a global module" ;}
|
|
|
|
|
2015-01-24 10:38:50 +08:00
|
|
|
|
2015-02-03 10:42:12 +08:00
|
|
|
# Faking the absence of npm
|
|
|
|
PATH=".:$PATH"
|
|
|
|
touch npm
|
|
|
|
chmod +x npm
|
|
|
|
|
|
|
|
message=$(nvm_check_global_modules)
|
2015-02-08 10:50:10 +08:00
|
|
|
[ -z "$message" ] || {
|
|
|
|
puts '-- `which npm`: ' "$(which npm)"
|
|
|
|
puts '-- `npm --version`: ' "$(npm --version)"
|
|
|
|
puts '-- Printed message:'
|
|
|
|
puts "'''$message'''"
|
|
|
|
|
|
|
|
die "nvm_check_global_modules should not have printed a notice when npm was unavailable" ;}
|
2015-02-03 10:42:12 +08:00
|
|
|
|
|
|
|
|
2015-01-24 10:38:50 +08:00
|
|
|
cleanup
|