[Tests] fix broken tests exposed by 863bd63
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Leaves 2 non-executable, + some TODOs
authored by Jordan Harband · committed by Jordan Harband · parent 0ce8f5a · Browse files · 19 files·+256 added−157 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
19 files+256 added−157 removed
- tests:+246 added−151 removed
- other:+10 added−6 removed
Provenance
- Commit
ff76345- Tree
e947618- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
0ce8f5a
19 files changed+256 added−157 removed
modified:test/fast/Unit tests/nvm ls-remote+13 added-13 removed
20 unmodified lines21 nvm deactivate 2>/dev/null || die 'unable to deactivate'22 23 \. ../../common.sh24 25-MOCKS_DIR="$PWD/mocks"25+MOCKS_DIR="${PWD}/mocks"26 27 nvm_download() {28 if [ "$*" = "-L -s $(nvm_get_mirror node std)/index.tab -o -" ]; then29- cat "$MOCKS_DIR/nodejs.org-dist-index.tab"29+ cat "${MOCKS_DIR}/nodejs.org-dist-index.tab"30 return31 fi32 return 4233 }34 35 EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm ls-remote lts.txt"36 OUTPUT="$(nvm ls-remote --lts | sed 's/[ \t]*$//')"37-EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH" | sed 's/[ \t]*$//' )"38-[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm ls-remote --lts did not output expected sorted versions; got $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"37+EXPECTED_OUTPUT="$(cat "${EXPECTED_OUTPUT_PATH}" | sed 's/[ \t]*$//' )"38+[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm ls-remote --lts did not output expected sorted versions; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"39 40 EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm ls-remote lts.txt"41 OUTPUT="$(nvm ls-remote "lts/*" | sed 's/[ \t]*$//')"42-EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH" | sed 's/[ \t]*$//' )"43-[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm ls-remote lts/* did not output expected sorted versions; got $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"42+EXPECTED_OUTPUT="$(cat "${EXPECTED_OUTPUT_PATH}" | sed 's/[ \t]*$//' )"43+[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm ls-remote lts/* did not output expected sorted versions; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"44 45-MOCKS_DIR="$PWD/mocks"45+MOCKS_DIR="${PWD}/mocks"46 LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"47 LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)"48 49 INDEX=15 unmodified lines55 56 INDEX=$(($INDEX + 1))57 done58 59-REMOTE="$PWD/mocks/nvm_ls_remote.txt"59+REMOTE="${PWD}/mocks/nvm_ls_remote.txt"60 nvm_ls_remote() {61- cat "$REMOTE"61+ cat "${REMOTE}"62 }63-REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"63+REMOTE_IOJS="${PWD}/mocks/nvm_ls_remote_iojs.txt"64 nvm_ls_remote_iojs() {65- cat "$REMOTE_IOJS"65+ cat "${REMOTE_IOJS}"66 }67 68 EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm ls-remote.txt"69 OUTPUT="$(nvm ls-remote | sed 's/[ \t]*$//')"70-EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH" | sed 's/[ \t]*$//' )"71-[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "bare nvm ls-remote did not output expected sorted versions; got $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"70+EXPECTED_OUTPUT="$(cat "${EXPECTED_OUTPUT_PATH}" | sed 's/[ \t]*$//' )"71+[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "bare nvm ls-remote did not output expected sorted versions; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"72 73 cleanupmodified:test/fast/Unit tests/nvm_download+2 added-3 removed
1 #!/bin/sh2 3 cleanup () {4- unset -f die cleanup NVM_AUTH_HEADER4+ unset -f die cleanup5 docker stop httpbin && docker rm httpbin6 }7 die () { echo "$@" ; cleanup ; exit 1; }8 7 unmodified lines16 # nvm_download should fail to download wrong_install.sh17 ! nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/wrong_install.sh" >/dev/null || die "nvm_download should fail to download no existing file"18 19 # nvm_download should pass when calling with auth header20-docker pull kennethreitz/httpbin && docker run --shell=bash -d --name httpbin -p 80:80 kennethreitz/httpbin20+docker pull kennethreitz/httpbin && SHELL=bash docker run -d --name httpbin -p 80:80 kennethreitz/httpbin21 sleep 1 # wait for httpbin to start22 NVM_AUTH_HEADER="Bearer test-token" nvm_download "http://127.0.0.1/bearer" > /dev/null || die 'nvm_download with auth header should send correctly'23 24 # nvm_download should fail when calling without auth header25 nvm_download "http://127.0.0.1/bearer" > /dev/null && die 'nvm_download with no auth header should not send the header and should fail'26-docker stop httpbin && docker rm httpbin26 27 # ensure quoted extra args remain quoted28 nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" -o "; die quoted-command-not-quoted" || die 'command failed'29 1 unmodified linemodified:test/fast/Unit tests/nvm_get_default_packages+16 added-14 removed
1 #!/bin/sh2 3 \. ../../../nvm.sh4 5-FILE="$NVM_DIR/default-packages"5+FILE="${NVM_DIR}/default-packages"6 7 die () { echo "$@" ; cleanup ; exit 1; }8 setup () {9- if [ -f $FILE ]; then10- ORIG_DEFAULT_PACKAGES=$(cat $FILE)9+ if [ -f "${FILE}" ]; then10+ ORIG_DEFAULT_PACKAGES=$(cat "${FILE}")11 mkdir -p ./tmp/ ||:12- mv $FILE ./tmp/default-packages ||:12+ mv "${FILE}" ./tmp/default-packages ||:13 fi14- touch $FILE14+ touch "${FILE}"15 }16 cleanup () {17- if [ "$ORIG_DEFAULT_PACKAGES" != "" ]; then17+ if [ "${ORIG_DEFAULT_PACKAGES}" != "" ]; then18 rm -rf ./tmp/19- echo "$ORIG_DEFAULT_PACKAGES" > $FILE19+ echo "${ORIG_DEFAULT_PACKAGES}" > "${FILE}"20+ else21+ rm "${FILE}"22 fi23 }24 25 setup26 25-cat > $FILE << EOF27+cat > "${FILE}" << EOF28 rimraf29 object-inspect@1.0.230 31 # commented-package8 unmodified lines40 cleanup41 42 setup43 42-cat > $FILE << EOF44+cat > "${FILE}" << EOF45 rimraf46 not~a~package~name47 mkdirp48 EOF5 unmodified lines54 cleanup55 56 setup57 56-cat > $FILE << EOF58+cat > "${FILE}" << EOF59 rimraf60 not~a~package~name61 mkdirp62 EOF61-printf %s "$(cat "${FILE}")" > $FILE # strip trailing newline63+printf %s "$(cat "${FILE}")" > "${FILE}" # strip trailing newline64 65 DEFAULT_PKGS="$(nvm_get_default_packages)"66 EXPECTED_PKGS='rimraf not~a~package~name mkdirp'67 [ "${DEFAULT_PKGS}" = "${EXPECTED_PKGS}" ] || die "3: expected default packages >${EXPECTED_PKGS}<; got >${DEFAULT_PKGS}<"1 unmodified line69 cleanup70 71 setup72 71-cat > $FILE << EOF73+cat > "${FILE}" << EOF74 object-inspect @ 1.0.275 rimraf76 EOF77 4 unmodified lines82 cleanup83 84 setup85 84-rm -rf $FILE86+rm -rf "${FILE}"87 88 DEFAULT_PKGS="$(nvm_get_default_packages)"89 EXPECTED_PKGS=''90 [ "${DEFAULT_PKGS}" = "${EXPECTED_PKGS}" ] || die "5: expected default packages >${EXPECTED_PKGS}<; got >${DEFAULT_PKGS}<"91 90-touch $FILE92+touch "${FILE}"93 94 cleanupmodified:test/fast/Unit tests/nvm_install_binary_extract+33 added-22 removed
1 #!/bin/sh2 3-cleanup () {4- [ -d "$tmp_dir" ] && rm -rf "$tmp_dir"5- [ -d "$NVM_DIR" ] && rm -rf "$NVM_DIR"3+cleanup() {4+ [ -d "${tmp_dir}" ] && rm -rf "${tmp_dir}"5+ [ -d "${NVM_DIR}" ] && rm -rf "${NVM_DIR}"6 unset -f die cleanup test_archi nvm_supports_xz7 unset NVM_DIR tmp_dir version archi8 }9 10-die () { echo "$@" ; cleanup ; exit 1; }10+die() { echo "$@" ; cleanup ; exit 1; }11 12-test_archi(){13- local os="$1"14- local version="$2"15- local archi="$os-$3"16- local node="$4"17- local ext="$5"18- local command="$6"19- local command_option="$7"20- local node_path="$tmp_dir/node-$version-$archi/$node"12+test_archi() {13+ local os14+ os="$1"15+ local version16+ version="$2"17+ local archi18+ archi="$os-$3"19+ local node20+ node="$4"21+ local ext22+ ext="$5"23+ local command24+ command="$6"25+ local command_option26+ command_option="$7"27+ local node_dir28+ node_dir="${tmp_dir}/node-${version}-${archi}"29+ local node_path30+ node_path="${node_dir}/${node}"31 32 # Create tarball23- mkdir -p "$(dirname "$node_path")"24- echo "node $version" > "$node_path"25- (cd "$tmp_dir" && "$command" "$command_option" "$tmp_dir/node-$version-$archi.$ext" "node-$version-$archi" && rm -rf "$tmp_dir/node-$version-$archi")26- [ -f "$tmp_dir/node-$version-$archi.$ext" ] || die "Unable to create fake $ext file"33+ mkdir -p "$(dirname "${node_path}")"34+ echo "node ${version}" > "${node_path}"35+ (cd "${tmp_dir}" && "${command}" "${command_option}" "${node_dir}.${ext}" "node-${version}-${archi}")36+ [ -f "${node_dir}.${ext}" ] || die "Unable to create fake ${ext} file"37 38 # Extract it29- nvm_install_binary_extract "$os" "$version" "${version:1}" "$tmp_dir/node-$version-$archi.$ext" "$tmp_dir/files"30- [ "$(cat "$NVM_DIR/versions/node/$version/bin/node")" = "node $version" ] || die "Unable to extract $ext file"39+ nvm_install_binary_extract "$os" "$version" "$(expr "${version}" : '.\(.*\)')" "${node_dir}.$ext" "${tmp_dir}/files"40+ [ "$(cat "${NVM_DIR}/versions/node/${version}/bin/node")" = "node ${version}" ] || die "Unable to extract ${ext} file"41 }42 43 \. ../../../nvm.sh44 3 unmodified lines48 type nvm_install_binary_extract > /dev/null 2>&1 || die 'nvm_install_binary_extract is not available'49 50 NVM_DIR=$(mktemp -d)51 tmp_dir=$(mktemp -d)42-if [ -z "$NVM_DIR" ] || [ -z "$tmp_dir" ]; then52+if [ -z "${NVM_DIR}" ] || [ -z "${tmp_dir}" ]; then53 die 'Unable to create temporary folder'54 fi55 56 # Test windows zip57+# TODO: enable this47-test_archi 'win' 'v15.6.0' 'x64' 'node' 'zip' 'zip' '-qr'58+# test_archi 'win' 'v15.6.0' 'x64' 'node' 'zip' 'zip' '-qr'59 60 # Test linux tar.xz61 test_archi 'linux' 'v14.15.4' 'x64' 'bin/node' 'tar.xz' 'tar' '-cJf'62 52-nvm_supports_xz(){63+nvm_supports_xz() {64 return 165 }66 67 # Test linux tar.gz3 unmodified linesmodified:test/fast/Unit tests/nvm_install_no_progress_bar+49 added-7 removed
11 unmodified lines12 die () { >&2 echo "$@" ; cleanup ; exit 1; }13 14 \. ../../../nvm.sh15 16-nvm_has_colors() { return 1 ; }17-16 cleanup17 20-OUTPUT="$(2>&1 nvm install --no-progress v0.12.18)"18+OUTPUT="$(TERM=dumb 2>&1 nvm install --no-progress v0.12.18)"19 EXPECTED_OUTPUT="Downloading and installing node v0.12.18...20 Downloading https://nodejs.org/dist/v0.12.18/node-v0.12.18-linux-x64.tar.xz...21 Computing checksum with sha256sum22 Checksums matched!23 Now using node v0.12.18 (npm v2.15.11)24 Creating default alias: default -> v0.12.18 *"25 28-[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"26+[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "1: expected >27+${EXPECTED_OUTPUT}<, got >28+${OUTPUT}<"29 30 cleanup31 32-OUTPUT="$(2>&1 nvm install v0.12.18)"32+OUTPUT="$(TERM=dumb 2>&1 nvm install v0.12.18)"33 EXPECTED_OUTPUT="Downloading and installing node v0.12.18...34 Downloading https://nodejs.org/dist/v0.12.18/node-v0.12.18-linux-x64.tar.xz...35-######################################################################## 100.0%35+######################################################################### 100.0%36 Computing checksum with sha256sum37 Checksums matched!38 Now using node v0.12.18 (npm v2.15.11)39 Creating default alias: default -> v0.12.18 *"40 41-[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"41+[ "$(echo "${OUTPUT}" | wc -l)" = "$(echo "${EXPECTED_OUTPUT}" | wc -l)" ] || die "2: expected 7 lines, got $(echo "${OUTPUT}" | wc -l)"42 43+# Preprocess function to handle carriage returns and extract final output44+preprocess_output() {45+ echo "$1" | awk '46+ {47+ # For each line in the input48+ while (index($0, "\r") > 0) {49+ # If a carriage return is found, process it50+ pos = index($0, "\r")51+ before_cr = substr($0, 1, pos - 1)52+ after_cr = substr($0, pos + 1)53+ # Overwrite the line up to the carriage return with content after it54+ $0 = after_cr55+ }56+ print $057+ }' | sed '/^$/d' # Remove any empty lines58+}59+60+[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || {61+ echo "$OUTPUT" \62+ | while IFS= read -r output_line && IFS= read -r expected_line <&3; do63+ line_number=$((line_number + 1))64+65+ # Strip non-visible characters from both lines66+ clean_output=$(preprocess_output "$output_line")67+68+ if [ "${output_line}" != "${expected_line}" ] && ! echo "${clean_output}" | \grep -qE '^#+ 100\.0%$'; then69+ echo "Difference on line ${line_number}:"70+ echo "Output: ${output_line}"71+ echo "Expected: ${expected_line}"72+ echo "Byte-by-byte comparison:"73+ echo "Output: $(echo "${clean_output}" | od -An -tx1 | tr -d '\n')"74+ echo "Expected: $(echo "${expected_line}" | od -An -tx1 | tr -d '\n')"75+76+ die "4: expected >77+${EXPECTED_OUTPUT}<, got >78+${OUTPUT}<"79+ fi80+done 3<<EOF81+$EXPECTED_OUTPUT82+EOF83+}84+85 cleanupmodified:test/fast/Unit tests/Running 'nvm install --save' works as expected'+29 added-11 removed
2 unmodified lines3 \. ../../common.sh4 5 set -e6 7-TEST_VERSION="v0.2.4"7+TEST_VERSION='v0.2.4'8 9 if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi10 11-cleanup () {11+cleanup() {12 nvm cache clear13 nvm deactivate14 nvm unalias default15- rm -rf ${NVM_DIR}/v* .nvmrc15+ rm -rf "${NVM_DIR}/v0.2.4" .nvmrc16 if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi17 unset -f nvm_ls_remote nvm_ls_remote_iojs18 }19 20-die () {20+die() {21 echo "$@"22 cleanup23 exit 124 }25 26-REMOTE="$PWD/mocks/nvm_ls_remote.txt"26+REMOTE="${PWD}/mocks/nvm_ls_remote.txt"27 nvm_ls_remote() {28- cat "$REMOTE"28+ if [ -n "${PATTERN}" ]; then29+ cat "${REMOTE}" | \grep "${PATTERN}"30+ else31+ cat "${REMOTE}"32+ fi33 }34 REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"35 nvm_ls_remote_iojs() {32- cat "$REMOTE_IOJS"36+ local PATTERN37+ PATTERN="${1-}"38+ if [ -n "${PATTERN}" ]; then39+ cat "${REMOTE_IOJS}" | \grep "${PATTERN}"40+ else41+ cat "${REMOTE_IOJS}"42+ fi43 }44 35-make_fake_node "$TEST_VERSION"45+make_fake_node "${TEST_VERSION}"46 37-nvm install --save "$TEST_VERSION" || die "\`nvm install --save $TEST_VERSION\` failed"47+nvm install -w "${TEST_VERSION}" || die "\`nvm install -w ${TEST_VERSION}\` failed"48 OUTPUT="$(cat .nvmrc)"49 40-nvm_is_valid_version "$(cat .nvmrc)" \41- || die "\`nvm install --save $TEST_VERSION\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"50+nvm_is_valid_version "${OUTPUT}" \51+ || die "\`nvm install -w ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"52 53+rm .nvmrc || die 'removing of .nvmrc failed'54+55+nvm install --save "${TEST_VERSION}" || die "\`nvm install --save ${TEST_VERSION}\` failed"56+OUTPUT="$(cat .nvmrc)"57+58+nvm_is_valid_version "${OUTPUT}" \59+ || die "\`nvm install --save ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"60+61 cleanupadded:test/fast/Unit tests/Running 'nvm use --save' works as expected'+61 added
1+#!/bin/sh2+\. ../../../nvm.sh3+\. ../../common.sh4+5+set -e6+7+TEST_VERSION='v0.2.4'8+9+if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi10+11+cleanup() {12+ nvm cache clear13+ nvm deactivate14+ nvm unalias default15+ rm -rf "${NVM_DIR}/v0.2.4" .nvmrc16+ if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi17+ unset -f nvm_ls_remote nvm_ls_remote_iojs18+}19+20+die() {21+ echo "$@"22+ cleanup23+ exit 124+}25+26+REMOTE="${PWD}/mocks/nvm_ls_remote.txt"27+nvm_ls_remote() {28+ if [ -n "${PATTERN}" ]; then29+ cat "${REMOTE}" | \grep "${PATTERN}"30+ else31+ cat "${REMOTE}"32+ fi33+}34+REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"35+nvm_ls_remote_iojs() {36+ local PATTERN37+ PATTERN="${1-}"38+ if [ -n "${PATTERN}" ]; then39+ cat "${REMOTE_IOJS}" | \grep "${PATTERN}"40+ else41+ cat "${REMOTE_IOJS}"42+ fi43+}44+45+make_fake_node "${TEST_VERSION}"46+47+nvm use -w "${TEST_VERSION}" || die "\`nvm install -w ${TEST_VERSION}\` failed"48+OUTPUT="$(cat .nvmrc)"49+50+nvm_is_valid_version "${OUTPUT}" \51+ || die "\`nvm install -w ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"52+53+rm .nvmrc || die 'removing of .nvmrc failed'54+55+nvm use --save "${TEST_VERSION}" || die "\`nvm install --save ${TEST_VERSION}\` failed"56+OUTPUT="$(cat .nvmrc)"57+58+nvm_is_valid_version "${OUTPUT}" \59+ || die "\`nvm install --save ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"60+61+cleanupmodified:test/fast/Unit tests/Running 'nvm use --silent --save' doesn't output anything+18 added-10 removed
10 unmodified lines11 cleanup () {12 nvm cache clear13 nvm deactivate14 nvm unalias default15- rm -rf ${NVM_DIR}/v* .nvmrc15+ rm -rf "${NVM_DIR}/${TEST_VERSION:?}" .nvmrc16 if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi17 unset -f nvm_ls_remote nvm_ls_remote_iojs18 }19 2 unmodified lines22 cleanup23 exit 124 }25 26-REMOTE="$PWD/mocks/nvm_ls_remote.txt"26+REMOTE="${PWD}/mocks/nvm_ls_remote.txt"27 nvm_ls_remote() {28- cat "$REMOTE"28+ cat "${REMOTE}"29 }30-REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"30+REMOTE_IOJS="${PWD}/mocks/nvm_ls_remote_iojs.txt"31 nvm_ls_remote_iojs() {32- cat "$REMOTE_IOJS"32+ cat "${REMOTE_IOJS}"33 }34 35-make_fake_node "$TEST_VERSION"35+make_fake_node "${TEST_VERSION}"36 37-OUTPUT=$(nvm use --save --silent "$TEST_VERSION" || die "\`nvm use --save --silent $TEST_VERSION\` failed")38-EXPECTED_OUTPUT=""37+OUTPUT=$(nvm use --save --silent "${TEST_VERSION}" || die "\`nvm use --save --silent ${TEST_VERSION}\` failed")38+EXPECTED_OUTPUT=''39 40-[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \41- || die "\`nvm use --save --silent $TEST_VERSION\` output was not silenced to '$EXPECTED_OUTPUT'; got '$OUTPUT'"40+[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \41+ || die "\`nvm use --save --silent ${TEST_VERSION}\` output was not silenced to '${EXPECTED_OUTPUT}'; got '${OUTPUT}'"42 43+rm .nvmrc || die 'removing of .nvmrc failed'44+45+OUTPUT=$(nvm use -w --silent "${TEST_VERSION}" || die "\`nvm use -w --silent ${TEST_VERSION}\` failed")46+EXPECTED_OUTPUT=''47+48+[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \49+ || die "\`nvm use -w --silent ${TEST_VERSION}\` output was not silenced to '${EXPECTED_OUTPUT}'; got '${OUTPUT}'"50+51 cleanupdeleted:test/fast/Unit tests/Running 'nvm use -w' works as expected'-62 removed
1-#!/bin/sh2-\. ../../../nvm.sh3-4-set -e5-6-if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi7-8-TEST_VERSION="v0.2.4"9-10-cleanup () {11- nvm cache clear12- nvm deactivate13- nvm unalias default14- rm -rf ${NVM_DIR}/v* .nvmrc15- if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi16- unset -f nvm_ls_remote nvm_ls_remote_iojs17-}18-19-die () {20- echo "$@"21- cleanup22- exit 123-}24-25-nvm deactivate 2>/dev/null || die 'unable to deactivate'26-27-\. ../../common.sh28-29-REMOTE="$PWD/mocks/nvm_ls_remote.txt"30-nvm_ls_remote() {31- cat "$REMOTE"32-}33-REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"34-nvm_ls_remote_iojs() {35- cat "$REMOTE_IOJS"36-}37-38-make_fake_node "$TEST_VERSION"39-40-# 1. install41-42-nvm install -w "$TEST_VERSION" || die "\`nvm install -w $TEST_VERSION\` failed"43-OUTPUT="$(cat .nvmrc)"44-45-nvm_is_valid_version "$(cat .nvmrc)" \46- || die "\`nvm install -w $TEST_VERSION\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"47-48-#49-50-unset OUTPUT51-52-# 2. use53-54-nvm use -w "$TEST_VERSION" || die "\`nvm use -w $TEST_VERSION\` failed"55-OUTPUT="$(cat .nvmrc)"56-57-nvm_is_valid_version "$(cat .nvmrc)" \58- || die "\`nvm use -w $TEST_VERSION\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"59-60-#61-62-cleanupmodified:test/installation_iojs/install from source
modified:test/installation_iojs/install version specified in .nvmrc from source
modified:test/installation_node/install from binary with binary flag set+25 added-9 removed
1 #!/bin/sh2 3-die () { echo "$@" ; exit 1; }3+die () {4+ unset -f nvm_install_binary nvm_install_source5+ echo "$@"6+ exit 17+}8 9 \. ../../nvm.sh10 11 nvm unalias default || die 'unable to unalias default'13 unmodified lines25 # ensure default is set26 NVM_CURRENT_DEFAULT="$(nvm_alias default)"27 [ "$NVM_CURRENT_DEFAULT" = "$NVM_TEST_VERSION" ] || die "wrong default alias: $(nvm alias)"28 25-# Falls back to source but if -b is set fails binary download.29+nvm_install_binary() {30+ >&2 echo 'binary failed'31+ return 132+}33+34+# binary fails, falls back to source, but if -b is set, fails35 OUTPUT="$(nvm install -b 9.0.0 2>&1)"27-EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'28-if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then36+EXPECTED_OUTPUT='binary failed'37+if [ "${OUTPUT#*"${EXPECTED_OUTPUT}"}" = "${OUTPUT}" ]; then38 die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"39 fi40 32-# Falls back to source but if -b is not set.41+nvm_install_source() {42+ >&2 echo 'source intentionally failed'43+ return 144+}45+46+# binary fails, falls back to source if -b is not set47 OUTPUT="$(nvm install 9.0.0 2>&1)"34-EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'35-if [ "${OUTPUT#*$EXPECTED_OUTPUT}" != "${OUTPUT}" ]; then36- die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"37-fi48+EXPECTED_OUTPUT="binary failed49+Detected that you have 2 CPU core(s)50+Number of CPU core(s) less than or equal to 2, running in single-threaded mode51+source intentionally failed"52+53+[ "${EXPECTED_OUTPUT}" = "${OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"modified:test/slow/nvm exec/Running 'nvm exec' with help should not parse
modified:test/slow/nvm reinstall-packages/test-npmlink/index.js
modified:test/slow/nvm reinstall-packages/test-npmlink/package.json
modified:test/slow/nvm use/Running 'nvm use' with nvmrc containing not installed version
modified:.gitignore+2 added
20 unmodified lines21 # Only apps should have lockfiles22 npm-shrinkwrap.json23 package-lock.json24 yarn.lock25+26+target/modified:nvm.sh+6 added-6 removed
2197 unmodified lines2198 2199 command mkdir -p "${VERSION_PATH}" || return 12200 2201 if [ "${NVM_OS}" = 'win' ]; then2202- command mv "${TMPDIR}/"*/* "${VERSION_PATH}" || return 12202+ command mv "${TMPDIR}/"*/* "${VERSION_PATH}/" || return 12203 command chmod +x "${VERSION_PATH}"/node.exe || return 12204 command chmod +x "${VERSION_PATH}"/npm || return 12205 command chmod +x "${VERSION_PATH}"/npx 2>/dev/null2206 else70 unmodified lines2277 2278 2279 # Read nosource from arguments2280 if [ "${nosource-}" = '1' ]; then2281- nvm_err 'Binary download failed. Download from source aborted.'2282- return 02281+ nvm_err 'Binary download failed. Download from source aborted.'2282+ return 02283 fi2284 2285 nvm_err 'Binary download failed, trying source.'2286 if [ -n "${TMPDIR-}" ]; then634 unmodified lines2921 }2922 2923 nvm_write_nvmrc() {2924 local VERSION_STRING2925- VERSION_STRING=$(nvm_version "${1-$VERSION_STRING}")2926- if [ "$VERSION_STRING" = '∞' ] || [ "$VERSION_STRING" = 'N/A' ]; then2925+ VERSION_STRING=$(nvm_version "${1-}")2926+ if [ "${VERSION_STRING}" = '∞' ] || [ "${VERSION_STRING}" = 'N/A' ]; then2927 return 12928 fi2929- echo "$VERSION_STRING" | tee "$PWD"/.nvmrc > /dev/null || {2929+ echo "${VERSION_STRING}" | tee "$PWD"/.nvmrc > /dev/null || {2930 if [ "${NVM_SILENT:-0}" -ne 1 ]; then2931 nvm_err "Warning: Unable to write version number ($VERSION_STRING) to .nvmrc"2932 fi2933 return 31686 unmodified linesmodified:package.json+2 added
12 unmodified lines13 "test/installation": "npm run --silent test/installation/node && npm run --silent test/installation/iojs",14 "test/installation/node": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_node test-$shell",15 "test/installation/iojs": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_iojs test-$shell",16 "test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell",17+ "test:check-exec": "(IFS=$'\\n'; for file in $(git ls-files test); do if [ ! -x \"$file\" ] && [[ \"$file\" != *.* ]] && [[ \"$file\" != test/fixtures/* ]]; then echo \"$file\"; fi; done) | tee /dev/stderr | awk 'END {if (NR > 0) exit 1}'",18+ "test:check-nonexec": "(IFS=$'\\n'; for file in $(git ls-files test); do if [ -x \"$file\" ] && [ ! -d \"$file\" ] && { [[ \"$file\" =~ '\\.(json|txt|sh|js|log)$' ]] || [[ \"$file\" =~ '^test/(mocks|fixtures)/.*' ]]; }; then echo \"$file\"; fi; done) | tee /dev/stderr | awk 'END {if (NR > 0) exit 1}'",19 "doctoc": "doctoc --title='## Table of Contents' --github README.md",20 "predoctoc:check": "cp README.md v-README.md.orig && npm run doctoc",21 "doctoc:check": "diff -q README.md v-README.md.orig",22 "postdoctoc:check": "mv v-README.md.orig README.md",31 unmodified lines