From 3c5707f7fbbdcf2cad0bb24ad2ed00d5771aae57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Wed, 13 Nov 2024 12:35:22 +0100 Subject: [PATCH] Improve reliability of NO_COLOR tests. (#3188) * 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. --- tests/shtest | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/shtest b/tests/shtest index 96b547e5..507c4439 100755 --- a/tests/shtest +++ b/tests/shtest @@ -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. @@ -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