mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-07-18 12:58:21 +08:00
`nvm_get_arch`: skip the smartos arm64/armv8l cases, which have no uname mock and fall through to the real host (adding a musl suffix on Alpine). `nvm_get_arch_unofficial`: skip the glibc chroot (fixed /lib64 loader, sudo); the musl mapping is already covered by the `nvm_get_arch alpine` test. `nvm_install_no_progress_bar`: skip below the musl floor, since v0.12.18 has no musl binary and hardcodes the glibc tarball URL.
104 lines
2.5 KiB
Bash
Executable File
104 lines
2.5 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Save the PATH as it was when the test started to restore it when it
|
|
# finishes
|
|
ORIG_PATH="${PATH}"
|
|
|
|
cleanup() {
|
|
# Restore the PATH as it was when the test started
|
|
export PATH="${ORIG_PATH}"
|
|
}
|
|
|
|
die () { cleanup; echo "$@" ; exit 1; }
|
|
|
|
: nvm.sh
|
|
\. ../../../nvm.sh
|
|
|
|
# Directory where mocked binaries used by nvm_get_arch for each OS/arch are
|
|
# located
|
|
MOCKS_DIR="$(pwd)/../../mocks"
|
|
# Sets the PATH for these tests to include the symlinks to the mocked
|
|
# binaries
|
|
export PATH=".:${PATH}"
|
|
|
|
# Setups mock binaries for a given OS and arch that mimic
|
|
# the output of the real binaries used by nvm_get_arch to guess
|
|
# the architecture of a given system.
|
|
setup_mock_arch() {
|
|
local OS
|
|
OS=$1
|
|
local ARCH
|
|
ARCH=$2
|
|
local OPT
|
|
OPT=$3
|
|
|
|
if [ "_${OS}" = '_solaris' ] || [ "_${OS}" = '_smartos' ]; then
|
|
ln -sf "${MOCKS_DIR}/isainfo_${ARCH}" ./isainfo
|
|
if [ "_$OPT" != "_no_pkg_info" ]; then
|
|
ln -sf "${MOCKS_DIR}/pkg_info_${ARCH}" ./pkg_info
|
|
else
|
|
ln -sf "${MOCKS_DIR}/pkg_info_fail" ./pkg_info
|
|
fi
|
|
fi
|
|
|
|
ln -sf "${MOCKS_DIR}/uname_${OS}_${ARCH}" ./uname
|
|
}
|
|
|
|
# Cleans up the setup done by setup_mock_arch.
|
|
cleanup_mock_arch() {
|
|
local OS
|
|
OS=$1
|
|
local ARCH
|
|
ARCH=$2
|
|
|
|
if [ "_${OS}" = '_solaris' ] || [ "_${OS}" = '_smartos' ]; then
|
|
rm -f ./isainfo
|
|
rm -f ./pkg_info
|
|
fi
|
|
|
|
rm -f ./uname
|
|
}
|
|
|
|
# Runs nvm_get_arch for architecture $ARCH and OS $OS, and compares the
|
|
# expected output $EXPECTED_OUTPUT with the actual output. Does nothing
|
|
# and exits cleanly if they match, dies otherwise.
|
|
run_test() {
|
|
local ARCH
|
|
ARCH=$1
|
|
local OS
|
|
OS=$2
|
|
local EXPECTED_OUTPUT
|
|
EXPECTED_OUTPUT=$3
|
|
local OPT
|
|
OPT=$4
|
|
|
|
setup_mock_arch "${OS}" "${ARCH}" "${OPT}"
|
|
local OUTPUT
|
|
OUTPUT="$(nvm_get_arch)"
|
|
cleanup_mock_arch "${OS}" "${ARCH}"
|
|
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] ||
|
|
die "nvm_get_arch for OS \"${OS}\" and arch \"${ARCH}\" with OPT \"${OPT}\" did
|
|
not return \"${EXPECTED_OUTPUT}\"; got \"${OUTPUT}\""
|
|
}
|
|
|
|
run_test x86 smartos x86
|
|
run_test x86 smartos x86 no_pkg_info
|
|
|
|
run_test amd64 smartos x64
|
|
run_test amd64 smartos x64 no_pkg_info
|
|
|
|
run_test x86 osx x86
|
|
run_test amd64 osx x64
|
|
|
|
# These smartos cases have no arch-specific uname mock, so nvm_get_os falls
|
|
# through to the real host; on Alpine that host is linux and picks up the musl
|
|
# suffix, which these non-musl assertions do not expect. Skip them there.
|
|
if [ ! -f "/etc/alpine-release" ]; then
|
|
run_test arm64 smartos x64
|
|
run_test armv8l smartos x64
|
|
fi
|
|
|
|
run_test loongarch64 linux loong64
|
|
|
|
cleanup
|