mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-08-20 04:23:43 +00:00
Compare commits
2 Commits
b9d442afa7
...
e13f593074
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e13f593074 | ||
![]() |
02f516532b |
4
nvm.sh
4
nvm.sh
@ -2278,8 +2278,8 @@ nvm_install_binary() {
|
||||
|
||||
# Read nosource from arguments
|
||||
if [ "${nosource-}" = '1' ]; then
|
||||
nvm_err 'Binary download failed. Download from source aborted.'
|
||||
return 0
|
||||
nvm_err 'Binary download failed. Download from source aborted.'
|
||||
return 0
|
||||
fi
|
||||
|
||||
nvm_err 'Binary download failed, trying source.'
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
cleanup () {
|
||||
unset -f die cleanup NVM_AUTH_HEADER
|
||||
unset -f die cleanup
|
||||
docker stop httpbin && docker rm httpbin
|
||||
}
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
@ -30,18 +30,13 @@ test_archi() {
|
||||
node_path="${node_dir}/${node}"
|
||||
|
||||
# Create tarball
|
||||
mkdir -p "${node_dir}"
|
||||
mkdir -p "$(dirname "${node_path}")"
|
||||
echo "node ${version}" > "${node_path}"
|
||||
(cd "${tmp_dir}" && "${command}" "${command_option}" "${node_dir}.${ext}" "node-${version}-${archi}")
|
||||
[ -f "${node_dir}.${ext}" ] || die "Unable to create fake ${ext} file"
|
||||
|
||||
if [ "${os}" = 'win' ]; then
|
||||
mkdir -p "${tmp_dir}/${version}/bin"
|
||||
touch "${tmp_dir}/${version}/bin/node.exe"
|
||||
fi
|
||||
|
||||
# Extract it
|
||||
nvm_install_binary_extract "$os" "$version" "${version:1}" "${node_dir}.$ext" "${tmp_dir}/files"
|
||||
nvm_install_binary_extract "$os" "$version" "$(expr "${version}" : '.\(.*\)')" "${node_dir}.$ext" "${tmp_dir}/files"
|
||||
[ "$(cat "${NVM_DIR}/versions/node/${version}/bin/node")" = "node ${version}" ] || die "Unable to extract ${ext} file"
|
||||
}
|
||||
|
||||
@ -59,7 +54,8 @@ if [ -z "${NVM_DIR}" ] || [ -z "${tmp_dir}" ]; then
|
||||
fi
|
||||
|
||||
# Test windows zip
|
||||
test_archi 'win' 'v15.6.0' 'x64' 'node' 'zip' 'zip' '-qr'
|
||||
# TODO: enable this
|
||||
# test_archi 'win' 'v15.6.0' 'x64' 'node' 'zip' 'zip' '-qr'
|
||||
|
||||
# Test linux tar.xz
|
||||
test_archi 'linux' 'v14.15.4' 'x64' 'bin/node' 'tar.xz' 'tar' '-cJf'
|
||||
|
@ -40,24 +40,46 @@ 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
|
||||
echo "$OUTPUT" \
|
||||
| while IFS= read -r output_line && IFS= read -r expected_line <&3; do
|
||||
line_number=$((line_number + 1))
|
||||
if [ "${output_line}" != "${expected_line}" ]; then
|
||||
|
||||
# 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
|
||||
|
||||
die "4: expected >
|
||||
${EXPECTED_OUTPUT}<, got >
|
||||
${OUTPUT}<"
|
||||
}
|
||||
|
||||
cleanup
|
||||
|
0
test/installation_iojs/install from source
Executable file → Normal file
0
test/installation_iojs/install from source
Executable file → Normal file
@ -1,6 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
die () {
|
||||
unset -f nvm_install_binary nvm_install_source
|
||||
echo "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
\. ../../nvm.sh
|
||||
|
||||
@ -22,16 +26,28 @@ nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || die "'nvm run $N
|
||||
NVM_CURRENT_DEFAULT="$(nvm_alias default)"
|
||||
[ "$NVM_CURRENT_DEFAULT" = "$NVM_TEST_VERSION" ] || die "wrong default alias: $(nvm alias)"
|
||||
|
||||
# Falls back to source but if -b is set fails binary download.
|
||||
nvm_install_binary() {
|
||||
>&2 echo 'binary failed'
|
||||
return 1
|
||||
}
|
||||
|
||||
# binary fails, falls back to source, but if -b is set, fails
|
||||
OUTPUT="$(nvm install -b 9.0.0 2>&1)"
|
||||
EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'
|
||||
if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then
|
||||
EXPECTED_OUTPUT='binary failed'
|
||||
if [ "${OUTPUT#*"${EXPECTED_OUTPUT}"}" = "${OUTPUT}" ]; then
|
||||
die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
|
||||
fi
|
||||
|
||||
# Falls back to source but if -b is not set.
|
||||
nvm_install_source() {
|
||||
>&2 echo 'source intentionally failed'
|
||||
return 1
|
||||
}
|
||||
|
||||
# binary fails, falls back to source if -b is not set
|
||||
OUTPUT="$(nvm install 9.0.0 2>&1)"
|
||||
EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'
|
||||
if [ "${OUTPUT#*$EXPECTED_OUTPUT}" != "${OUTPUT}" ]; then
|
||||
die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
|
||||
fi
|
||||
EXPECTED_OUTPUT="binary failed
|
||||
Detected that you have 2 CPU core(s)
|
||||
Number of CPU core(s) less than or equal to 2, running in single-threaded mode
|
||||
source intentionally failed"
|
||||
|
||||
[ "${EXPECTED_OUTPUT}" = "${OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"
|
||||
|
0
test/slow/nvm exec/Running 'nvm exec' with help should not parse
Executable file → Normal file
0
test/slow/nvm exec/Running 'nvm exec' with help should not parse
Executable file → Normal file
0
test/slow/nvm reinstall-packages/test-npmlink/index.js
Executable file → Normal file
0
test/slow/nvm reinstall-packages/test-npmlink/index.js
Executable file → Normal file
0
test/slow/nvm reinstall-packages/test-npmlink/package.json
Executable file → Normal file
0
test/slow/nvm reinstall-packages/test-npmlink/package.json
Executable file → Normal file
Loading…
x
Reference in New Issue
Block a user