Skip to content
Myr

[Refactor] add `nvm_stdout_is_terminal` helper

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

authored by Christopher Sahnwaldt · committed by Jordan Harband · parent a1abfd1 · Browse files · 2 files+37 added−1 removed
This commit

State

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

Diff stats

2 files+37 added−1 removed

  • tests:+32 added−0 removed
  • other:+5 added−1 removed

2 files+37 added−1 removed

added:test/fast/Unit tests/nvm_stdout_is_terminal+32 added
1#!/bin/sh23tempfile=$(mktemp)45die () { echo "$@" ; cleanup; exit 1; }6cleanup() { rm -f "$tempfile"; }78\. ../../../nvm.sh910if [ -t 1 ] ; then11 # test is running in a terminal, e.g. locally12 nvm_stdout_is_terminal || die 'nvm_stdout_is_terminal should be true'13 nvm_stdout_is_terminal 2>/dev/null || die 'nvm_stdout_is_terminal should be true when stderr is redirected'14 nvm_stdout_is_terminal </dev/null || die 'nvm_stdout_is_terminal should be true when stdin is redirected'15else16 # test is not running in a terminal, e.g. on travis-ci17 ! nvm_stdout_is_terminal || die 'nvm_stdout_is_terminal should be false'18 ! nvm_stdout_is_terminal 2>/dev/null || die 'nvm_stdout_is_terminal should be false when stderr is redirected'19 ! nvm_stdout_is_terminal </dev/null || die 'nvm_stdout_is_terminal should be false when stdin is redirected'20fi2122(! nvm_stdout_is_terminal || echo "boo!") | read && die 'nvm_stdout_is_terminal should be false when stdout goes to a pipe'23! nvm_stdout_is_terminal >/dev/null || die 'nvm_stdout_is_terminal should be false when stdout goes to /dev/null'24! nvm_stdout_is_terminal >"$tempfile" || die 'nvm_stdout_is_terminal should be false when stdout goes to a file'25[ "$(nvm_stdout_is_terminal; echo $?)" = "1" ] || die 'nvm_stdout_is_terminal should be false in command substitution'2627# also test the 'true' case while running on travis-ci or similar environments28nvm_stdout_is_terminal >/dev/tty || die 'nvm_stdout_is_terminal should be true when stdout goes to /dev/tty'29nvm_stdout_is_terminal >/dev/tty 2>/dev/null || die 'nvm_stdout_is_terminal should be true when stdout goes to /dev/tty and stderr is redirected'30nvm_stdout_is_terminal >/dev/tty </dev/null || die 'nvm_stdout_is_terminal should be true when stdout goes to /dev/tty and stdin is redirected'3132cleanup
modified:nvm.sh+5 added-1 removed
14 unmodified lines
15nvm_is_zsh() {16 [ -n "${ZSH_VERSION-}" ]17}1819nvm_stdout_is_terminal() {20 [ -t 1 ]21}2223nvm_echo() {24 command printf %s\\n "$*" 2>/dev/null25}26
3475 unmodified lines
3502 nvm_list_aliases nvm_make_alias nvm_print_alias_path \3503 nvm_print_default_alias nvm_print_formatted_alias nvm_resolve_local_alias \3504 nvm_sanitize_path nvm_has_colors nvm_process_parameters \3505 node_version_has_solaris_binary iojs_version_has_solaris_binary \3502 nvm_curl_libz_support nvm_command_info nvm_is_zsh \3506 nvm_curl_libz_support nvm_command_info nvm_is_zsh nvm_stdout_is_terminal \3507 >/dev/null 2>&13508 unset NVM_RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \3509 NVM_CD_FLAGS NVM_BIN NVM_MAKE_JOBS \3510 >/dev/null 2>&1
143 unmodified lines