Skip to content
Myr

[Fix] `nvm_err`, `nvm_err_with_colors`: do not fail when stderr is closed

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fixes #3906

authored by Lazizbek Ergashev · committed by Jordan Harband · parent aeace46 · Browse files · 3 files+28 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+28 added−2 removed

  • tests:+23 added−0 removed
  • other:+5 added−2 removed

3 files+28 added−2 removed

modified:test/fast/Unit tests/nvm_compare_checksum+2 added
52 unmodified lines
53EXPECTED_OUTPUT='Checksums matched!'54[ "${CAPTURED_STDERR}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${CAPTURED_STDERR}<"55[ "${CAPTURED_EXIT_CODE}" = 0 ] || die "expected to exit with code 0, got ${CAPTURED_EXIT_CODE}"5657(set +x; nvm_compare_checksum ../../../nvm.sh checksum 2>&-) || die "with stderr closed, expected to exit with code 0, got $?"5859cleanup
added:test/fast/Unit tests/nvm_err+21 added
1#!/bin/sh23die () { echo "$@" ; exit 1; }45: nvm.sh6\. ../../../nvm.sh78\. ../../common.sh910try_err nvm_err 'an error'11EXPECTED_OUTPUT='an error'12[ "${CAPTURED_STDERR}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${CAPTURED_STDERR}<"13[ "${CAPTURED_EXIT_CODE}" = 0 ] || die "expected to exit with code 0, got ${CAPTURED_EXIT_CODE}"1415try_err nvm_err_with_colors 'an error'16EXPECTED_OUTPUT='an error'17[ "${CAPTURED_STDERR}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${CAPTURED_STDERR}<"18[ "${CAPTURED_EXIT_CODE}" = 0 ] || die "expected to exit with code 0, got ${CAPTURED_EXIT_CODE}"1920nvm_err 'an error' 2>&- || die "nvm_err with stderr closed exited with code $?"21nvm_err_with_colors 'an error' 2>&- || die "nvm_err_with_colors with stderr closed exited with code $?"
modified:nvm.sh+5 added-2 removed
31 unmodified lines
32nvm_cd() {33 \cd "$@"34}3536# a caller that closed stderr, rather than redirecting it to /dev/null, makes37# the `>&2` fail; zsh cannot report that, so it aborts the script, which only a38# subshell contains, and `|| return 0` keeps the status from the caller39nvm_err() {37 >&2 nvm_echo "$@"40 (>&2 nvm_echo "$@") || return 041}4243nvm_err_with_colors() {41 >&2 nvm_echo_with_colors "$@"44 (>&2 nvm_echo_with_colors "$@") || return 045}4647nvm_grep() {48 GREP_OPTIONS='' command grep "$@"
5125 unmodified lines