Files
nvm/test/fast/Unit tests/nvm_get_checksum
Jordan Harband 14d01c6877 [Tests] add try/try_err helpers; convert tests to use them
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.
2026-03-13 15:26:07 -04:00

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