Compare commits

..

1 Commits

Author SHA1 Message Date
Jordan Harband
b9d442afa7
wip 2024-08-26 13:53:28 -07:00
9 changed files with 28 additions and 62 deletions

4
nvm.sh
View File

@ -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.'

View File

@ -1,7 +1,7 @@
#!/bin/sh
cleanup () {
unset -f die cleanup
unset -f die cleanup NVM_AUTH_HEADER
docker stop httpbin && docker rm httpbin
}
die () { echo "$@" ; cleanup ; exit 1; }

View File

@ -30,13 +30,18 @@ test_archi() {
node_path="${node_dir}/${node}"
# Create tarball
mkdir -p "$(dirname "${node_path}")"
mkdir -p "${node_dir}"
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" "$(expr "${version}" : '.\(.*\)')" "${node_dir}.$ext" "${tmp_dir}/files"
nvm_install_binary_extract "$os" "$version" "${version:1}" "${node_dir}.$ext" "${tmp_dir}/files"
[ "$(cat "${NVM_DIR}/versions/node/${version}/bin/node")" = "node ${version}" ] || die "Unable to extract ${ext} file"
}
@ -54,8 +59,7 @@ if [ -z "${NVM_DIR}" ] || [ -z "${tmp_dir}" ]; then
fi
# Test windows zip
# TODO: enable this
# test_archi 'win' 'v15.6.0' 'x64' 'node' 'zip' 'zip' '-qr'
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'

View File

@ -40,46 +40,24 @@ 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))
# 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
if [ "${output_line}" != "${expected_line}" ]; 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 Normal file → Executable file
View File

View File

@ -1,10 +1,6 @@
#!/bin/sh
die () {
unset -f nvm_install_binary nvm_install_source
echo "$@"
exit 1
}
die () { echo "$@" ; exit 1; }
\. ../../nvm.sh
@ -26,28 +22,16 @@ 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)"
nvm_install_binary() {
>&2 echo 'binary failed'
return 1
}
# binary fails, falls back to source, but if -b is set, fails
# Falls back to source but if -b is set fails binary download.
OUTPUT="$(nvm install -b 9.0.0 2>&1)"
EXPECTED_OUTPUT='binary failed'
if [ "${OUTPUT#*"${EXPECTED_OUTPUT}"}" = "${OUTPUT}" ]; then
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
nvm_install_source() {
>&2 echo 'source intentionally failed'
return 1
}
# binary fails, falls back to source if -b is not set
# Falls back to source but if -b is not set.
OUTPUT="$(nvm install 9.0.0 2>&1)"
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}<"
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

View File

0
test/slow/nvm reinstall-packages/test-npmlink/index.js Normal file → Executable file
View File

View File