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 # Read nosource from arguments
if [ "${nosource-}" = '1' ]; then if [ "${nosource-}" = '1' ]; then
nvm_err 'Binary download failed. Download from source aborted.' nvm_err 'Binary download failed. Download from source aborted.'
return 0 return 0
fi fi
nvm_err 'Binary download failed, trying source.' nvm_err 'Binary download failed, trying source.'

View File

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

View File

@ -30,13 +30,18 @@ test_archi() {
node_path="${node_dir}/${node}" node_path="${node_dir}/${node}"
# Create tarball # Create tarball
mkdir -p "$(dirname "${node_path}")" mkdir -p "${node_dir}"
echo "node ${version}" > "${node_path}" echo "node ${version}" > "${node_path}"
(cd "${tmp_dir}" && "${command}" "${command_option}" "${node_dir}.${ext}" "node-${version}-${archi}") (cd "${tmp_dir}" && "${command}" "${command_option}" "${node_dir}.${ext}" "node-${version}-${archi}")
[ -f "${node_dir}.${ext}" ] || die "Unable to create fake ${ext} file" [ -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 # 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" [ "$(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 fi
# Test windows zip # 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 linux tar.xz
test_archi 'linux' 'v14.15.4' 'x64' 'bin/node' 'tar.xz' 'tar' '-cJf' 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)" [ "$(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}" ] || { [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || {
echo "$OUTPUT" \ echo "$OUTPUT" |
| while IFS= read -r output_line && IFS= read -r expected_line <&3; do while IFS= read -r output_line && IFS= read -r expected_line <&3; do
line_number=$((line_number + 1)) 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 "Difference on line ${line_number}:"
echo "Output: ${output_line}" echo "Output: ${output_line}"
echo "Expected: ${expected_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 fi
done 3<<EOF done 3<<EOF
$EXPECTED_OUTPUT $EXPECTED_OUTPUT
EOF EOF
die "4: expected >
${EXPECTED_OUTPUT}<, got >
${OUTPUT}<"
} }
cleanup cleanup

0
test/installation_iojs/install from source Normal file → Executable file
View File

View File

@ -1,10 +1,6 @@
#!/bin/sh #!/bin/sh
die () { die () { echo "$@" ; exit 1; }
unset -f nvm_install_binary nvm_install_source
echo "$@"
exit 1
}
\. ../../nvm.sh \. ../../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_alias default)"
[ "$NVM_CURRENT_DEFAULT" = "$NVM_TEST_VERSION" ] || die "wrong default alias: $(nvm alias)" [ "$NVM_CURRENT_DEFAULT" = "$NVM_TEST_VERSION" ] || die "wrong default alias: $(nvm alias)"
nvm_install_binary() { # Falls back to source but if -b is set fails binary download.
>&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)" OUTPUT="$(nvm install -b 9.0.0 2>&1)"
EXPECTED_OUTPUT='binary failed' EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'
if [ "${OUTPUT#*"${EXPECTED_OUTPUT}"}" = "${OUTPUT}" ]; then if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then
die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<" die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
fi fi
nvm_install_source() { # Falls back to source but if -b is not set.
>&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)" OUTPUT="$(nvm install 9.0.0 2>&1)"
EXPECTED_OUTPUT="binary failed EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'
Detected that you have 2 CPU core(s) if [ "${OUTPUT#*$EXPECTED_OUTPUT}" != "${OUTPUT}" ]; then
Number of CPU core(s) less than or equal to 2, running in single-threaded mode die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
source intentionally failed" fi
[ "${EXPECTED_OUTPUT}" = "${OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"

View File

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

View File