From 79169a834f9860284af203bf2c40e5143c119ef7 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 23 Oct 2023 14:06:19 -0700 Subject: [PATCH] [New] aliases: skip leading blank lines in alias file --- nvm.sh | 2 +- ...uld ignore leading blank lines in the file | 20 +++++++++++++++++++ test/fast/Aliases/teardown | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 test/fast/Aliases/'nvm alias' should ignore leading blank lines in the file diff --git a/nvm.sh b/nvm.sh index 0b57f05714..bee8456f81 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1141,7 +1141,7 @@ nvm_alias() { return 2 fi - command cat "${NVM_ALIAS_PATH}" + command awk 'NF' "${NVM_ALIAS_PATH}" } nvm_ls_current() { diff --git a/test/fast/Aliases/'nvm alias' should ignore leading blank lines in the file b/test/fast/Aliases/'nvm alias' should ignore leading blank lines in the file new file mode 100755 index 0000000000..3fe5784ba3 --- /dev/null +++ b/test/fast/Aliases/'nvm alias' should ignore leading blank lines in the file @@ -0,0 +1,20 @@ +#!/bin/sh + +die() { echo "$@" ; exit 1; } + +export NVM_DIR="$(cd ../../.. && pwd)" + +\. "${NVM_DIR}/nvm.sh" +\. ../../common.sh + +echo " + +v0.0.1 +" > ../../../alias/test-blank-lines + +EXPECTED='v0.0.1' +ACTUAL="$(nvm_alias test-blank-lines)" +EXIT_CODE="$(nvm_alias test-blank-lines 2>&1 >/dev/null; echo $?)" + +[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" +[ "${EXIT_CODE}" = '0' ] || die "expected exit code 0, got ${EXIT_CODE}" diff --git a/test/fast/Aliases/teardown b/test/fast/Aliases/teardown index 005c7296d8..33e1b02470 100755 --- a/test/fast/Aliases/teardown +++ b/test/fast/Aliases/teardown @@ -15,3 +15,4 @@ rm -f "../../../alias/unstable" rm -f "../../../alias/node" rm -f "../../../alias/iojs" rm -f "../../../alias/default" +rm -f "../../../alias/test-blank-lines"