jq icon indicating copy to clipboard operation
jq copied to clipboard

1 test fails on WSL Debian

Open polluks opened this issue 1 year ago • 14 comments
trafficstars

Describe the bug FAIL: tests/shtest

To Reproduce make check

Expected behavior FAIL: 0

Environment:

  • OS and Version: Linux Debian 10
  • jq version jq-1.6rc1-510-gfb8cc53

Additional context test-suite.log

polluks avatar Dec 18 '23 11:12 polluks

We run check on CI so it works for us. Looks like an issue of NO_COLOR support, but I have no clue. Please describe more information about how you build and run tests.

itchyny avatar Dec 18 '23 13:12 itchyny

That test is assuming that the login shell of the current user is a POSIX shell; it probably has something to do with that

emanuele6 avatar Dec 18 '23 18:12 emanuele6

Can you please try this patch?

diff --git a/tests/shtest b/tests/shtest
index 14aafbf..ca7e41f 100755
--- a/tests/shtest
+++ b/tests/shtest
@@ -507,11 +507,11 @@ 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 |
+  unset -v NO_COLOR
+  if script -qc true /dev/null >/dev/null 2>&1; then
+    faketty() { SHELL=sh script -qec "$*" /dev/null; }
+  else # BSD
+    faketty() { SHELL=sh script -q /dev/null -- "$@" /dev/null |
       sed 's/^\x5E\x44\x08\x08//'; }
   fi
 

emanuele6 avatar Dec 18 '23 19:12 emanuele6

Also, I am confused by that sed command on MacOS, because I am pretty sure s/^/\x12/ does not work in macOS sed. Maybe s/^\x12// works though. Could someone check with printf '\x12HELLO\n' | sed -n 's/^\x12//; l' on macOS? (If you see just HELLO$, it works; if you see somethingHELLO$ it does not work)

In any case, we should probably just use something more portable like bs=$(printf \\b); sed "1s/^^D$bs$bs//"

emanuele6 avatar Dec 18 '23 19:12 emanuele6

@emanuele6 macOS

$ printf '\x12HELLO\n' | sed -n 's/^\x12//; l'
HELLO$

wader avatar Dec 18 '23 21:12 wader

@emanuele6 Sorry, your patch didn't help. I'm using a simple bash.

  _____      stefan@Stefan-PC
 /  __ \     os     Debian GNU/Linux 10 (buster) on Windows 10 [WSL2]
|  /    |    host   x86_64
|  \___-     kernel 4.4.0-19041-Microsoft
-_           uptime 30m
  --_        pkgs   1434
             memory 6192M / 16335M

test-suite.log

polluks avatar Dec 19 '23 11:12 polluks

@polluks Can you try the following commands on the terminal?

/home/stefan/g/jq/jq --version
NO_COLOR=1 /home/stefan/g/jq/jq -n . | od -tc
NO_COLOR=1 script -qec /home/stefan/g/jq/jq -n . /dev/null | od -tc

itchyny avatar Dec 19 '23 12:12 itchyny

Or

/home/stefan/g/jq/jq --version
NO_COLOR=1 /home/stefan/g/jq/jq -n . | od -tc
NO_COLOR=1 script -qec '/home/stefan/g/jq/jq -n .' /dev/null | od -tc

emanuele6 avatar Dec 19 '23 13:12 emanuele6

$ /home/stefan/g/jq/jq --version
jq-1.6rc1-510-gfb8cc53-dirty
$ NO_COLOR=1 /home/stefan/g/jq/jq -n . | od -tc
0000000   n   u   l   l  \n
0000005
$ NO_COLOR=1 script -qec '/home/stefan/g/jq/jq -n .' /dev/null | od -tc
0000000   n   u   l   l  \r  \n
0000006
$ NO_COLOR=1 script -qec /home/stefan/g/jq/jq -n . /dev/null | od -tc
script: invalid option -- 'n'
Try 'script --help' for more information.
0000000
$ script --version
script from util-linux 2.33.1

polluks avatar Dec 20 '23 10:12 polluks

$SHELL --version export X=1; f() { printenv X; }; X=2 f

itchyny avatar Dec 20 '23 10:12 itchyny

$ $SHELL --version
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ export X=1; f() { printenv X; }; X=2 f
2

polluks avatar Dec 20 '23 15:12 polluks

Can you try with /bin/sh -c? /bin/sh -xc 'NO_COLOR=1 script -qec "/home/stefan/g/jq/jq -n ." /dev/null | od -tc'

itchyny avatar Dec 20 '23 23:12 itchyny

$ /bin/sh -xc 'NO_COLOR=1 script -qec "/home/stefan/g/jq/jq -n ." /dev/null | od -tc'
+ NO_COLOR=1 script -qec /home/stefan/g/jq/jq -n . /dev/null
+ od -tc
0000000   n   u   l   l  \r  \n
0000006

polluks avatar Dec 21 '23 12:12 polluks

@polluks Did you find any other clue? You're the only one that can debug step by step so appreciated if you can find the cause yourself. Otherwise I'm thinking of closing this issue because there was no further context provided and the test implementation looks correct.

itchyny avatar Dec 26 '23 06:12 itchyny