Skip to content

Commit

Permalink
Improve reliability of NO_COLOR tests. (#3188)
Browse files Browse the repository at this point in the history
* Improve reliability of NO_COLOR tests.

Use `env` to ensure that `NO_COLOR` is set to the desired value
regardless of any initialization that may occur when `script`
forks a shell to run jq in.

Note that `env -u` is not portable, so there is no good solution
for the first test case.

* Always use /bin/sh, not the user's login shell.
  • Loading branch information
dag-erling authored Nov 13, 2024
1 parent 32a304b commit 3c5707f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/shtest
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ JQ="$JQ -b"

PATH=$JQBASEDIR:$PATH $JQBASEDIR/tests/jq-f-test.sh > /dev/null

SHELL=/bin/sh
export SHELL

if [ -f "$JQBASEDIR/.libs/libinject_errors.so" ]; then
# Do some simple error injection tests to check that we're handling
# I/O errors correctly.
Expand Down Expand Up @@ -608,17 +611,17 @@ if $test_no_color && command -v script >/dev/null 2>&1; then
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 3c5707f

Please sign in to comment.