-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
100 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 | ||
|
||
die () { echo "$@" ; cleanup ; exit 1; } | ||
|
||
\. ../../../nvm.sh | ||
|
||
set -ex | ||
|
||
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,22 @@ | ||
#!/bin/sh | ||
|
||
die () { echo "$@" ; cleanup ; exit 1; } | ||
|
||
\. ../../../nvm.sh | ||
\. ../../common.sh | ||
|
||
|
||
set -ex | ||
|
||
for cmd in ls ls-remote alias --help; do | ||
NO_COLORS="$(run_in_terminal nvm "${cmd}" --no-colors)" | ||
COLORS="$(run_in_terminal 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 |