mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-04-03 11:34:50 +08:00
Add `try` and `try_err` helper functions to `test/common.sh` that capture stdout/stderr and exit code from a single invocation, eliminating duplicate command executions in tests. Convert all existing tests that used the `OUTPUT`/`EXIT_CODE` double-invocation pattern to use the new helpers. Also fixes a pre-existing bug in the `nvm_die_on_prefix` test where ASCII apostrophes were used instead of U+2019 to match nvm.sh output.
46 lines
1.1 KiB
Bash
Executable File
46 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
set -ex
|
|
|
|
cleanup () {
|
|
unset -f nvm_download nvm_get_checksum_alg nvm_get_mirror
|
|
}
|
|
die () { echo "$@" ; cleanup ; exit 1; }
|
|
|
|
set +e # TODO: fix
|
|
: nvm.sh
|
|
\. ../../../nvm.sh
|
|
set -e
|
|
|
|
\. ../../common.sh
|
|
|
|
nvm_get_mirror() {
|
|
echo "mirror-${1}-${2}"
|
|
}
|
|
|
|
try_err nvm_get_checksum
|
|
EXPECTED_OUTPUT='supported flavors: node, iojs'
|
|
[ "${CAPTURED_STDERR}" = "${EXPECTED_OUTPUT}" ] || die "expected error output >${EXPECTED_OUTPUT}<, got >${CAPTURED_STDERR}<"
|
|
[ "${CAPTURED_EXIT_CODE}" = 2 ] || die "expected exit code 2, got ${CAPTURED_EXIT_CODE}"
|
|
|
|
nvm_download() {
|
|
echo "ERROR_FAILED_MATCH no_match more fields"
|
|
echo "${3} bar.tar.baz more fields"
|
|
}
|
|
|
|
nvm_get_checksum_alg() {
|
|
echo 'sha-256'
|
|
}
|
|
OUTPUT="$(nvm_get_checksum node std foo bar tar.baz)"
|
|
EXPECTED_OUTPUT="mirror-node-std/foo/SHASUMS256.txt"
|
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"
|
|
|
|
nvm_get_checksum_alg() {
|
|
echo 'sha-1'
|
|
}
|
|
OUTPUT="$(nvm_get_checksum iojs std foo bar tar.baz)"
|
|
EXPECTED_OUTPUT="mirror-iojs-std/foo/SHASUMS.txt"
|
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"
|
|
|
|
cleanup
|