mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.16k stars 338 forks source link

some tests fail when system have unconfigured locales #773

Closed talau closed 2 years ago

talau commented 2 years ago

Hi there!

On Linux, when you run tests on a chroot/docker that do not have locales installed and configured, some tests, like parser_test.go and interp_test.go, fail.

One example of fail:

=== CONT TestRunnerRunConfirm/#133 interp_test.go:3280: wrong bash output in "INTERP_GLOBAL=; $ENV_PROG | grep '^INTERP_GLOBAL='": want: "INTERP_GLOBAL=\n" got: "bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)\nINTERP_GLOBAL=\n"

As some systems, like Debian, use CI tests in an environment like that, please, can you consider ignoring warnings like this on the tests?

Cheers, mt

mvdan commented 2 years ago

Thanks for letting me know; looks like using C.UTF-8 fixes the issue. I also see that a few other tests might fail due to UID/PID assumptions.

mvdan commented 2 years ago

Hmm, looks like that locale isn't on my system by default, either. C might have to do.

talau commented 2 years ago

Yep, I think that changing en_US.UTF-8 to C in os.Setenv on interp_test.go/parser_test.go fixes the issue.

mvdan commented 2 years ago

It's unfortunately not that easy, because C implies no UTF-8, and some of the tests assume it. I think I'll have to go with C.UTF-8, with perhaps some form of logic to detect whether it's present. Arch Linux doesn't have it for instance, as glibc won't ship with it until 2.35.

talau commented 2 years ago

Hi there!

I tested on Debian and it's fixed the issue! Thanks @mvdan!

You can see the log here: https://salsa.debian.org/talau-guest/shfmt-tests-minimal/-/jobs/2277914/raw