From 050a2ee9d38c700e04f6dc51153ee0541cc45eb4 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 28 Sep 2014 18:02:33 -0700 Subject: [PATCH] nvm_remote_version: add unit tests `nvm_ls_remote` is stubbed out to avoid making network calls here. --- test/fast/Unit tests/nvm_remote_version | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 test/fast/Unit tests/nvm_remote_version diff --git a/test/fast/Unit tests/nvm_remote_version b/test/fast/Unit tests/nvm_remote_version new file mode 100755 index 0000000..f7fc377 --- /dev/null +++ b/test/fast/Unit tests/nvm_remote_version @@ -0,0 +1,35 @@ +#!/bin/sh + +die () { echo $@ ; cleanup ; exit 1; } + +cleanup() { + unset -f nvm_ls_remote +} + +. ../../../nvm.sh + +nvm_ls_remote() { + echo "N/A" +} + +OUTPUT="$(nvm_remote_version foo)" +EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)" + +[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A" +[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE" + +nvm_ls_remote() { + echo "test output" + echo "more test output" + echo "pattern received: _$1_" +} + +OUTPUT="$(nvm_remote_version foo)" +EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)" + +[ "_$OUTPUT" = "_pattern received: _foo_" ] \ + || die "nvm_remote_version foo did not return last line only of nvm_ls_remote foo; got $OUTPUT" +[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version foo did not exit with 0, got $EXIT_CODE" + +cleanup +