nvm_remote_version
This file
Path
test/fast/Unit tests/nvm_remote_version
91 lines · 3.6 KiB
Last changed by
[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6
History of this fileTake it
1#!/bin/sh23die () { echo "$@" ; cleanup ; exit 1; }45cleanup() {6 unset -f nvm_ls_remote nvm_ls_remote_iojs7}89: nvm.sh10\. ../../../nvm.sh1112\. ../../common.sh1314nvm_ls_remote() {15 echo "N/A"16}17try nvm_remote_version foo18[ "_$CAPTURED_STDOUT" = "_N/A" ] || die "nonexistent version did not report N/A"19[ "_$CAPTURED_EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $CAPTURED_EXIT_CODE"2021nvm_ls_remote_iojs() {22 echo "N/A"23}24try nvm_remote_version iojs-foo25[ "_$CAPTURED_STDOUT" = "_N/A" ] || die "nonexistent version did not report N/A"26[ "_$CAPTURED_EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $CAPTURED_EXIT_CODE"272829nvm_ls_remote() {30 if [ -z "$1" ] || ! nvm_is_iojs_version "$1"; then31 echo "test_output"32 echo "more_test_output"33 echo "pattern_received:_$1_"34 fi35}36nvm_ls_remote_iojs() {37 if [ -z "$1" ] || nvm_is_iojs_version "$1"; then38 echo "test_iojs_output"39 echo "more_iojs_test_output"40 echo "iojs_pattern_received:_$1_"41 fi42}43try nvm_remote_version foo44[ "_$CAPTURED_STDOUT" = "_pattern_received:_foo_" ] \45 || die "nvm_remote_version foo did not return last line only of nvm_ls_remote foo; got $CAPTURED_STDOUT"46[ "_$CAPTURED_EXIT_CODE" = "_0" ] || die "nvm_remote_version foo did not exit with 0, got $CAPTURED_EXIT_CODE"4748try nvm_remote_version iojs-foo49[ "_$CAPTURED_STDOUT" = "_iojs_pattern_received:_iojs-foo_" ] \50 || die "nvm_remote_version iojs-foo did not return last line only of nvm_ls_remote_iojs foo; got $CAPTURED_STDOUT"51[ "_$CAPTURED_EXIT_CODE" = "_0" ] || die "nvm_remote_version iojs-foo did not exit with 0, got $CAPTURED_EXIT_CODE"5253try nvm_remote_version iojs54[ "_$CAPTURED_STDOUT" = "_iojs_pattern_received:__" ] \55 || die "nvm_remote_version iojs did not return last line only of nvm_ls_remote_iojs; got $CAPTURED_STDOUT"56[ "_$CAPTURED_EXIT_CODE" = "_0" ] || die "nvm_remote_version iojs did not exit with 0, got $CAPTURED_EXIT_CODE"5758try nvm_remote_version stable59[ "_$CAPTURED_STDOUT" = "_$(nvm_ls_remote stable)" ] \60 || die "nvm_remote_version stable did not return contents of nvm_ls_remote stable; got $CAPTURED_STDOUT"61[ "_$CAPTURED_EXIT_CODE" = "_0" ] || die "nvm_remote_version stable did not exit with 0, got $CAPTURED_EXIT_CODE"6263try nvm_remote_version unstable64[ "_$CAPTURED_STDOUT" = "_$(nvm_ls_remote unstable)" ] \65 || die "nvm_remote_version unstable did not return contents of nvm_ls_remote unstable; got $CAPTURED_STDOUT"66[ "_$CAPTURED_EXIT_CODE" = "_0" ] || die "nvm_remote_version unstable did not exit with 0, got $CAPTURED_EXIT_CODE"6768try nvm_remote_version node69[ "_$CAPTURED_STDOUT" = "_$(nvm_ls_remote node)" ] \70 || die "nvm_remote_version node did not return contents of nvm_ls_remote node; got $CAPTURED_STDOUT"71[ "_$CAPTURED_EXIT_CODE" = "_0" ] || die "nvm_remote_version node did not exit with 0, got $CAPTURED_EXIT_CODE"7273# Test LTS name rejection (Issue #3474)74# When nvm_remote_versions returns a line with LTS name in description,75# nvm_remote_version should reject it if the pattern doesn't match the version number7677nvm_remote_versions() {78 echo "v4.9.1 Argon *"79}80try nvm_remote_version Argon81[ "_$CAPTURED_STDOUT" = "_N/A" ] || die "nvm_remote_version Argon should return N/A (LTS name not in version), got $CAPTURED_STDOUT"82[ "_$CAPTURED_EXIT_CODE" = "_3" ] || die "nvm_remote_version Argon should exit with code 3, got $CAPTURED_EXIT_CODE"8384nvm_remote_versions() {85 echo "v4.9.1"86}87try nvm_remote_version 488[ "_$CAPTURED_STDOUT" = "_v4.9.1" ] || die "nvm_remote_version 4 should return v4.9.1, got $CAPTURED_STDOUT"89[ "_$CAPTURED_EXIT_CODE" = "_0" ] || die "nvm_remote_version 4 should exit with code 0, got $CAPTURED_EXIT_CODE"9091cleanup