mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-04-04 03:54:51 +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.
29 lines
1.3 KiB
Bash
Executable File
29 lines
1.3 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
die () { echo "$@" ; exit 1; }
|
|
|
|
: nvm.sh
|
|
\. ../../../nvm.sh
|
|
|
|
\. ../../common.sh
|
|
|
|
EXPECTED_FIRST_MSG="nvm_print_implicit_alias must be specified with local or remote as the first argument."
|
|
[ "_$(nvm_print_implicit_alias 2>&1)" = "_$EXPECTED_FIRST_MSG" ] \
|
|
|| die "nvm_print_implicit_alias did not require local|remote as first argument"
|
|
[ "_$(nvm_print_implicit_alias foo 2>&1)" = "_$EXPECTED_FIRST_MSG" ] \
|
|
|| die "nvm_print_implicit_alias did not require local|remote as first argument"
|
|
|
|
try_err nvm_print_implicit_alias
|
|
[ "_$CAPTURED_EXIT_CODE" = "_1" ] \
|
|
|| die "nvm_print_implicit_alias without local|remote had wrong exit code: expected 1, got $CAPTURED_EXIT_CODE"
|
|
|
|
EXPECTED_SECOND_MSG="Only implicit aliases 'stable', 'unstable', 'iojs', and 'node' are supported."
|
|
[ "_$(nvm_print_implicit_alias local 2>&1)" = "_$EXPECTED_SECOND_MSG" ] \
|
|
|| die "nvm_print_implicit_alias did not require stable|unstable|iojs|node as second argument"
|
|
[ "_$(nvm_print_implicit_alias local foo 2>&1)" = "_$EXPECTED_SECOND_MSG" ] \
|
|
|| die "nvm_print_implicit_alias did not require stable|unstable|iojs|node as second argument"
|
|
|
|
try_err nvm_print_implicit_alias local
|
|
[ "_$CAPTURED_EXIT_CODE" = "_2" ] \
|
|
|| die "nvm_print_implicit_alias without stable|unstable|iojs|node had wrong exit code: expected 2, got $CAPTURED_EXIT_CODE"
|