-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] do not colorize output in a pipe, unless
--colors
is passed
Fixes 2497
- Loading branch information
Showing
3 changed files
with
103 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/fast/Set Colors/Using --colors and --no-colors errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
|
||
set -ex | ||
|
||
die () { echo "$@" ; cleanup ; exit 1; } | ||
|
||
\. ../../nvm.sh | ||
|
||
nvm ls --colors --no-colors && die "\`nvm ls --colors --no-colors\` did not fail" | ||
nvm ls-remote --colors --no-colors && die "\`nvm ls-remote --colors --no-colors\` did not fail" | ||
nvm alias --colors --no-colors && die "\`nvm alias --colors --no-colors\` did not fail" | ||
nvm --help --colors --no-colors && die "\`nvm --help --colors --no-colors\` did not fail" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/sh | ||
|
||
set -ex | ||
|
||
die () { echo "$@" ; cleanup ; exit 1; } | ||
|
||
\. ../../nvm.sh | ||
|
||
# ensures that commands are run as if in a terminal | ||
term_cmd() { | ||
script -q -a /dev/null sh -c "\. ../../nvm.sh ; $*" | ||
} | ||
|
||
for cmd in ls ls-remote alias --help; do | ||
NO_COLORS="$(term_cmd nvm "${cmd}" --no-colors)" | ||
COLORS="$(term_cmd nvm "${cmd}" --colors)" | ||
|
||
[ "${COLORS}" != "${NO_COLORS}" ] || die "Expected \`nvm ${cmd} --colors\` to be different from \`nvm ${cmd} --no-colors\`" | ||
|
||
PIPE="$(nvm "${cmd}")" | ||
PIPE_COLORS="$(nvm "${cmd}" --colors)" | ||
|
||
[ "${PIPE}" = "${NO_COLORS}" ] || die "Expected \`nvm ${cmd}\` in a pipe to be the same as \`nvm ${cmd} --no-colors\`" | ||
[ "${PIPE_COLORS}" = "${COLORS}" ] || die "Expected \`nvm ${cmd} --colors\` in a pipe to be the same as \`nvm ls\` in a terminal (with colors)" | ||
done |