From e2ff1e7f088d260af7a810f4c522949132518d68 Mon Sep 17 00:00:00 2001 From: Bark Date: Wed, 6 Mar 2024 16:03:10 +0200 Subject: [PATCH 1/6] fix: Do a version check on `nvm-exec` This check would display a message in case the `.nvmrc` version is not installed, and would not alter the output otherwise. --- nvm-exec | 1 + 1 file changed, 1 insertion(+) diff --git a/nvm-exec b/nvm-exec index 44d5ddb116..c082f8fb2b 100755 --- a/nvm-exec +++ b/nvm-exec @@ -7,6 +7,7 @@ unset NVM_CD_FLAGS # shellcheck disable=SC1090,SC1091 \. "$DIR/nvm.sh" --no-use +nvm_rc_version > /dev/null && nvm_ensure_version_installed "$NVM_RC_VERSION"; if [ -n "$NODE_VERSION" ]; then nvm use "$NODE_VERSION" > /dev/null || exit 127 elif ! nvm use >/dev/null 2>&1; then From 05feeaa92709eb89ab0184808d4e634a1230d720 Mon Sep 17 00:00:00 2001 From: Bark Date: Wed, 6 Mar 2024 16:03:10 +0200 Subject: [PATCH 2/6] [Fix] `nvm exec`: Do a version check on `nvm-exec` This check would display a message in case the `.nvmrc` version is not installed, and would not alter the output otherwise. --- nvm-exec | 1 + ...-exec' should display required node version | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100755 test/fast/Running 'nvm-exec' should display required node version diff --git a/nvm-exec b/nvm-exec index 44d5ddb116..c082f8fb2b 100755 --- a/nvm-exec +++ b/nvm-exec @@ -7,6 +7,7 @@ unset NVM_CD_FLAGS # shellcheck disable=SC1090,SC1091 \. "$DIR/nvm.sh" --no-use +nvm_rc_version > /dev/null && nvm_ensure_version_installed "$NVM_RC_VERSION"; if [ -n "$NODE_VERSION" ]; then nvm use "$NODE_VERSION" > /dev/null || exit 127 elif ! nvm use >/dev/null 2>&1; then diff --git a/test/fast/Running 'nvm-exec' should display required node version b/test/fast/Running 'nvm-exec' should display required node version new file mode 100755 index 0000000000..df5ace7087 --- /dev/null +++ b/test/fast/Running 'nvm-exec' should display required node version @@ -0,0 +1,18 @@ +#!/bin/bash + +set -x +\. ../../nvm.sh + +NVM_TEST_VERSION=v0.42 + +# Write it to nvmrc +echo "$NVM_TEST_VERSION" > .nvmrc + +OUTPUT="$(../../nvm-exec 2>&1)"; +EXPECTED="N/A: version \"${NVM_TEST_VERSION}\" is not yet installed. + +You need to run \`nvm install ${NVM_TEST_VERSION}\` to install and use it. +No NODE_VERSION provided; no .nvmrc file found"; + +# Skip install, we want to test the error message +diff <(echo "${EXPECTED}") <(echo "${OUTPUT}") From 5a28180ed6072b892bc2dc342c5c08a33c93121f Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Tue, 30 Jul 2024 11:51:32 +0300 Subject: [PATCH 3/6] tests: Add test to check if the message contains the relevant information. --- ...vm-exec' should display required node version | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/slow/Running 'nvm-exec' should display required node version diff --git a/test/slow/Running 'nvm-exec' should display required node version b/test/slow/Running 'nvm-exec' should display required node version new file mode 100644 index 0000000000..53b149b7f2 --- /dev/null +++ b/test/slow/Running 'nvm-exec' should display required node version @@ -0,0 +1,16 @@ +#!/bin/sh + +set -ex +die () { echo "$@" ; exit 1; } +\. ../../../nvm.sh + +NVM_TEST_VERSION=v9 + +# Remove the stuff we're clobbering. +[ -e ../../$NVM_TEST_VERSION ] && rm -R ../../$NVM_TEST_VERSION + +# Write it to nvmrc +echo "$NVM_TEST_VERSION" > .nvmrc + +# Skip install, we want to test the error message +nvm-exec From 650b069bb83c0d704cb48e2a59468a021d7cdcd8 Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Tue, 30 Jul 2024 11:56:35 +0300 Subject: [PATCH 4/6] Seems changes done in docker do not persist, had to reapply them --- ...'nvm-exec' should display required node version | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/slow/Running 'nvm-exec' should display required node version b/test/slow/Running 'nvm-exec' should display required node version index 53b149b7f2..8c91cf7e2a 100644 --- a/test/slow/Running 'nvm-exec' should display required node version +++ b/test/slow/Running 'nvm-exec' should display required node version @@ -1,8 +1,7 @@ -#!/bin/sh +#!/bin/bash -set -ex -die () { echo "$@" ; exit 1; } -\. ../../../nvm.sh +set -x +\. ../../nvm.sh NVM_TEST_VERSION=v9 @@ -12,5 +11,10 @@ NVM_TEST_VERSION=v9 # Write it to nvmrc echo "$NVM_TEST_VERSION" > .nvmrc +output="$(../../nvm-exec 2>&1)"; +expected='N/A: version "v9" is not yet installed. + +You need to run `nvm install v9` to install and use it. +No NODE_VERSION provided; no .nvmrc file found'; # Skip install, we want to test the error message -nvm-exec +diff <(echo "$expected") <(echo "$output") From 59b40b8ae743080e6b37571513d54039b063a8a5 Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Wed, 31 Jul 2024 16:42:03 +0300 Subject: [PATCH 5/6] Rookie mistake from my side, forgot to clean-up the nvmrc, which caused other tests to fail. Updated version color printing test because it did not pass. --- ...unning 'nvm-exec' should display required node version | 1 + .../Set Colors/nvm_print_versions calls nvm_get_colors | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test/fast/Running 'nvm-exec' should display required node version b/test/fast/Running 'nvm-exec' should display required node version index df5ace7087..25c9a0de07 100755 --- a/test/fast/Running 'nvm-exec' should display required node version +++ b/test/fast/Running 'nvm-exec' should display required node version @@ -16,3 +16,4 @@ No NODE_VERSION provided; no .nvmrc file found"; # Skip install, we want to test the error message diff <(echo "${EXPECTED}") <(echo "${OUTPUT}") +rm .nvmrc diff --git a/test/fast/Set Colors/nvm_print_versions calls nvm_get_colors b/test/fast/Set Colors/nvm_print_versions calls nvm_get_colors index 55e2334993..b54d2300ba 100755 --- a/test/fast/Set Colors/nvm_print_versions calls nvm_get_colors +++ b/test/fast/Set Colors/nvm_print_versions calls nvm_get_colors @@ -2,7 +2,7 @@ \. ../../../nvm.sh -set -e +#set -e #nvm use system returns 127 and No system set message die () { # echo "$@" ; @@ -24,7 +24,7 @@ fi # default system color nvm use system OUTPUT=$(nvm_print_versions system) -FORMAT="\033[0;32m-> %12s\033[0m" +FORMAT="\033[0;33m%15s\033[0m" VERSION='system' EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}") @@ -34,7 +34,7 @@ nvm_ls_current() { echo "current";} # default current color OUTPUT=$(nvm_print_versions current) -FORMAT="\033[0;32m-> %12s\033[0m" +FORMAT="\033[0;32m->%13s\033[0m" VERSION="current" EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}") @@ -43,7 +43,7 @@ EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}") # custom current color nvm set-colors YCMGR OUTPUT=$(nvm_print_versions current) -FORMAT="\033[1;35m-> %12s\033[0m" +FORMAT="\033[1;35m->%13s\033[0m" VERSION="current" EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}") From 8066dc851168cd13a7b116244ba0ca105add1f8c Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Wed, 31 Jul 2024 16:44:25 +0300 Subject: [PATCH 6/6] remove test from slow folder --- ...exec' should display required node version | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 test/slow/Running 'nvm-exec' should display required node version diff --git a/test/slow/Running 'nvm-exec' should display required node version b/test/slow/Running 'nvm-exec' should display required node version deleted file mode 100644 index 8c91cf7e2a..0000000000 --- a/test/slow/Running 'nvm-exec' should display required node version +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -set -x -\. ../../nvm.sh - -NVM_TEST_VERSION=v9 - -# Remove the stuff we're clobbering. -[ -e ../../$NVM_TEST_VERSION ] && rm -R ../../$NVM_TEST_VERSION - -# Write it to nvmrc -echo "$NVM_TEST_VERSION" > .nvmrc - -output="$(../../nvm-exec 2>&1)"; -expected='N/A: version "v9" is not yet installed. - -You need to run `nvm install v9` to install and use it. -No NODE_VERSION provided; no .nvmrc file found'; -# Skip install, we want to test the error message -diff <(echo "$expected") <(echo "$output")