[Fix] default_packages: work when the file lacks a trailing newline

Fixes #1995.
This commit is contained in:
Jordan Harband
2019-02-02 13:45:11 -08:00
parent 5c117e6ab3
commit db19450caa
3 changed files with 33 additions and 4 deletions

View File

@@ -52,6 +52,21 @@ cleanup
setup
cat > $FILE << EOF
rimraf
not~a~package~name
mkdirp
EOF
printf %s "$(cat "${FILE}")" > $FILE # strip trailing newline
DEFAULT_PKGS="$(nvm_get_default_packages)"
EXPECTED_PKGS='rimraf not~a~package~name mkdirp'
[ "${DEFAULT_PKGS}" = "${EXPECTED_PKGS}" ] || die "3: expected default packages >${EXPECTED_PKGS}<; got >${DEFAULT_PKGS}<"
cleanup
setup
cat > $FILE << EOF
object-inspect @ 1.0.2
rimraf
@@ -59,7 +74,7 @@ EOF
DEFAULT_PKGS="$(nvm_get_default_packages 2>&1 >/dev/null)"
EXPECTED_PKGS="Only one package per line is allowed in the $FILE file. Please remove any lines with multiple space-separated values."
[ "${DEFAULT_PKGS}" = "${EXPECTED_PKGS}" ] || die "3: expected default packages >${EXPECTED_PKGS}<; got >${DEFAULT_PKGS}<"
[ "${DEFAULT_PKGS}" = "${EXPECTED_PKGS}" ] || die "4: expected default packages >${EXPECTED_PKGS}<; got >${DEFAULT_PKGS}<"
cleanup
@@ -69,7 +84,7 @@ rm -rf $FILE
DEFAULT_PKGS="$(nvm_get_default_packages)"
EXPECTED_PKGS=''
[ "${DEFAULT_PKGS}" = "${EXPECTED_PKGS}" ] || die "4: expected default packages >${EXPECTED_PKGS}<; got >${DEFAULT_PKGS}<"
[ "${DEFAULT_PKGS}" = "${EXPECTED_PKGS}" ] || die "5: expected default packages >${EXPECTED_PKGS}<; got >${DEFAULT_PKGS}<"
touch $FILE

View File

@@ -30,8 +30,11 @@ object-inspect@1.0.2
# commented-package
stevemao/left-pad
daytime
EOF
printf %s "$(cat "${FILE}")" > $FILE # strip trailing newline
nvm install v6.10.1 2>&1
EXIT_CODE=$?
[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm install v6.10.1' to exit with 0, got $EXIT_CODE"
@@ -41,6 +44,11 @@ if [ -z "$?" ]; then
die "expected 'nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'rimraf'' to exit with 0, got $?"
fi
nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'daytime'
if [ -z "$?" ]; then
die "expected 'nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'daytime'' to exit with 0, got $?"
fi
cleanup
setup