jq icon indicating copy to clipboard operation
jq copied to clipboard

3 tests fail on FreeBSD

Open yurivict opened this issue 2 years ago • 14 comments

Describe the bug

See log.

To Reproduce Testsuite.

Environment (please complete the following information):

  • OS and Version: FreeBSD 13.2
  • jq version: 1.7

yurivict avatar Sep 08 '23 04:09 yurivict

AFAICT this is a locale problem: strptime is returning the wrong day of the week (3 instead of 4), which could mean that the current locale's first_weekday is different from the expected locale's first_weekday. jq should set the locale it expects explicitly in tests to avoid this.

ncfavier avatar Sep 08 '23 10:09 ncfavier

Oh, yes, now that jq calls setlocale() we need to maybe not set it when running tests, or else set it to the C locale.

nicowilliams avatar Sep 08 '23 15:09 nicowilliams

The workaround is to run LC_ALL=C TZ= make check.

nicowilliams avatar Sep 08 '23 16:09 nicowilliams

The workaround is to run LC_ALL=C TZ= make check.

This workaround doesn't solve the problem.

When we run: /usr/bin/env LC_ALL=C TZ= gmake -f Makefile check we see that the same tests are still failing:

Test #1: '[strptime("%Y-%m-%dT%H:%M:%SZ")|(.,mktime)]' at line number 4
*** Expected [[2015,2,5,23,51,47,4,63],1425599507], but got [[2015,2,5,23,51,47,3,63],1425599507] for test at line number 6: [strptime("%Y-%m-%dT%H:%M:%SZ")|(.,mktime)]
Test #2: 'last(range(365 * 67)|("1970-03-01T01:02:03Z"|strptime("%Y-%m-%dT%H:%M:%SZ")|mktime) + (86400 * .)|strftime("%Y-%m-%dT%H:%M:%SZ")|strptime("%Y-%m-%dT%H:%M:%SZ"))' at line number 11
*** Expected [2037,1,11,1,2,3,3,41], but got [2037,1,11,1,2,3,2,41] for test at line number 13: last(range(365 * 67)|("1970-03-01T01:02:03Z"|strptime("%Y-%m-%dT%H:%M:%SZ")|mktime) + (86400 * .)|strftime("%Y-%m-%dT%H:%M:%SZ")|strptime("%Y-%m-%dT%H:%M:%SZ"))
Test #3: 'strftime("%A, %B %e, %Y")' at line number 16
1 of 3 tests passed (0 malformed, 0 skipped)
FAIL tests/optionaltest (exit status: 1)

yurivict avatar Sep 08 '23 17:09 yurivict

@nicowilliams

Any chance to fix tests?

yurivict avatar Feb 19 '24 20:02 yurivict

@yurivict does https://github.com/jqlang/jq/pull/3039 make it better? or is TZ= also needed?

wader avatar Feb 19 '24 20:02 wader

No, the latest revision 913b264 still has 3 failing tests.

yurivict avatar Feb 19 '24 21:02 yurivict

@emanuele6 set TZ also for tests?

wader avatar Feb 19 '24 21:02 wader

Earlier I tried with LC_ALL=C TZ= but it didn't help either.

yurivict avatar Feb 19 '24 21:02 yurivict

@yurivict doh sorry i misread your earlier comment

wader avatar Feb 19 '24 21:02 wader

Dugg a bit into this. What differs seems to be the tm_wday field (Day of week [0,6] (Sunday =0). ), expected to be 4 but is 3. The code related to calculating and assigning it i think is here https://github.com/freebsd/freebsd-src/blob/main/lib/libc/stdtime/strptime.c#L620-L686 but i don't really follow yet how it's affected by locale.

@yurivict Could you provide a dump of env variables, locale and timezone related configuration used? are you able to reproduce it with LC_ALL=C TZ= jq -n '"2015-03-05T23:51:47Z" | strptime("%Y-%m-%dT%H:%M:%SZ")[6]' 4? and could you also try with a different time for example LC_ALL=C TZ= jq -n '"2015-03-05T10:00:00Z" | strptime("%Y-%m-%dT%H:%M:%SZ")[6]'?

wader avatar Mar 06 '24 09:03 wader

$ LC_ALL=C TZ= jq -n '"2015-03-05T23:51:47Z" | strptime("%Y-%m-%dT%H:%M:%SZ")[6]'
3
$ LC_ALL=C TZ= jq -n '"2015-03-05T10:00:00Z" | strptime("%Y-%m-%dT%H:%M:%SZ")[6]'
3
$ env
SHELL=/usr/local/bin/bash
SESSION_MANAGER=local/yv.noip.me:/tmp/.ICE-unix/2511
WINDOWID=52428807
COLORTERM=truecolor
XDG_CONFIG_DIRS=/etc/xdg:/usr/local/etc/xdg
CVSROOT=/usr/home/cvs
XDG_MENU_PREFIX=xfce-
GTK_IM_MODULE=ibus
LANGUAGE=
SSH_AUTH_SOCK=/tmp/ssh-mjqHU6IlqwkD/agent.2509
SVN_EDITOR=vim
SHELL_SESSION_ID=dfb7f3ab8f4c41139cbbbdffbf526315
XMODIFIERS=@im=ibus
DESKTOP_SESSION=xfce
SSH_AGENT_PID=2510
EDITOR=vim
PWD=/usr/ports/textproc/jq
LOGNAME=yuri
XAUTHORITY=/home/yuri/.Xauthority
HOME=/home/yuri
LANG=C.UTF-8
XDG_CURRENT_DESKTOP=XFCE
KONSOLE_DBUS_SERVICE=:1.25
KONSOLE_DBUS_SESSION=/Sessions/32
PROFILEHOME=
CLICOLOR=1
KONSOLE_VERSION=230804
[email protected]
XDG_SESSION_COOKIE=yv.noip.me-1709543059.359749-1619039467
TERM=xterm-256color
USER=yuri
COLORFGBG=15;0
DISPLAY=unix:0.0
SHLVL=1
QT_IM_MODULE=ibus
MM_CHARSET=UTF-8
LC_CTYPE=en_US.UTF-8
XDG_RUNTIME_DIR=/home/yuri/runtime-yuri
XDG_DATA_DIRS=/usr/local/share:/usr/share
PATH=/home/yuri/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/dbus-vDKya3HEQr,guid=f54fcca95e3c140a8968284565e58e93
MAIL=/var/mail/yuri
OLDPWD=/usr/ports
KONSOLE_DBUS_WINDOW=/Windows/1
_=/usr/bin/env

Timezone is PST. Locale is en_US.UTF-8.

yurivict avatar Mar 06 '24 10:03 yurivict

@yurivict Thanks, not sure when i will get some more time to look at this, think i nearly need a freebsd env somewhere

wader avatar Mar 07 '24 11:03 wader

@wader

I have instructions on file how to easily get FreeBSD installed. Maybe they can help?

Is there an easy way to test under FreeBSD?

  1. Install the FreeBSD VM image into VirtualBox.
  2. Boot FreeBSD
  3. Install git: pkg install git
  4. Check out the ports tree: git clone https://git.FreeBSD.org/ports.git /usr/ports
  5. cd /usr/ports/textproc/jq
  6. Install dependencies: pkg install -A `make missing`
  7. Build: make
  8. Run tests: make test

yurivict avatar Mar 07 '24 22:03 yurivict