mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-07-18 21:08:23 +08:00
`--offline` version resolution could only see cached node binaries: `nvm_ls_cached` listed `.cache/bin` with a `node-` prefix filter, so cached source tarballs, and everything io.js, could never resolve offline. List both cache kinds, for both flavors, and update the pinned test expectations to match.
73 lines
2.9 KiB
Bash
Executable File
73 lines
2.9 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
die () { echo "$@" ; cleanup ; exit 1; }
|
|
|
|
\. ../../../nvm.sh
|
|
|
|
\. ../../common.sh
|
|
|
|
TEST_DIR="$(pwd)/nvm_offline_version_tmp"
|
|
|
|
cleanup() {
|
|
rm -rf "${TEST_DIR}"
|
|
CACHE_DIR="$(nvm_cache_dir)"
|
|
SUFFIX="$(nvm_get_os)-$(nvm_get_arch)"
|
|
rm -rf "${CACHE_DIR}/bin/node-v0.99.98-${SUFFIX}" "${CACHE_DIR}/bin/iojs-v0.99.97-${SUFFIX}" \
|
|
"${CACHE_DIR}/src/node-v0.99.96" "${CACHE_DIR}/src/iojs-v0.99.95"
|
|
}
|
|
|
|
[ ! -e "${TEST_DIR}" ] && mkdir -p "${TEST_DIR}"
|
|
|
|
# nvm_offline_version should find installed versions
|
|
INSTALLED_VERSION="$(nvm_version node)"
|
|
if [ "_${INSTALLED_VERSION}" != '_N/A' ] && [ "_${INSTALLED_VERSION}" != '_system' ]; then
|
|
try nvm_offline_version "${INSTALLED_VERSION}"
|
|
[ "_$CAPTURED_STDOUT" = "_${INSTALLED_VERSION}" ] \
|
|
|| die "nvm_offline_version '${INSTALLED_VERSION}' should return '${INSTALLED_VERSION}'; got '$CAPTURED_STDOUT'"
|
|
[ "_$CAPTURED_EXIT_CODE" = "_0" ] \
|
|
|| die "nvm_offline_version '${INSTALLED_VERSION}' should exit 0; got '$CAPTURED_EXIT_CODE'"
|
|
fi
|
|
|
|
# nvm_offline_version with nonexistent version should return N/A
|
|
try nvm_offline_version "999.999.999"
|
|
[ "_$CAPTURED_STDOUT" = "_N/A" ] \
|
|
|| die "nvm_offline_version '999.999.999' should return 'N/A'; got '$CAPTURED_STDOUT'"
|
|
[ "_$CAPTURED_EXIT_CODE" = "_3" ] \
|
|
|| die "nvm_offline_version '999.999.999' should exit 3; got '$CAPTURED_EXIT_CODE'"
|
|
|
|
# nvm_ls_cached with nonexistent pattern should return nothing
|
|
try nvm_ls_cached "999.999"
|
|
[ -z "$CAPTURED_STDOUT" ] \
|
|
|| die "nvm_ls_cached '999.999' should return empty; got '$CAPTURED_STDOUT'"
|
|
|
|
# nvm_ls_cached should list bin- and src-cached artifacts, for node and io.js
|
|
CACHE_DIR="$(nvm_cache_dir)"
|
|
SUFFIX="$(nvm_get_os)-$(nvm_get_arch)"
|
|
mkdir -p "${CACHE_DIR}/bin/node-v0.99.98-${SUFFIX}" "${CACHE_DIR}/bin/iojs-v0.99.97-${SUFFIX}" \
|
|
"${CACHE_DIR}/src/node-v0.99.96" "${CACHE_DIR}/src/iojs-v0.99.95"
|
|
|
|
try nvm_ls_cached "v0.99.98"
|
|
[ "_$CAPTURED_STDOUT" = "_v0.99.98" ] \
|
|
|| die "nvm_ls_cached 'v0.99.98' should find the bin-cached node version; got '$CAPTURED_STDOUT'"
|
|
|
|
try nvm_ls_cached "iojs-v0.99.97"
|
|
[ "_$CAPTURED_STDOUT" = "_iojs-v0.99.97" ] \
|
|
|| die "nvm_ls_cached 'iojs-v0.99.97' should find the bin-cached io.js version; got '$CAPTURED_STDOUT'"
|
|
|
|
try nvm_ls_cached "v0.99.96"
|
|
[ "_$CAPTURED_STDOUT" = "_v0.99.96" ] \
|
|
|| die "nvm_ls_cached 'v0.99.96' should find the src-cached node version; got '$CAPTURED_STDOUT'"
|
|
|
|
try nvm_ls_cached "iojs-v0.99.95"
|
|
[ "_$CAPTURED_STDOUT" = "_iojs-v0.99.95" ] \
|
|
|| die "nvm_ls_cached 'iojs-v0.99.95' should find the src-cached io.js version; got '$CAPTURED_STDOUT'"
|
|
|
|
# ... and nvm_offline_version should resolve them
|
|
try nvm_offline_version "iojs-v0.99.95"
|
|
[ "_$CAPTURED_STDOUT" = "_iojs-v0.99.95" ] \
|
|
|| die "nvm_offline_version 'iojs-v0.99.95' should resolve the src-cached io.js version; got '$CAPTURED_STDOUT'"
|
|
[ "_$CAPTURED_EXIT_CODE" = "_0" ] \
|
|
|| die "nvm_offline_version 'iojs-v0.99.95' should exit 0; got '$CAPTURED_EXIT_CODE'"
|
|
|
|
cleanup
|