added:test/fast/Unit tests/nvm_echo+38 added
1+#!/bin/sh2+3+die () { echo "$@" ; exit 1; }4+5+cleanup() {6+ rm -rf "${TEST_DIR}"7+}8+9+: nvm.sh10+\. ../../../nvm.sh11+12+TEST_DIR="$(pwd)/nvm_echo_tmp"13+[ ! -e "${TEST_DIR}" ] && mkdir "${TEST_DIR}"14+15+# a `printf` that reports that it ran: `nvm_echo` must use a shell builtin16+# rather than resolving `printf` through `PATH` (zsh's `command` skips the17+# builtin and runs `/usr/bin/printf` on every call)18+MOCK_BIN="${TEST_DIR}/bin"19+mkdir -p "${MOCK_BIN}"20+{21+ echo '#!/bin/sh'22+ echo "echo 'MOCKED-PRINTF'"23+} > "${MOCK_BIN}/printf"24+chmod +x "${MOCK_BIN}/printf"25+26+OUTPUT="$(nvm_echo 'hello world')"27+[ "${OUTPUT}" = 'hello world' ] || die "expected 'hello world', got '${OUTPUT}'"28+29+OUTPUT="$(nvm_echo)"30+[ -z "${OUTPUT}" ] || die "expected no output, got '${OUTPUT}'"31+32+OUTPUT="$(PATH="${MOCK_BIN}:${PATH}" nvm_echo 'no fork, please' 2>&1)"33+[ "${OUTPUT}" = 'no fork, please' ] || die "for nvm_echo, expected 'no fork, please', got '${OUTPUT}'"34+35+OUTPUT="$(PATH="${MOCK_BIN}:${PATH}" nvm_echo_with_colors 'no fork, please' 2>&1)"36+[ "${OUTPUT}" = 'no fork, please' ] || die "for nvm_echo_with_colors, expected 'no fork, please', got '${OUTPUT}'"37+38+cleanup