Files
nvm/test/fast/Unit tests/nvm_ls_remote_iojs
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

40 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
die () { echo "$@" ; cleanup ; exit 1; }
cleanup() {
unset -f nvm_download
}
: nvm.sh
\. ../../../nvm.sh
# sample output at the time the test was written
TAB_PATH="$PWD/mocks/iojs.org-dist-index.tab"
nvm_download() {
cat "$TAB_PATH"
}
EXPECTED_OUTPUT_PATH="$PWD/mocks/nvm_ls_remote_iojs.txt"
\. ../../common.sh
try nvm_ls_remote_iojs foo
[ "_$CAPTURED_STDOUT" = "_N/A" ] || die "nonexistent version did not report N/A"
[ "_$CAPTURED_EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $CAPTURED_EXIT_CODE"
OUTPUT="$(nvm_ls_remote_iojs)"
EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH")"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "bare nvm_ls_remote_iojs did not output expected sorted versions; got $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"
OUTPUT="$(nvm_ls_remote_iojs 1.0)"
EXPECTED_OUTPUT="iojs-v1.0.0
iojs-v1.0.1
iojs-v1.0.2
iojs-v1.0.3
iojs-v1.0.4"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote_iojs 1.0 did not output 1.0.x versions; got $OUTPUT"
cleanup