nvm_echo
This file
Path
test/fast/Unit tests/nvm_echo
38 lines · 1.1 KiB
Last changed by
[Perf] `nvm_echo`: use the `printf` shell builtin under zshCassidy Marblebefore adoption66640e6
History of this fileTake it
1#!/bin/sh23die () { echo "$@" ; exit 1; }45cleanup() {6 rm -rf "${TEST_DIR}"7}89: nvm.sh10\. ../../../nvm.sh1112TEST_DIR="$(pwd)/nvm_echo_tmp"13[ ! -e "${TEST_DIR}" ] && mkdir "${TEST_DIR}"1415# 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)18MOCK_BIN="${TEST_DIR}/bin"19mkdir -p "${MOCK_BIN}"20{21 echo '#!/bin/sh'22 echo "echo 'MOCKED-PRINTF'"23} > "${MOCK_BIN}/printf"24chmod +x "${MOCK_BIN}/printf"2526OUTPUT="$(nvm_echo 'hello world')"27[ "${OUTPUT}" = 'hello world' ] || die "expected 'hello world', got '${OUTPUT}'"2829OUTPUT="$(nvm_echo)"30[ -z "${OUTPUT}" ] || die "expected no output, got '${OUTPUT}'"3132OUTPUT="$(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}'"3435OUTPUT="$(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}'"3738cleanup