#!/bin/sh set -e cleanup () { nvm cache clear nvm deactivate rm -rf ${NVM_DIR}/v* nvm unalias default } die () { >&2 echo "$@" ; cleanup ; exit 1; } \. ../../../nvm.sh cleanup OUTPUT="$(TERM=dumb 2>&1 nvm install --no-progress v0.12.18)" EXPECTED_OUTPUT="Downloading and installing node v0.12.18... Downloading https://nodejs.org/dist/v0.12.18/node-v0.12.18-linux-x64.tar.xz... Computing checksum with sha256sum Checksums matched! Now using node v0.12.18 (npm v2.15.11) Creating default alias: default -> v0.12.18 *" [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "1: expected > ${EXPECTED_OUTPUT}<, got > ${OUTPUT}<" cleanup OUTPUT="$(TERM=dumb 2>&1 nvm install v0.12.18)" EXPECTED_OUTPUT="Downloading and installing node v0.12.18... Downloading https://nodejs.org/dist/v0.12.18/node-v0.12.18-linux-x64.tar.xz... ######################################################################### 100.0% Computing checksum with sha256sum Checksums matched! Now using node v0.12.18 (npm v2.15.11) Creating default alias: default -> v0.12.18 *" [ "$(echo "${OUTPUT}" | wc -l)" = "$(echo "${EXPECTED_OUTPUT}" | wc -l)" ] || die "2: expected 7 lines, got $(echo "${OUTPUT}" | wc -l)" [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || { echo "$OUTPUT" | while IFS= read -r output_line && IFS= read -r expected_line <&3; do line_number=$((line_number + 1)) if [ "${output_line}" != "${expected_line}" ]; then echo "Difference on line ${line_number}:" echo "Output: ${output_line}" echo "Expected: ${expected_line}" fi done 3< ${EXPECTED_OUTPUT}<, got > ${OUTPUT}<" } cleanup