The duplicate-key check kept keys in a space-separated list, so a key such as `a b` followed by a key `a` or `b` was reported as a duplicate, unlike in the `nvmrc` package. Keep the keys newline-separated, since a key cannot contain a newline.
44 lines
1.4 KiB
Bash
Executable File
44 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
die () { echo "$@" ; exit 1; }
|
|
|
|
: nvm.sh
|
|
\. ../../../nvm.sh
|
|
|
|
\. ../../common.sh
|
|
|
|
for KEY in a a.b 'a*' '(' '[' 'a\' 'a b'; do
|
|
CONTENT="20
|
|
${KEY}=1
|
|
other=2
|
|
${KEY} = 3"
|
|
|
|
try_err nvm_process_nvmrc_content "${CONTENT}"
|
|
[ "${CAPTURED_EXIT_CODE}" = 1 ] || die "expected a duplicate key \`${KEY}\` to be invalid; got exit code ${CAPTURED_EXIT_CODE}"
|
|
case "${CAPTURED_STDERR}" in
|
|
*'invalid .nvmrc!'*) ;;
|
|
*) die "expected the invalid .nvmrc message for a duplicate key \`${KEY}\`; got >${CAPTURED_STDERR}<" ;;
|
|
esac
|
|
|
|
try nvm_process_nvmrc_content "${CONTENT}"
|
|
[ -z "${CAPTURED_STDOUT}" ] || die "expected no version for a duplicate key \`${KEY}\`; got \`${CAPTURED_STDOUT}\`"
|
|
done
|
|
|
|
# keys are compared as they are written, not as patterns
|
|
for KEY in b ab A a. '*' '.*' '?' 'a|b' '[a]' 'a b' 'b a' 'b a'; do
|
|
for CONTENT in "20
|
|
a=1
|
|
${KEY}=2" "20
|
|
${KEY}=1
|
|
a=2"; do
|
|
try_err nvm_process_nvmrc_content "${CONTENT}"
|
|
[ "${CAPTURED_EXIT_CODE}" = 0 ] || die "expected the keys \`a\` and \`${KEY}\` to be distinct; got exit code ${CAPTURED_EXIT_CODE}"
|
|
case "${CAPTURED_STDERR}" in
|
|
*'invalid .nvmrc!'*) die "expected no error for the keys \`a\` and \`${KEY}\`; got >${CAPTURED_STDERR}<" ;;
|
|
esac
|
|
|
|
try nvm_process_nvmrc_content "${CONTENT}"
|
|
[ "${CAPTURED_STDOUT}" = '20' ] || die "expected \`20\` with the keys \`a\` and \`${KEY}\`; got \`${CAPTURED_STDOUT}\`"
|
|
done
|
|
done
|