mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-10-11 00:00:13 +08:00
- `nvm_get_arch`: the unmocked smartos cases fall through to the host, so only run them on x86_64 - `nvm_get_arch_unofficial`: the chroot checks need x86_64 glibc Linux - `nvm_install_no_progress_bar`: derive the tarball slug and checksum tool instead of assuming linux-x64 and `sha256sum`
98 lines
2.9 KiB
Bash
Executable File
98 lines
2.9 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
cleanup () {
|
|
nvm cache clear
|
|
nvm deactivate
|
|
rm -rf ${NVM_DIR}/v*
|
|
nvm unalias default || true
|
|
}
|
|
|
|
die () { >&2 echo "$@" ; cleanup ; exit 1; }
|
|
|
|
: nvm.sh
|
|
\. ../../../nvm.sh
|
|
|
|
# v0.12.18 predates musl binaries and the expected output hardcodes the glibc
|
|
# x64 tarball URL, so on Alpine nvm would request a nonexistent -musl build.
|
|
# The progress-bar behavior is not OS-specific, so skip below the musl floor.
|
|
if [ -f "/etc/alpine-release" ]; then
|
|
echo 'on Alpine; skipping (v0.12.18 has no musl binary)'
|
|
exit 0
|
|
fi
|
|
|
|
cleanup
|
|
|
|
SLUG="$(nvm_get_download_slug node binary v0.12.18)"
|
|
CHECKSUM_LINE="$(nvm_compute_checksum ../../../nvm.sh 2>&1 >/dev/null)"
|
|
|
|
OUTPUT="$(TERM=dumb 2>&1 nvm install --no-progress v0.12.18)"
|
|
EXPECTED_OUTPUT="Downloading and installing node v0.12.18...
|
|
Downloading https://nodejs.org/dist/v0.12.18/${SLUG}.tar.xz...
|
|
${CHECKSUM_LINE}
|
|
Checksums matched!
|
|
Now using node v0.12.18 (npm v2.15.11)
|
|
Creating default alias: default -> v0.12.18 *"
|
|
|
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "1: expected >
|
|
${EXPECTED_OUTPUT}<, got >
|
|
${OUTPUT}<"
|
|
|
|
cleanup
|
|
|
|
OUTPUT="$(TERM=dumb 2>&1 nvm install v0.12.18)"
|
|
EXPECTED_OUTPUT="Downloading and installing node v0.12.18...
|
|
Downloading https://nodejs.org/dist/v0.12.18/${SLUG}.tar.xz...
|
|
######################################################################### 100.0%
|
|
${CHECKSUM_LINE}
|
|
Checksums matched!
|
|
Now using node v0.12.18 (npm v2.15.11)
|
|
Creating default alias: default -> v0.12.18 *"
|
|
|
|
[ "$(echo "${OUTPUT}" | wc -l)" = "$(echo "${EXPECTED_OUTPUT}" | wc -l)" ] || die "2: expected 7 lines, got $(echo "${OUTPUT}" | wc -l)"
|
|
|
|
# Preprocess function to handle carriage returns and extract final output
|
|
preprocess_output() {
|
|
echo "$1" | awk '
|
|
{
|
|
# For each line in the input
|
|
while (index($0, "\r") > 0) {
|
|
# If a carriage return is found, process it
|
|
pos = index($0, "\r")
|
|
before_cr = substr($0, 1, pos - 1)
|
|
after_cr = substr($0, pos + 1)
|
|
# Overwrite the line up to the carriage return with content after it
|
|
$0 = after_cr
|
|
}
|
|
print $0
|
|
}' | sed '/^$/d' # Remove any empty lines
|
|
}
|
|
|
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || {
|
|
echo "$OUTPUT" \
|
|
| while IFS= read -r output_line && IFS= read -r expected_line <&3; do
|
|
line_number=$((line_number + 1))
|
|
|
|
# Strip non-visible characters from both lines
|
|
clean_output=$(preprocess_output "$output_line")
|
|
|
|
if [ "${output_line}" != "${expected_line}" ] && ! echo "${clean_output}" | \grep -qE '^#+ 100\.0%$'; then
|
|
echo "Difference on line ${line_number}:"
|
|
echo "Output: ${output_line}"
|
|
echo "Expected: ${expected_line}"
|
|
echo "Byte-by-byte comparison:"
|
|
echo "Output: $(echo "${clean_output}" | od -An -tx1 | tr -d '\n')"
|
|
echo "Expected: $(echo "${expected_line}" | od -An -tx1 | tr -d '\n')"
|
|
|
|
die "4: expected >
|
|
${EXPECTED_OUTPUT}<, got >
|
|
${OUTPUT}<"
|
|
fi
|
|
done 3<<EOF
|
|
$EXPECTED_OUTPUT
|
|
EOF
|
|
}
|
|
|
|
cleanup
|