Skip to content

Commit

Permalink
Improve reliability of NO_COLOR tests.
Browse files Browse the repository at this point in the history
Use `env` to ensure that `NO_COLOR` is set to the desired value (or
unset) regardless of any initialization that may occur when `script`
forks a shell to run jq in.
  • Loading branch information
dag-erling committed Oct 4, 2024
1 parent 860af44 commit 950fb9c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tests/shtest
Original file line number Diff line number Diff line change
Expand Up @@ -573,30 +573,29 @@ test_no_color=true
$msys && test_no_color=false
$mingw && test_no_color=false
if $test_no_color && command -v script >/dev/null 2>&1; then
unset NO_COLOR
if script -qc echo /dev/null >/dev/null 2>&1; then
faketty() { script -qec "$*" /dev/null; }
else # macOS
faketty() { script -q /dev/null "$@" /dev/null |
sed 's/^\x5E\x44\x08\x08//'; }
fi

faketty $JQ_NO_B -n . > $d/color
faketty env -u NO_COLOR $JQ_NO_B -n . > $d/color
printf '\033[0;90mnull\033[0m\r\n' > $d/expect
od -tc $d/expect
od -tc $d/color
cmp $d/color $d/expect
NO_COLOR= faketty $JQ_NO_B -n . > $d/color
faketty env NO_COLOR= $JQ_NO_B -n . > $d/color
printf '\033[0;90mnull\033[0m\r\n' > $d/expect
od -tc $d/expect
od -tc $d/color
cmp $d/color $d/expect
NO_COLOR=1 faketty $JQ_NO_B -n . > $d/color
faketty env NO_COLOR=1 $JQ_NO_B -n . > $d/color
printf 'null\r\n' > $d/expect
od -tc $d/expect
od -tc $d/color
cmp $d/color $d/expect
NO_COLOR=1 faketty $JQ_NO_B -Cn . > $d/color
faketty env NO_COLOR=1 $JQ_NO_B -Cn . > $d/color
printf '\033[0;90mnull\033[0m\r\n' > $d/expect
od -tc $d/expect
od -tc $d/color
Expand Down

0 comments on commit 950fb9c

Please sign in to comment.