mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-09-18 00:00:30 +08:00
Under bash's `set +h`, `hash -r` errors with "hash: hashing disabled",
which is then printed on every `nvm use`, including the one at shell startup.
Guarding on `$-` alone would be wrong:
`zsh` never puts `h` in `$-` - there `h` is `HIST_IGNORE_DUPS` -
and `dash` has no `h` flag at all,
so it would skip the call in 3 of the 4 shells the fast suite runs.
Gate on the shell instead, and skip only where the call fails:
bash under `set +h`, and `ksh93`, whose `hash` takes no `-r` and whose
usage error aborts `nvm use` before it can export `NVM_BIN`.
`ksh` is detected by probing rather than by version,
so `mksh` and `pdksh`, which do accept `-r`, keep getting the call.
The `${-#*h}` test is from #3910.
Refs #2065
Refs #3247
46 lines
1.1 KiB
Bash
Executable File
46 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# the `bash` shebang is deliberate: only bash can exhibit the bug, so pinning
|
|
# it keeps this meaningful in every job of the shell matrix
|
|
|
|
die () { echo "$@" ; cleanup ; exit 1; }
|
|
cleanup () {
|
|
set -h
|
|
rm -f "${OUTPUT_FILE-}"
|
|
}
|
|
|
|
export NVM_DIR="$(cd ../.. && pwd)"
|
|
|
|
: nvm.sh
|
|
\. ../../nvm.sh
|
|
\. ../common.sh
|
|
|
|
make_fake_node v0.2.3 || die 'unable to make fake node'
|
|
|
|
OUTPUT_FILE="$(mktemp)"
|
|
|
|
set +h
|
|
|
|
# not in a command substitution, so the `PATH` it sets survives to `nvm deactivate`
|
|
nvm use --delete-prefix v0.2.3 > "${OUTPUT_FILE}" 2>&1
|
|
OUTPUT="$(cat "${OUTPUT_FILE}")"
|
|
case "${OUTPUT}" in
|
|
*'hash: '*) die "nvm use complained about hashing: ${OUTPUT}" ;;
|
|
esac
|
|
case "${OUTPUT}" in
|
|
*'Now using node v0.2.3'*) ;;
|
|
*) die "nvm use did not activate v0.2.3: ${OUTPUT}" ;;
|
|
esac
|
|
|
|
nvm deactivate > "${OUTPUT_FILE}" 2>&1
|
|
OUTPUT="$(cat "${OUTPUT_FILE}")"
|
|
case "${OUTPUT}" in
|
|
*'hash: '*) die "nvm deactivate complained about hashing: ${OUTPUT}" ;;
|
|
esac
|
|
case "${OUTPUT}" in
|
|
*'removed from ${PATH}'*) ;;
|
|
*) die "nvm deactivate did not strip the nvm bin dir: ${OUTPUT}" ;;
|
|
esac
|
|
|
|
cleanup
|