mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-10-11 00:00:13 +08:00
The file is read, not sourced. An `ID` with no OS of its own is only taken as Linux when the kernel's `ostype` says so; otherwise `uname -a` decides.
53 lines
1.6 KiB
Bash
Executable File
53 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
ORIG_PATH="${PATH}"
|
|
|
|
cleanup() {
|
|
rm -f ./uname
|
|
export PATH="${ORIG_PATH}"
|
|
}
|
|
|
|
die () { cleanup; echo "$@" ; exit 1; }
|
|
|
|
: nvm.sh
|
|
\. ../../../nvm.sh
|
|
|
|
MOCKS_DIR="$(pwd)/../../mocks"
|
|
export PATH=".:${PATH}"
|
|
|
|
# `nvm_get_os` reads `/etc/os-release` where it is available; this test drives
|
|
# the OS through the mocked `uname`, so point it at a file that does not exist
|
|
export NVM_OS_RELEASE="${MOCKS_DIR}/nonexistent-os-release"
|
|
|
|
# On Alpine (where /etc/alpine-release exists), both x64 and arm64 should get
|
|
# the -musl suffix, since unofficial-builds publishes musl binaries for both.
|
|
# On non-Alpine, neither should get -musl.
|
|
|
|
if [ -f "/etc/alpine-release" ]; then
|
|
# x64 on Alpine should produce x64-musl
|
|
ln -sf "${MOCKS_DIR}/uname_linux_x86_64" ./uname
|
|
OUTPUT="$(nvm_get_arch)"
|
|
rm -f ./uname
|
|
[ "_${OUTPUT}" = "_x64-musl" ] || die "x64 on Alpine should be x64-musl, got ${OUTPUT}"
|
|
|
|
# aarch64 on Alpine should produce arm64-musl
|
|
ln -sf "${MOCKS_DIR}/uname_linux_aarch64" ./uname
|
|
OUTPUT="$(nvm_get_arch)"
|
|
rm -f ./uname
|
|
[ "_${OUTPUT}" = "_arm64-musl" ] || die "aarch64 on Alpine should be arm64-musl, got ${OUTPUT}"
|
|
else
|
|
# x64 on non-Alpine should produce x64 (no musl suffix)
|
|
ln -sf "${MOCKS_DIR}/uname_linux_x86_64" ./uname
|
|
OUTPUT="$(nvm_get_arch)"
|
|
rm -f ./uname
|
|
[ "_${OUTPUT}" = "_x64" ] || die "x64 on non-Alpine should be x64, got ${OUTPUT}"
|
|
|
|
# aarch64 on non-Alpine should produce arm64
|
|
ln -sf "${MOCKS_DIR}/uname_linux_aarch64" ./uname
|
|
OUTPUT="$(nvm_get_arch)"
|
|
rm -f ./uname
|
|
[ "_${OUTPUT}" = "_arm64" ] || die "aarch64 on non-Alpine should be arm64, got ${OUTPUT}"
|
|
fi
|
|
|
|
cleanup
|